中铁建设投资集团有限公司网站,sina app engine wordpress,广告设计公司网,免费手机网站空间申请背景#xff1a;
关于如何在机器上拉terraform代码#xff0c;初始化就不重复了#xff0c;需要的可以查看前面的文章#xff1a;
【Terraform学习】Terraform-AWS部署快速入门#xff08;快速入门#xff09;_向往风的男子的博客-CSDN博客
管理显式依赖关系 隐式依赖…背景
关于如何在机器上拉terraform代码初始化就不重复了需要的可以查看前面的文章
【Terraform学习】Terraform-AWS部署快速入门快速入门_向往风的男子的博客-CSDN博客
管理显式依赖关系 隐式依赖关系是 Terraform 了解资源之间关系的主要方式。 但是有时资源之间存在对Terraform不可见的依赖关系。 depends_on该参数可以为资源创建显式依赖关系。 为了说明这一点假设您在 EC2 实例上运行一个应用程序该应用程序预期使用特定的 Amazon S3 存储桶。 此依赖项是在应用程序内部配置的因此对 Terraform 不可见。 您可以使用显式声明依赖项。您还可以在参数中指定多个资源Terraform 将等到所有资源都已创建完毕后再创建目标资源。 提示由于 Terraform 将等到创建指定资源后再创建依赖资源因此添加显式依赖项可能会增加 Terraform 创建基础结构所需的时间。 将以下内容添加到main.tf。 resource aws_s3_bucket example {acl private
}resource aws_instance example_c {ami data.aws_ami.amazon_linux.idinstance_type t2.microdepends_on [aws_s3_bucket.example]
}module example_sqs_queue {source terraform-aws-modules/sqs/awsversion 2.1.0depends_on [aws_s3_bucket.example, aws_instance.example_c]
} 此配置包括对新模块的引用。必须先安装模块然后 Terraform 才能使用它们。 terraform get 现在应用更改 terraform apply 您将看到类似于以下内容的输出。 aws_s3_bucket.example: Creating...
aws_s3_bucket.example: Still creating... [10s elapsed]
## ...
aws_s3_bucket.example: Creation complete after 1m0s [idterraform-20200813175124184300000001]
aws_instance.example_c: Creating...
aws_instance.example_c: Still creating... [10s elapsed]
aws_instance.example_c: Still creating... [20s elapsed]
aws_instance.example_c: Still creating... [30s elapsed]
aws_instance.example_c: Still creating... [40s elapsed]
aws_instance.example_c: Creation complete after 44s [idi-08a44071a2517179f]
module.example_sqs_queue.aws_sqs_queue.this[0]: Creating...
module.example_sqs_queue.aws_sqs_queue.this[0]: Creation complete after 6s [idhttps://sqs.us-west-1.amazonaws.com/561656980159/terraform-20200813175223563000000002]
module.example_sqs_queue.data.aws_arn.this[0]: Reading...
module.example_sqs_queue.data.aws_arn.this[0]: Read complete after 0s [idarn:aws:sqs:us-west-1:561656980159:terraform-20200813175223563000000002]Apply complete! Resources: 3 added, 0 changed, 0 destroyed. 由于实例和 SQS 队列都依赖于 S3 存储桶因此 Terraform 会等到创建存储桶后再开始创建其他两个资源。