Skip to content

EliasOulkadi/shokunin / .pack/skills/terraform

terraform

Unverified

Design and manage infrastructure as code with Terraform — modules, remote state (S3 + DynamoDB), Stacks (deployments), test framework, preconditions/postconditions, moved/removed blocks, and CI/CD plan/apply separation. Use when user asks to write Terraform config, set up remote state, design modules, manage state, or automate infrastructure. Do NOT use for Kubernetes (use kubernetes), Docker (use docker), or CI/CD pipeline design (use ci-cd).

assets/module-template/main.tf

View on GitHub
# main.tf — Module template
# Copy this directory as a starting point for new modules.

data "aws_caller_identity" "current" {}
data "aws_region" "current" {}

resource "aws_kms_alias" "this" {
  name_prefix   = "alias/${var.name}-"
  target_key_id = aws_kms_key.this.id
}

resource "aws_kms_key" "this" {
  description             = var.description
  deletion_window_in_days = var.deletion_window_in_days
  enable_key_rotation     = var.enable_key_rotation
  policy                  = data.aws_iam_policy_document.this.json

  lifecycle {
    precondition {
      condition     = var.deletion_window_in_days >= 7 && var.deletion_window_in_days <= 30
      error_message = "KMS key deletion window must be between 7 and 30 days"
    }

    precondition {
      condition     = can(regex("^[a-z0-9-]+$", var.name))
      error_message = "Name must contain only lowercase letters, numbers, and hyphens"
    }

    postcondition {
      condition     = self.arn != ""
      error_message = "KMS key was created without an ARN"
    }
  }
}

data "aws_iam_policy_document" "this" {
  version = "2012-10-17"
  statement {
    sid    = "Enable IAM User Permissions"
    effect = "Allow"
    principals {
      type        = "AWS"
      identifiers = ["arn:aws:iam::${data.aws_caller_identity.current.account_id}:root"]
    }
    actions   = ["kms:*"]
    resources = ["*"]
  }

  dynamic "statement" {
    for_each = var.admin_principals
    content {
      sid    = "AllowAdminPrincipals"
      effect = "Allow"
      principals {
        type        = "AWS"
        identifiers = statement.value
      }
      actions = [
        "kms:Create*",
        "kms:Describe*",
        "kms:Enable*",
        "kms:List*",
        "kms:Put*",
        "kms:Update*",
        "kms:Revoke*",
        "kms:Disable*",
        "kms:Get*",
        "kms:ScheduleKeyDeletion",
        "kms:CancelKeyDeletion",
      ]
      resources = ["*"]
    }
  }
}

resource "aws_kms_key_policy" "this" {
  key_id = aws_kms_key.this.id
  policy = data.aws_iam_policy_document.this.json
}

# Grant specific IAM roles access to use the key
resource "aws_kms_grant" "this" {
  for_each          = { for idx, principal in var.grant_principals : idx => principal }
  name              = "${var.name}-grant-${each.key}"
  key_id            = aws_kms_key.this.id
  grantee_principal = each.value
  operations        = var.grant_operations

  lifecycle {
    precondition {
      condition     = contains(["Encrypt", "Decrypt", "GenerateDataKey", "ReEncryptFrom", "ReEncryptTo"], each.value) == false
      error_message = "Grant operations must be valid KMS grant operations"
    }
  }
}
finishing-a-development-branchobra/superpowersUse when implementation is complete, all tests pass, and you need to decide how to integrate the workStars: 322kUpdated Claude CodeCodexVerifiedInstall
systematic-debuggingobra/superpowersUse when encountering any bug, test failure, or unexpected behavior, before proposing fixesStars: 322kUpdated Claude CodeCodexVerifiedInstall
test-driven-developmentobra/superpowersUse when implementing any feature or bugfix, before writing implementation codeStars: 322kUpdated Claude CodeCodexVerifiedInstall
skill-creatoranthropics/skillsCreate new skills, modify and improve existing skills, and measure skill performance. Use when users want to create a skill from scratch, edit, or optimize an existing skill, run evals to test a skill, benchmark skill performance with variance analysis, or optimize a skill's description for better triggering accuracy.Stars: 198kUpdated Claude CodeCodexVerifiedInstall