Skip to content

Instantly share code, notes, and snippets.

// ref: https://packer.io/docs/builders/amazon.html#iam-task-or-instance-role
{
"Statement": [
{
"Sid": "PackerSecurityGroupAccess",
"Action": [
"ec2:CreateSecurityGroup",
"ec2:DeleteSecurityGroup",
"ec2:DescribeSecurityGroups",
"ec2:AuthorizeSecurityGroupIngress",
@houdinisparks
houdinisparks / provisioners.hcl
Last active February 24, 2020 01:59
using triggers to control provisioners
module "db" {
source = "https://github.com/terraform-aws-modules/terraform-aws-rds"
# ...
}
resource "null_resource" "rds_setup" {
# Don't run this if we're restoring from a snapshot
count = var.db_snapshot_id == "" ? 1 : 0
remote_state {
backend = "s3"
config = {
# ...
# use VPC endpoints for STS https://docs.aws.amazon.com/IAM/latest/UserGuide/id_credentials_sts_vpce.html
sts_endpoint = "sts.ap-southeast-1.amazonaws.com"
# ...
}
}
terraform {
# an example of a resource that will always throw a folder error
# due to abspath saved in state.
resource "local_file" "rds_bootstrap" {
content = templatefile("scripts/sql_bootstrap.sh", {
# ...
})
filename = "${abspath(path.module)}/rendered/sql_bootstrap.sh"
}
# path: ./modules/naming_conventions/main.tf
# apply all naming conventions in this module
variable "environment" {}
variable "project_code" {}
variable "agency" {}
locals {
iam_policy_name_prefix = format(
"iam-policy-%s-%snana",
# path: environments/shared/terragrunt.hcl
locals {
environment = "shared"
}
remote_state {
backend = "s3"
config = {
bucket = "bgp-terraform"
#...
# path: get_parent_terragrunt_dir()/terraform.tf
terraform {
backend "s3" {}
}
provider "aws" {
region = "ap-southeast-1"
endpoints {
sts = "https://sts.ap-southeast-1.amazonaws.com"
}
@houdinisparks
houdinisparks / terragrunt.hcl
Last active March 12, 2020 01:28
terragrunt
locals {
environment = "lower"
aws_region = "ap-southeast-1"
}
remote_state {
backend = "s3"
config = {
bucket = "bgp-terraform"
region = "${local.aws_region}"
# ./modules/route53/variables.tf
variable "environment" {
default = "dev"
}
variable "ips" {
default =
{
smtp = ["10.x.x.x"]
}
@houdinisparks
houdinisparks / smtp_example.tf
Last active February 16, 2020 09:56
medium_terragrunt
# ./modules/route53/variables.tf
variable "environment_map" {
default = {
dev = {
smtp_ips = ["10.3.0.135"]
}
ci = {
smtp_ips = ["10.3.0.135"]
}