28
loading...
This website collects cookies to deliver better user experience
aws cli
and boto3
, while this worked it was missing key features like state management, allowing quick disaster recovery, and maintainability. We decided to use terraform as our tool in the end and in this article I will be covering how we used Terraform and yaml files to be in sync with our in house solutions..tfvars
files to maintain our configurations. However, as soon as we wrote our initial configurations, there was a large unreadability issue and an increasing complexity of duplicate configurations stored in different formats, to ensure we keep a single source of truth we made the choice of implementing our existing pattern of using yaml
configurations for our migration.Note: The implementation was written using terraform version 0.14.6
, and has not been tested on 1.0.0
yet.
for_each
, lookup
and flatten
. It is highly recommended to go through the docs to get a better understanding of how it works. yamldecode
- helps in formatting your yaml file into a map object that terraform can read from.flatten
- helps in restructuring nested maps into a more readable map that is easier to access by terraform functions.n
sqs queues just by adding new configurations in the yaml
file. The following file helps in doing that, using for_each
for queue in local.sqs_standard_queues : queue.name => queue
"production-example-queue-dlq": {
"access_policy": "basic"
"dlq": null
"name": "production-example-queue-dlq"
"type": "standard"
}
for_each
- Iterate through each key in the map generated above and creates a resource as shown below in the plan.aws_sqs_queue.sqs_standard_queues["production-example-queue-dlq"]
Note: The above statement is also how we need to reference the queue in a different resource
if
- Helps to condense the list based on meeting the criteria if the key dlq exists or not.each.value.*
- each references to the key
. value
references to the value of the key and the *
can be any of the keys that we set in our locals.map
.terraform console
> local.sqs_queues #prints out the yaml file decoded
> local.sqs_standard_queues #prints out the flattened object
.tfvars
files to abstract away complexity from our infrastructure users, which in turn introduces a burden on our users to understand how terraforms language works. By leveraging yaml for configuration as code, as our user interface, we empower our infrastructure users to easily create new resources and stacks using a language they are already familiar with.