【发布时间】:2020-12-29 04:29:31
【问题描述】:
我一直在尝试重新构建我的 terraform 模块,使其可以重复使用。 我在这里试图解决的问题是避免创建新的 tf 模块,其中只有一两个用于特定设置的新属性。
目前的结构:
├── services
│ ├── ec2
│ │ └── terragrunt.hcl
│ ├── ec2_with_fixed_ip
│ │ └── terragrunt.hcl (2)
│ └── terragrunt.hcl (1)
├── tf_moodules
└── ec2
│ └── main.tf
└── ec2_with_fixed_ip
│ └── main.tf
└── ec2_with_root_block_device
└── main.tf
我也一直在考虑使用 terraform-aws-ec2-instance git repo 作为我的 terragrunt 脚本中的源。这样,我根本不需要管理 tf 模块。但我不确定我应该如何编写 terragrunt.hcl 以指向 GitHub 存储库并与某个版本挂钩。
这是推荐的做事方式吗?还是有更清洁的方法?
terragrunt.hcl 中的内容 (1)
remote_state {
backend = "s3"
config = {
encrypt = true
bucket = "my_bucket"
key = "${path_relative_to_include()}/terraform.tfstate"
region = "ap-southeast-1"
dynamodb_table = "tf-locks"
}
}
terragrunt.hcl 中的内容 (2)
terraform {
source = "git::https://github.com/terraform-aws-modules/terraform-aws-ec2-instance.git//?ref=v2.15.0"
}
include {
path = find_in_parent_folders()
}
inputs = {
ami = "ami-0123456789abcd"
instance_type = "t3.medium"
disable_api_termination = false
}
尝试了上述设置,但面临缺少后端“s3”块的问题
【问题讨论】:
-
你已经在做正确的事情了!您可以考虑使用 git 源 (
git::git@github.com:terraform-aws-modules/terraform-aws-ec2-instance.git//?ref=v2.15.0),但这主要是一个偏好问题。
标签: amazon-web-services terraform terraform-provider-aws terragrunt