devops:terraform
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
devops:terraform [2023/10/14 06:34] – skipidar | devops:terraform [2024/04/03 19:53] (current) – skipidar | ||
---|---|---|---|
Line 1: | Line 1: | ||
===== Terraform ===== | ===== Terraform ===== | ||
+ | |||
+ | ===Debugging=== | ||
+ | |||
+ | |||
+ | <sxh shell> | ||
+ | # https:// | ||
+ | # investigage errors | ||
+ | export TF_LOG=" | ||
+ | export TF_LOG_PATH=" | ||
+ | </ | ||
===Glossary=== | ===Glossary=== | ||
Line 122: | Line 132: | ||
=== Data === | === Data === | ||
+ | |||
+ | When you define '' | ||
+ | |||
+ | <sxh json> | ||
+ | |||
+ | </ | ||
+ | |||
+ | You can apply filters. | ||
+ | |||
+ | <sxh json> | ||
+ | |||
+ | # Find the latest available AMI that is tagged with Component = web | ||
+ | data " | ||
+ | filter { | ||
+ | name = " | ||
+ | values = [" | ||
+ | } | ||
+ | |||
+ | filter { | ||
+ | name = " | ||
+ | values = [" | ||
+ | } | ||
+ | |||
+ | most_recent = true | ||
+ | } | ||
+ | </ | ||
+ | |||
Create **templates.tf** | Create **templates.tf** | ||
Line 160: | Line 197: | ||
} | } | ||
</ | </ | ||
+ | |||
+ | |||
+ | === Dynamic block === | ||
+ | |||
+ | See https:// | ||
+ | |||
+ | To replace the repetitive code as here in a module: | ||
+ | <sxh json> | ||
+ | resource " | ||
+ | name = " | ||
+ | resource_group_name = azurerm_resource_group.dynamic_block.name | ||
+ | location | ||
+ | address_space | ||
+ | |||
+ | subnet { | ||
+ | name = " | ||
+ | address_prefix = " | ||
+ | } | ||
+ | |||
+ | subnet { | ||
+ | name = " | ||
+ | address_prefix = " | ||
+ | } | ||
+ | |||
+ | subnet { | ||
+ | name = " | ||
+ | address_prefix = " | ||
+ | } | ||
+ | |||
+ | subnet { | ||
+ | name = " | ||
+ | address_prefix = " | ||
+ | } | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | |||
+ | Use the " | ||
+ | |||
+ | <sxh json> | ||
+ | resource " | ||
+ | name = " | ||
+ | resource_group_name = azurerm_resource_group.dynamic_block.name | ||
+ | location | ||
+ | address_space | ||
+ | |||
+ | dynamic " | ||
+ | for_each = var.subnets | ||
+ | iterator = item # | ||
+ | content { | ||
+ | name = item.value.name | ||
+ | address_prefix = item.value.address_prefix | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | |||
+ | </ | ||
+ | |||
+ | |||
+ | Declare a variable in your module | ||
+ | <sxh json> | ||
+ | variable " | ||
+ | description = "list of values to assign to subnets" | ||
+ | type = list(object({ | ||
+ | name = string | ||
+ | address_prefix = string | ||
+ | })) | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | |||
+ | **USAGE of your module** | ||
+ | |||
+ | Assigning values to the variable " | ||
+ | |||
+ | <sxh json> | ||
+ | subnets = [ | ||
+ | { name = " | ||
+ | { name = " | ||
+ | { name = " | ||
+ | { name = " | ||
+ | ] | ||
+ | </ | ||
+ |
devops/terraform.1697265277.txt.gz · Last modified: by skipidar