Skip to content

Conversation

mariusmagureanu
Copy link

@mariusmagureanu mariusmagureanu commented Sep 2, 2025

Synopis

This PR aims to introduce some minimal Terraform best practices, along with a newer TF and AWS provider version.


Implementation

  • prefer lower case variables, upper case ones are usually reserved for environment variables
  • prefer underscore instead of dashes in resource or data-lookup names
  • run terraform fmt against all terraform files
  • prefer variables instead of hardcoded values in data-lookups
  • remove default values for mandatory variables (e.g. key_name)
  • extend the README with Terraform requirements/providers/inputs/outputs
  • added a pre-commit goodie to format tf files and update the README file accordingly
  • moved from t2.micro to t3.micro as default instance type

Notes

The tables in the README file have automatically been generated with:

by running the folllowing in the terraform-aws folder:

$ pre-commit run --show-diff-on-failure --all-files terraform_docs

Potential trouble

This section is relevant only if you already have provisioned infrastructure. Otherwise, if starting from scratch - skip the following lines.

The tf-ve6 resource has been renamed to tf_ve6.

If you'll plan this code against already provisioned infra, then Terraform will attempt to create a new aws_instance resource.

You most likely don't want that - as you already have the instance you need. However, this situation can easily be handled using the Terraform moved block.

Example:

moved {
    from = aws_instance.tf-ve6
    to = aws_instance.tf_ve6
}

@mariusmagureanu mariusmagureanu marked this pull request as ready for review September 2, 2025 20:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant