Course outlines for learning terraform.
expected time | requirements |
---|---|
60 minutes | A computer with Terraform installed, terraform knowledge. |
Goal: Be able to decide when to use the lifecycle
meta argument and implement it.
In some situations, Terraform needs to destroy and create a resource on changes. This means services may be interrupted. the lifecycle
meta argument can prevent this.
Be aware that you need to prevent conflicts in names of resources, ports, and likely other parameters.
This type of deployment is ofter referred to as blue-green deployment.
See this Docker demo or this local-file demo
variables.tf
to define a variable like deployment
or so.lifecycle
meta argument to main.tf
azurerm_container_group.example.name
to use the variable defined in variables.tf
.azurerm_container_group.example.dns_name_label
to use the variable defined in variables.tf
.-var="deployment=1"
.-var="deployment=2"
.-var="deployment=1"
.azurerm_container_group.example: Creating...
azurerm_container_group.example: Still creating... [10s elapsed]
...
azurerm_container_group.example: Still creating... [1m10s elapsed]
azurerm_container_group.example: Creation complete after 1m16s [id=/subscriptions/27c6a60b-0aed-4e75-a7ea-f5cf2e49f89e/resourceGroups/example-resources/providers/Microsoft.ContainerInstance/containerGroups/example-continst-2]
azurerm_container_group.example: Destroying... [id=/subscriptions/27c6a60b-0aed-4e75-a7ea-f5cf2e49f89e/resourceGroups/example-resources/providers/Microsoft.ContainerInstance/containerGroups/example-continst]
azurerm_container_group.example: Still destroying... [id=/subscriptions/27c6a60b-0aed-4e75-a7ea-...tance/containerGroups/example-continst, 10s elapsed]
...
azurerm_container_group.example: Still destroying... [id=/subscriptions/27c6a60b-0aed-4e75-a7ea-...tance/containerGroups/example-continst, 1m10s elapsed]
azurerm_container_group.example: Destruction complete after 1m13s