128 lines
2.7 KiB
Markdown
128 lines
2.7 KiB
Markdown
# Heroku Terraform 配置说明
|
||
|
||
## 当前状态
|
||
|
||
由于网络连接问题,无法自动下载 Heroku Terraform provider。以下是解决方案。
|
||
|
||
## 方案一:手动下载 Provider(推荐)
|
||
|
||
### 1. 手动下载 Heroku Provider
|
||
|
||
```bash
|
||
# 创建插件目录
|
||
mkdir -p ~/.terraform.d/plugins/linux_amd64/
|
||
|
||
# 下载 provider(需要网络连接)
|
||
cd ~/.terraform.d/plugins/linux_amd64/
|
||
wget https://github.com/heroku/terraform-provider-heroku/releases/download/v5.3.2/terraform-provider-heroku_5.3.2_linux_amd64.zip
|
||
|
||
# 解压
|
||
unzip terraform-provider-heroku_5.3.2_linux_amd64.zip
|
||
rm terraform-provider-heroku_5.3.2_linux_amd64.zip
|
||
|
||
# 返回项目目录
|
||
cd /home/ben/terraform/heroku
|
||
|
||
# 初始化
|
||
terraform init
|
||
```
|
||
|
||
### 2. 使用配置文件
|
||
|
||
```bash
|
||
# 应用配置
|
||
terraform apply -var="heroku_api_key=$(head -1 .env)" -var="heroku_email=$(tail -1 .env)"
|
||
```
|
||
|
||
## 方案二:使用 Heroku CLI(替代方案)
|
||
|
||
如果 Terraform provider 无法使用,可以直接使用 Heroku CLI:
|
||
|
||
### 安装 Heroku CLI
|
||
|
||
```bash
|
||
# 使用 snap 安装
|
||
sudo snap install --classic heroku
|
||
|
||
# 或使用 npm
|
||
npm install -g heroku
|
||
```
|
||
|
||
### 登录 Heroku
|
||
|
||
```bash
|
||
heroku login
|
||
```
|
||
|
||
### 创建应用
|
||
|
||
```bash
|
||
# 创建新应用
|
||
heroku create my-app
|
||
|
||
# 查看应用
|
||
heroku apps
|
||
|
||
# 添加 PostgreSQL
|
||
heroku addons:create heroku-postgresql:essential-0
|
||
|
||
# 添加 Redis
|
||
heroku addons:create heroku-redis:mini
|
||
|
||
# 设置环境变量
|
||
heroku config:set NODE_ENV=production PORT=8080
|
||
|
||
# 查看日志
|
||
heroku logs --tail
|
||
|
||
# 部署应用
|
||
git push heroku main
|
||
```
|
||
|
||
## 方案三:使用 HTTP 代理
|
||
|
||
如果你有可用的代理,可以配置环境变量:
|
||
|
||
```bash
|
||
# 设置代理
|
||
export HTTP_PROXY=http://your-proxy:port
|
||
export HTTPS_PROXY=http://your-proxy:port
|
||
|
||
# 初始化 Terraform
|
||
terraform init
|
||
```
|
||
|
||
## 当前账户信息
|
||
|
||
根据 API 查询,你的 Heroku 账户有以下应用:
|
||
|
||
- **应用名称**: cauldron
|
||
- **应用 URL**: https://cauldron-6e3816f9af3f.herokuapp.com/
|
||
- **Stack**: heroku-24
|
||
- **区域**: us
|
||
- **邮箱**: houzhongxu@seekkey.tech
|
||
|
||
## Terraform 配置文件说明
|
||
|
||
[main.tf](file:///home/ben/terraform/heroku/main.tf) 包含以下资源:
|
||
|
||
1. **Heroku App** - 主应用
|
||
2. **Formation** - Web dyno 配置
|
||
3. **PostgreSQL Add-on** - 数据库
|
||
4. **Redis Add-on** - 缓存
|
||
5. **Config Vars** - 环境变量
|
||
|
||
## 可自定义的变量
|
||
|
||
- `app_name` - 应用名称(默认:terraform-app)
|
||
- `region` - 区域(默认:us)
|
||
- `stack` - Stack 版本(默认:heroku-22)
|
||
- `dyno_size` - Dyno 规格(默认:basic)
|
||
|
||
## 注意事项
|
||
|
||
1. Heroku 免费版已经停止,需要付费使用
|
||
2. Add-ons 会产生额外费用
|
||
3. 建议先在测试环境验证配置
|
||
4. 记得定期检查账单和资源使用情况
|