Terragrunt¶
Imported from Confluence
Content may be outdated. Verify before following any procedures. View original | Last updated: January 2023
Tips and tricks¶
Remote source on git¶
- if you work with deployment/module in remote git and doesn’t change version for every change (which is impossible if module development just in progress) you will to commit every change and then either remove .terragrunt-cache or use terragrunt apply --terragrunt-source-update
- much easier way, while you are developing is to replace source to local directory like here:
terragrunt apply --terragrunt-source /Users/ddenyshchenko/wd/github/fyber/devops/gitlab-bln-terraform-library//deployments/standalone-instances/v0.0.3
Dependencies¶
And another feature which we should mandatory use. In AWS terraform we use data “terraform_remote_state” to get outputs from other deployments. In GCP we develop new deployments/modules without any reference to environments, so it should not reference any remote states. But this causes us to hardcode may parameters in terragrunt.hcl files. Terragrunt has solution for this. For example I deployed 5 instances for kafka and want to add dns records for instances. I added following output to standalone-instances/v0.0.3:
output "instances_ip" {
value = {for k, v in google_compute_instance.main : k => v.network_interface.0.network_ip}
}
which will produce following output:
Apply complete! Resources: 0 added, 0 changed, 0 destroyed.
Outputs:
instances_ip = {
"vm-kafka-core-offerwall-prod-useast1-0" = "10.186.0.25"
"vm-kafka-core-offerwall-prod-useast1-1" = "10.186.0.28"
"vm-kafka-core-offerwall-prod-useast1-2" = "10.186.0.27"
"vm-kafka-core-offerwall-prod-useast1-3" = "10.186.0.26"
"vm-kafka-core-offerwall-prod-useast1-4" = "10.186.0.24"
}
Now in cloud-dns config file terragrunt.hcl I add
and records:
{
name = "kafka-core-0"
type = "A"
ttl = 300
records = [
dependency.kafka-core.outputs.instances_ip.vm-kafka-core-offerwall-prod-useast1-0,
]
},
so, if instances will be redeployed and change it’s ip, we need to just reapply cloud-dns without updating manually ip addresses