I've been trying to restructure my terraform modules in a way that things can be reused. The issue I'm trying to resolve here is to avoid creating new tf modules with just one or two new attributes that are meant for certain setup.
The current structure:
├── services
│ ├── ec2
│ │ └── terragrunt.hcl
│ ├── ec2_with_fixed_ip
│ │ └── terragrunt.hcl (2)
│ └── terragrunt.hcl (1)
├── tf_moodules
└── ec2
│ └── main.tf
└── ec2_with_fixed_ip
│ └── main.tf
└── ec2_with_root_block_device
└── main.tf
I've also been looking at using the terraform-aws-ec2-instance git repo as the source in my terragrunt script. This way, I won't have to manage the tf modules at all. But I'm not sure how I should write my terragrunt.hcl to point to the GitHub repo and peg to a certain version.
Is this a recommended way of doing things? or is there a cleaner way to do it?
Content inside the terragrunt.hcl (1)
remote_state {
backend = "s3"
config = {
encrypt = true
bucket = "my_bucket"
key = "${path_relative_to_include()}/terraform.tfstate"
region = "ap-southeast-1"
dynamodb_table = "tf-locks"
}
}
Content inside the terragrunt.hcl (2)
terraform {
source = "git::https://github.com/terraform-aws-modules/terraform-aws-ec2-instance.git//?ref=v2.15.0"
}
include {
path = find_in_parent_folders()
}
inputs = {
ami = "ami-0123456789abcd"
instance_type = "t3.medium"
disable_api_termination = false
}
Tried the above setup, but facing the issue with missing backend "s3" block
git::[email protected]:terraform-aws-modules/terraform-aws-ec2-instance.git//?ref=v2.15.0
) but that's mostly a matter of preference. – Ben Whaley