Terraform resources: Difference between revisions
From wikinotes
(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="...") |
|||
Line 26: | Line 26: | ||
= Provisioners = | = Provisioners = | ||
<blockquote> | |||
== Basics == | |||
<blockquote> | <blockquote> | ||
You can use provisioners to hand off the additional information to another configuration management tool. | You can use provisioners to hand off the additional information to another configuration management tool. | ||
Line 38: | Line 40: | ||
} | } | ||
</syntaxhighlight> | </syntaxhighlight> | ||
</blockquote><!-- Basics --> | |||
== Connections == | |||
<blockquote> | |||
Provisioner communication-style can be configured with a <code>connection</code> block. | Provisioner communication-style can be configured with a <code>connection</code> block. | ||
<syntaxhighlight lang="tf"> | <syntaxhighlight lang="tf"> | ||
Line 53: | Line 58: | ||
} | } | ||
</syntaxhighlight> | </syntaxhighlight> | ||
</blockquote><!-- Connections --> | |||
== Builtin Provisioners == | |||
<blockquote> | |||
There are three types of provisioners: | There are three types of provisioners: | ||
Line 65: | Line 73: | ||
|- | |- | ||
|} | |} | ||
</blockquote><!-- Builtin Provisioners --> | |||
== External Provisioners == | |||
<blockquote> | |||
You can also require external providers.<br> | |||
They are configured within the toplevel <code>terraform</code> block. | |||
<syntaxhighlight lang="tf"> | |||
terraform { | |||
required_providers { | |||
mycloud = { | |||
source = "mycorp/mycloud" | |||
version = "~> 1.0" | |||
} | |||
} | |||
} | |||
</syntaxhighlight> | |||
Version request syntax | |||
<syntaxhighlight lang="tf"> | |||
"~> 1.0.4" # I believe this is like ruby, putting upper bound on digit above last defined | |||
">= 1.0" | |||
</syntaxhighlight> | |||
</blockquote><!-- External Provisioners --> | |||
</blockquote><!-- Provisioners --> | </blockquote><!-- Provisioners --> |
Latest revision as of 17:18, 25 September 2022
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
Basics
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}" } }Connections
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}" } }Builtin Provisioners
There are three types of provisioners:
External Provisioners
You can also require external providers.
They are configured within the toplevelterraform
block.terraform { required_providers { mycloud = { source = "mycorp/mycloud" version = "~> 1.0" } } }Version request syntax
"~> 1.0.4" # I believe this is like ruby, putting upper bound on digit above last defined ">= 1.0"