github.com/pulumi/terraform@v1.4.0/website/docs/language/resources/provisioners/null_resource.mdx (about)

     1  ---
     2  page_title: Provisioners Without a Resource
     3  description: >-
     4    A terraform_data managed resource allows you to configure provisioners that
     5    are not directly associated with a single existing resource.
     6  ---
     7  
     8  # Provisioners Without a Resource
     9  
    10  If you need to run provisioners that aren't directly associated with a specific
    11  resource, you can associate them with a `null_resource`.
    12  
    13  Instances of [`terraform_data`](language/resources/terraform-data) are treated
    14  like normal resources, but they don't do anything. Like with any other resource
    15  type, you can configure [provisioners](/language/resources/provisioners/syntax)
    16  and [connection details](/language/resources/provisioners/connection) on a
    17  `terraform_data` resource. You can also use its `triggers` argument and any
    18  meta-arguments to control exactly where in the dependency graph its
    19  provisioners will run.
    20  
    21  ~> **Important:** Use provisioners as a last resort. There are better alternatives for most situations. Refer to
    22  [Declaring Provisioners](/language/resources/provisioners/syntax) for more details.
    23  
    24  ## Example usage
    25  
    26  ```hcl
    27  resource "aws_instance" "cluster" {
    28    count = 3
    29  
    30    # ...
    31  }
    32  
    33  resource "terraform_data" "cluster" {
    34    # Replacement of any instance of the cluster requires re-provisioning
    35    triggers_replace = aws_instance.cluster.[*].id
    36  
    37    # Bootstrap script can run on any instance of the cluster
    38    # So we just choose the first in this case
    39    connection {
    40      host = aws_instance.cluster.[0].public_ip
    41    }
    42  
    43    provisioner "remote-exec" {
    44      # Bootstrap script called with private_ip of each node in the cluster
    45      inline = [
    46        "bootstrap-cluster.sh ${join(" ", aws_instance.cluster.*.private_ip)}",
    47      ]
    48    }
    49  }
    50  ```