Initial commit: Terraform configurations for multiple cloud providers
This commit is contained in:
2
heroku/.env
Normal file
2
heroku/.env
Normal file
@@ -0,0 +1,2 @@
|
||||
HRKU-AAUX0JnQ334X9YT6wmhiLQWNzhJQIzR6u7CqHhpNuZYA_____wZAJIaLwSNQ
|
||||
houzhongxu@seekkey.tech
|
||||
127
heroku/README.md
Normal file
127
heroku/README.md
Normal file
@@ -0,0 +1,127 @@
|
||||
# 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. 记得定期检查账单和资源使用情况
|
||||
99
heroku/main.tf
Normal file
99
heroku/main.tf
Normal file
@@ -0,0 +1,99 @@
|
||||
terraform {
|
||||
required_providers {
|
||||
heroku = {
|
||||
source = "heroku/heroku"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
provider "heroku" {
|
||||
email = var.heroku_email
|
||||
api_key = var.heroku_api_key
|
||||
}
|
||||
|
||||
variable "heroku_api_key" {
|
||||
description = "Heroku API Key"
|
||||
type = string
|
||||
sensitive = true
|
||||
}
|
||||
|
||||
variable "heroku_email" {
|
||||
description = "Heroku Email"
|
||||
type = string
|
||||
}
|
||||
|
||||
variable "app_name" {
|
||||
description = "Heroku App Name"
|
||||
type = string
|
||||
default = "terraform-app"
|
||||
}
|
||||
|
||||
variable "region" {
|
||||
description = "Heroku Region"
|
||||
type = string
|
||||
default = "us"
|
||||
}
|
||||
|
||||
variable "stack" {
|
||||
description = "Heroku Stack"
|
||||
type = string
|
||||
default = "heroku-22"
|
||||
}
|
||||
|
||||
variable "dyno_size" {
|
||||
description = "Dyno Size"
|
||||
type = string
|
||||
default = "basic"
|
||||
}
|
||||
|
||||
resource "heroku_app" "main" {
|
||||
name = var.app_name
|
||||
region = var.region
|
||||
stack = var.stack
|
||||
}
|
||||
|
||||
resource "heroku_formation" "web" {
|
||||
app_id = heroku_app.main.id
|
||||
type = "web"
|
||||
quantity = 1
|
||||
size = var.dyno_size
|
||||
}
|
||||
|
||||
resource "heroku_addon" "postgres" {
|
||||
app_id = heroku_app.main.id
|
||||
plan = "heroku-postgresql:essential-0"
|
||||
}
|
||||
|
||||
resource "heroku_addon" "redis" {
|
||||
app_id = heroku_app.main.id
|
||||
plan = "heroku-redis:mini"
|
||||
}
|
||||
|
||||
resource "heroku_config" "app_config" {
|
||||
sensitive_vars = {
|
||||
NODE_ENV = "production"
|
||||
PORT = "8080"
|
||||
}
|
||||
}
|
||||
|
||||
output "app_url" {
|
||||
description = "Heroku App URL"
|
||||
value = "https://${var.app_name}.herokuapp.com"
|
||||
}
|
||||
|
||||
output "app_name" {
|
||||
description = "Heroku App Name"
|
||||
value = heroku_app.main.name
|
||||
}
|
||||
|
||||
output "postgres_url" {
|
||||
description = "PostgreSQL Database URL"
|
||||
value = heroku_addon.postgres.config_var_values
|
||||
sensitive = true
|
||||
}
|
||||
|
||||
output "redis_url" {
|
||||
description = "Redis URL"
|
||||
value = heroku_addon.redis.config_var_values
|
||||
sensitive = true
|
||||
}
|
||||
Reference in New Issue
Block a user