我想在另一个环境中使用资源,在本例中是vpc模块的输出。目标是将stage和开发资源放在同一个vpc中,为客户降低成本。Stage和dev有独立的ecs-cluster、asg、lc,ecr等不同的docker镜像,但需要在同一个vpc中使用相同的负载均衡,然后使用host header监听器转发到特定的目标组。两者应该使用相同的数据库和相同的负载均衡器。
要求有n个客户,每个客户都有阶段、开发和生产环境。所有客户文件夹都应包含这三个环境。
我的文件夹结构是
├── Terraform
│ ├── Customer1
│ ├── Customer2
│ ├── Customer3
│ ├── Customer4
│ ├── Customer5
│ ├── Global
│ │ ├── iam
│ │ │ └── terragrunt.hcl
│ ├── README.md
│ └── Customer6
│ ├── non-prod
│ │ ├── eu-central-1
│ │ │ ├── dev
│ │ │ │ ├── cloudwatch
│ │ │ │ │ └── terragrunt.hcl
│ │ │ │ ├── ec2
│ │ │ │ │ └── terragrunt.hcl
│ │ │ │ ├── ecs
│ │ │ │ │ └── terragrunt.hcl
│ │ │ │ ├── lambda
│ │ │ │ │ └── terragrunt.hcl
│ │ │ │ ├── rds
│ │ │ │ │ └── terragrunt.hcl
│ │ │ │ ├── terragrunt.hcl
│ │ │ │ ├── vars.hcl
│ │ │ │ └── vpc
│ │ │ │ └── terragrunt.hcl
│ │ │ ├── region.hcl
│ │ │ └── stage
│ │ │ ├── cloudwatch
│ │ │ │ └── terragrunt.hcl
│ │ │ ├── ec2
│ │ │ │ └── terragrunt.hcl
│ │ │ ├── ecs
│ │ │ │ └── terragrunt.hcl
│ │ │ ├── lambda
│ │ │ │ └── terragrunt.hcl
│ │ │ ├── rds
│ │ │ │ └── terragrunt.hcl
│ │ │ ├── terragrunt.hcl
│ │ │ ├── vars.hcl
│ │ │ └── vpc
│ │ │ └── terragrunt.hcl
│ │ └── terragrunt.hcl
│ └── prod
│ └── eu-central-1
│ ├── prod
│ │ ├── cloudwatch
│ │ │ └── terragrunt.hcl
│ │ ├── ec2
│ │ │ └── terragrunt.hcl
│ │ ├── ecs
│ │ │ └── terragrunt.hcl
│ │ ├── lambda
│ │ │ └── terragrunt.hcl
│ │ ├── rds
│ │ │ └── terragrunt.hcl
│ │ ├── terragrunt.hcl
│ │ ├── vars.hcl
│ │ └── vpc
│ │ └── terragrunt.hcl
│ └── region.hcl
└── Modules
├── cloudwatch
│ ├── Main.tf
│ ├── Outputs.tf
│ └── Variables.tf
├── ec2
│ ├── Main.tf
│ ├── Outputs.tf
│ └── Variables.tf
├── ecs
│ ├── Main.tf
│ ├── Outputs.tf
│ └── Variables.tf
├── iam
│ ├── Main.tf
│ ├── Outputs.tf
│ └── Variables.tf
├── lambda
│ ├── Main.tf
│ ├── Outputs.tf
│ └── Variables.tf
├── rds
│ ├── Main.tf
│ ├── Outputs.tf
│ └── Variables.tf
├── vpc
│ ├── Main.tf
│ ├── Outputs.tf
│ ├── Variables.tf
└── vpc-stage
├── Main.tf
├── Outputs.tf
└── Variables.tf我读过关于data terraform_remote_state的文章,但那是关于模块层的。对我来说,这不是在模块层做这件事的好方法,因为它只适用于阶段环境。有没有一种方法可以从开发环境的stage文件夹中的terragrunt.hcl中获取远程状态的输出,以将其用作ec2模块的输入?
我用过
dependency "vpc" {
config_path = "../vpc"
}然后
vpc_id = dependency.vpc.outputs.vpc_id用于ec2模块的输入,但这仅当它在相同的环境中时。
诚挚的问候。
发布于 2020-02-03 07:57:46
在上面显示的目录结构中,您在dev和stage环境中都有一个VPC。听起来您希望dev和stage共享一个VPC,因此要做的第一件事是将VPC目录移出dev和stage。将vpc放在eu-west-1下,您可以根据需要在dev和stage中使用它作为依赖项。
Customer6
│ ├── non-prod
└── eu-central-1
├── dev
│ └── ecs
├── stage
│ └── ecs
└── vpcdependency "vpc" {
config_path = "../../vpc"
}请参阅Passing outputs between modules上的Terragrunt文档。
https://stackoverflow.com/questions/57908636
复制相似问题