devops:terraform
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| devops:terraform [2022/09/22 16:37] – 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 16: | Line 26: | ||
| https:// | https:// | ||
| - | Apply terraform bash script | + | == Apply terraform bash script |
| <sxh bash> | <sxh bash> | ||
| Line 31: | Line 41: | ||
| #terraform apply | #terraform apply | ||
| + | </ | ||
| + | == Upgrade terraform provider == | ||
| - | </sxh> | + | https:// |
| + | <sxh bash> | ||
| + | terraform init -upgrade | ||
| + | |||
| + | Initializing the backend... | ||
| + | |||
| + | Initializing provider plugins... | ||
| + | - Finding hashicorp/ | ||
| + | - Installing hashicorp/ | ||
| + | - Installed hashicorp/ | ||
| + | |||
| + | Terraform has made some changes to the provider dependency selections recorded | ||
| + | in the .terraform.lock.hcl file. Review those changes and commit them to your | ||
| + | version control system if they represent changes you intended to make. | ||
| + | |||
| + | Terraform has been successfully initialized! | ||
| + | </ | ||
| === Main === | === Main === | ||
| Line 104: | 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 142: | 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.1663864633.txt.gz · Last modified: by skipidar
