首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Terragrunt使用来自其他环境的资源

Terragrunt使用来自其他环境的资源
EN

Stack Overflow用户
提问于 2019-09-12 22:12:10
回答 1查看 234关注 0票数 1

我想在另一个环境中使用资源,在本例中是vpc模块的输出。目标是将stage和开发资源放在同一个vpc中,为客户降低成本。Stage和dev有独立的ecs-cluster、asg、lc,ecr等不同的docker镜像,但需要在同一个vpc中使用相同的负载均衡,然后使用host header监听器转发到特定的目标组。两者应该使用相同的数据库和相同的负载均衡器。

要求有n个客户,每个客户都有阶段、开发和生产环境。所有客户文件夹都应包含这三个环境。

我的文件夹结构是

代码语言:javascript
复制
├── 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模块的输入?

我用过

代码语言:javascript
复制
dependency "vpc" {
  config_path = "../vpc"
}

然后

代码语言:javascript
复制
vpc_id = dependency.vpc.outputs.vpc_id

用于ec2模块的输入,但这仅当它在相同的环境中时。

诚挚的问候。

EN

回答 1

Stack Overflow用户

发布于 2020-02-03 07:57:46

在上面显示的目录结构中,您在dev和stage环境中都有一个VPC。听起来您希望dev和stage共享一个VPC,因此要做的第一件事是将VPC目录移出dev和stage。将vpc放在eu-west-1下,您可以根据需要在dev和stage中使用它作为依赖项。

代码语言:javascript
复制
Customer6
│       ├── non-prod
            └── eu-central-1
                ├── dev
                │   └── ecs
                ├── stage
                │   └── ecs
                └──  vpc
代码语言:javascript
复制
dependency "vpc" {
  config_path = "../../vpc"
}

请参阅Passing outputs between modules上的Terragrunt文档。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/57908636

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档