Skip to content

Instantly share code, notes, and snippets.

@miranda-zhang
Last active March 5, 2024 09:34
Show Gist options
  • Save miranda-zhang/9e54e2f202b0bb2686e224b35de1268a to your computer and use it in GitHub Desktop.
Save miranda-zhang/9e54e2f202b0bb2686e224b35de1268a to your computer and use it in GitHub Desktop.
terraform command and examples

Terraform

uninstall

brew uninstall --force terraform
brew cleanup -s terraform

tfswitch

tfenv

Debug

Remove lock

terraform force-unlock <LOCK_ID>

aws_iam_policy

resource "aws_iam_policy" "allow_kms_decrypt_letsEncryptKey" {
  name        = "tf-policy-${var.instance_name}_access_kms_letsEncryptKey"
  path        = "/"
  description = "Give certificate manager access to letsEncryptKey via KMS"
  policy = "${data.template_file.allow_kms_decrypt_letsEncryptKey.rendered}"
}

resource "aws_iam_role_policy_attachment" "attach_kms_decrypt_letsEncryptKey_to_role" {
  role       = "${aws_iam_role.certificate_manager_role.name}"
  policy_arn = "${aws_iam_policy.allow_kms_decrypt_letsEncryptKey.arn}"
}

data "template_file" "allow_route53_ListResourceRecordSets" {
  template = "${file("../common-modules/aws/policy/route53/ListResourceRecordSets.json.tpl")}"
  vars = {
    resource = "arn:aws:kms:us-east-1:494770124270:key/400e47b4-8562-4015-a14d-857dc3f388e6"
  }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment