Terraform 2.0 Resource terraform_data
2023-10-04 12:53:53    6    0    0
admin

不会做任何操作的resource,用于存放数据

官方案例
用于版本控制

  1. variable "revision" {
  2. default = 1
  3. }
  4. resource "terraform_data" "replacement" {
  5. input = var.revision
  6. }
  7. # This resource has no convenient attribute which forces replacement,
  8. # but can now be replaced by any change to the revision variable value.
  9. resource "example_database" "test" {
  10. lifecycle {
  11. replace_triggered_by = [terraform_data.replacement]
  12. }
  13. }

用于触发脚本

  1. resource "aws_instance" "web" {
  2. # ...
  3. }
  4. resource "aws_instance" "database" {
  5. # ...
  6. }
  7. # A use-case for terraform_data is as a do-nothing container
  8. # for arbitrary actions taken by a provisioner.
  9. resource "terraform_data" "bootstrap" {
  10. triggers_replace = [
  11. aws_instance.web.id,
  12. aws_instance.database.id
  13. ]
  14. provisioner "local-exec" {
  15. command = "bootstrap-hosts.sh"
  16. }
  17. }

上一篇: Terraform 1.0 AWS Provider

下一篇: Terraform 3.0 DataSource

文档导航