Terraform resources

From wikinotes
Revision as of 17:03, 25 September 2022 by Will (talk | contribs) (Created page with "Resources are the composable building blocks of your terraform configuration. = Documentation = <blockquote> {| class="wikitable" |- | overview || https://www.terraform.io/language/resources |- | provisioners || https://www.terraform.io/language/resources/provisioners/syntax |- |} </blockquote><!-- Documentation --> = Meta Arguments = <blockquote> Meta Arguments are available on all resource types, and allow you to customize how they are built. <syntaxhighlight lang="...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Resources are the composable building blocks of your terraform configuration.

Documentation

overview https://www.terraform.io/language/resources
provisioners https://www.terraform.io/language/resources/provisioners/syntax

Meta Arguments

Meta Arguments are available on all resource types, and allow you to customize how they are built.

provider    # google, aws, ...
depends_on  # build-order
count
for_each
lifecycle

Provisioners

You can use provisioners to hand off the additional information to another configuration management tool.

resource "aws_instance" "web" {
  # ...

  provisioner "local-exec" {
    command = "echo The server's IP address is ${self.private_ip}"
  }
}

Provisioner communication-style can be configured with a connection block.

provisioner "file" {
  source      = "conf/myapp.conf"
  destination = "/etc/myapp.conf"

  connection {
    type     = "ssh"
    user     = "root"
    password = "${var.root_password}"
    host     = "${var.host}"
  }
}

There are three types of provisioners:

file https://www.terraform.io/language/resources/provisioners/file
local-exec https://www.terraform.io/language/resources/provisioners/local-exec
remote-exec https://www.terraform.io/language/resources/provisioners/remote-exec