terraform如何知道它应该首先运行哪个资源来启动基础设施?

内容来源于 Stack Overflow,并遵循CC BY-SA 3.0许可协议进行翻译与使用

  • 回答 (2)
  • 关注 (0)
  • 查看 (142)

我正在使用terraform来启动Aws-DMS。要启动DMS,我们需要子网组,dms复制任务,dms端点,dms复制实例。我使用terraform文档配置了所有内容。我的问题是terraform将如何知道首先完成哪个任务以启动其他依赖任务?我们是否需要在地形中声明它或者是足够智能的terraform以便相应地运行?

提问于
用户回答回答于

来自:https: //learn.hashicorp.com/terraform/getting-started/dependencies.html depends_on是您正在寻找的,如果它不是一个隐式依赖。

# New resource for the S3 bucket our application will use.
resource "aws_s3_bucket" "example" {
  # NOTE: S3 bucket names must be unique across _all_ AWS accounts, so
  # this name must be changed before applying this example to avoid naming
  # conflicts.
  bucket = "terraform-getting-started-guide"
  acl    = "private"
}

# Change the aws_instance we declared earlier to now include "depends_on"
resource "aws_instance" "example" {
  ami           = "ami-2757f631"
  instance_type = "t2.micro"

  # Tells Terraform that this EC2 instance must be created only after the
  # S3 bucket has been created.
  depends_on = [aws_s3_bucket.example]
}
用户回答回答于

Terraform将按顺序自动创建资源,以便满足所有依赖关系。

例如:如果在DMS定义中设置安全组ID "${aws_security_group.my_sg.id}",则Terraform会识别此依赖关系并在DMS资源之前创建安全组。

扫码关注云+社区

领取腾讯云代金券