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

     1  ---
     2  page_title: Provisioners Without a Resource
     3  description: >-
     4    A null_resource allows you to configure provisioners that are not directly
     5    associated with a single existing resource.
     6  ---
     7  
     8  # Provisioners Without a Resource
     9  
    10  [null]: https://registry.terraform.io/providers/hashicorp/null/latest/docs/resources/resource
    11  
    12  If you need to run provisioners that aren't directly associated with a specific
    13  resource, you can associate them with a `null_resource`.
    14  
    15  Instances of [`null_resource`][null] are treated like normal resources, but they
    16  don't do anything. Like with any other resource, you can configure
    17  [provisioners](/language/resources/provisioners/syntax) and [connection
    18  details](/language/resources/provisioners/connection) on a `null_resource`. You can also
    19  use its `triggers` argument and any meta-arguments to control exactly where in
    20  the dependency graph its provisioners will run.
    21  
    22  ## Example usage
    23  
    24  ```hcl
    25  resource "aws_instance" "cluster" {
    26    count = 3
    27  
    28    # ...
    29  }
    30  
    31  resource "null_resource" "cluster" {
    32    # Changes to any instance of the cluster requires re-provisioning
    33    triggers = {
    34      cluster_instance_ids = "${join(",", aws_instance.cluster.*.id)}"
    35    }
    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 = "${element(aws_instance.cluster.*.public_ip, 0)}"
    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  ```
    51  
    52  ## Argument Reference
    53  
    54  In addition to meta-arguments supported by all resources, `null_resource`
    55  supports the following specific arguments:
    56  
    57  - `triggers` - A map of values which should cause this set of provisioners to
    58    re-run. Values are meant to be interpolated references to variables or
    59    attributes of other resources.