Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Terragrunt KMS module #96

Merged
merged 4 commits into from
Nov 3, 2021
Merged

feat: Terragrunt KMS module #96

merged 4 commits into from
Nov 3, 2021

Conversation

patheard
Copy link
Member

@patheard patheard commented Nov 3, 2021

Summary

Creates the Customer Managed Keys (CMKs) that are used to
encypt/decrypt CloudWatch and DynamoDB data.

Also includes Terraform static analysis workflow with checkov.

Ref: original source for module is 014e912

Related

Creates the Customer Managed Keys (CMKs) that are used to
encypt/decrypt CloudWatch and DynamoDB data.
@github-actions
Copy link

github-actions bot commented Nov 3, 2021

Scratch: kms

✅   Terraform Format: success
✅   Terraform Plan: success
✅   Conftest: success

Plan: 2 to add, 0 to change, 0 to destroy
Show plan
Resource actions are indicated with the following symbols:
  + create

Terraform will perform the following actions:

  # aws_kms_key.cloudwatch will be created
  + resource "aws_kms_key" "cloudwatch" {
      + arn                                = (known after apply)
      + bypass_policy_lockout_safety_check = false
      + customer_master_key_spec           = "SYMMETRIC_DEFAULT"
      + description                        = "CloudWatch Log Group Key"
      + enable_key_rotation                = true
      + id                                 = (known after apply)
      + is_enabled                         = true
      + key_id                             = (known after apply)
      + key_usage                          = "ENCRYPT_DECRYPT"
      + policy                             = jsonencode(
            {
              + Statement = [
                  + {
                      + Action    = "kms:*"
                      + Effect    = "Allow"
                      + Principal = {
                          + AWS = "arn:aws:iam::722713121070:root"
                        }
                      + Resource  = "*"
                      + Sid       = "Enable IAM User Permissions"
                    },
                  + {
                      + Action    = [
                          + "kms:ReEncrypt*",
                          + "kms:GenerateDataKey*",
                          + "kms:Encrypt*",
                          + "kms:Describe*",
                          + "kms:Decrypt*",
                        ]
                      + Effect    = "Allow"
                      + Principal = {
                          + Service = "logs.ca-central-1.amazonaws.com"
                        }
                      + Resource  = "*"
                      + Sid       = ""
                    },
                  + {
                      + Action    = [
                          + "kms:GenerateDataKey*",
                          + "kms:Decrypt",
                        ]
                      + Effect    = "Allow"
                      + Principal = {
                          + Service = "cloudwatch.amazonaws.com"
                        }
                      + Resource  = "*"
                      + Sid       = "Allow_CloudWatch_for_CMK"
                    },
                  + {
                      + Action    = [
                          + "kms:ReEncrypt*",
                          + "kms:GenerateDataKey*",
                          + "kms:Encrypt*",
                          + "kms:Describe*",
                          + "kms:Decrypt*",
                        ]
                      + Effect    = "Allow"
                      + Principal = {
                          + Service = "events.amazonaws.com"
                        }
                      + Resource  = "*"
                      + Sid       = "CloudwatchEvents"
                    },
                ]
              + Version   = "2012-10-17"
            }
        )
      + tags                               = {
          + "CostCentre" = "forms-platform-scratch"
          + "Terraform"  = "true"
        }
      + tags_all                           = {
          + "CostCentre" = "forms-platform-scratch"
          + "Terraform"  = "true"
        }
    }

  # aws_kms_key.dynamo_db will be created
  + resource "aws_kms_key" "dynamo_db" {
      + arn                                = (known after apply)
      + bypass_policy_lockout_safety_check = false
      + customer_master_key_spec           = "SYMMETRIC_DEFAULT"
      + description                        = "KMS key for DynamoDB encryption"
      + enable_key_rotation                = true
      + id                                 = (known after apply)
      + is_enabled                         = true
      + key_id                             = (known after apply)
      + key_usage                          = "ENCRYPT_DECRYPT"
      + policy                             = jsonencode(
            {
              + Statement = [
                  + {
                      + Action    = "kms:*"
                      + Effect    = "Allow"
                      + Principal = {
                          + AWS = "arn:aws:iam::722713121070:root"
                        }
                      + Resource  = "*"
                      + Sid       = "Enable IAM User Permissions"
                    },
                  + {
                      + Action    = [
                          + "kms:ReEncrypt*",
                          + "kms:GenerateDataKey*",
                          + "kms:Encrypt",
                          + "kms:DescribeKey",
                          + "kms:Decrypt",
                          + "kms:CreateGrant",
                        ]
                      + Condition = {
                          + StringLike = {
                              + kms:ViaService = [
                                  + "dynamodb.*.amazonaws.com",
                                ]
                            }
                        }
                      + Effect    = "Allow"
                      + Principal = {
                          + AWS = "arn:aws:iam::722713121070:root"
                        }
                      + Resource  = "*"
                      + Sid       = "Allow access through Amazon DynamoDB for all principals in the account that are authorized to use Amazon DynamoDB"
                    },
                  + {
                      + Action    = [
                          + "kms:List*",
                          + "kms:Get*",
                          + "kms:Describe*",
                        ]
                      + Effect    = "Allow"
                      + Principal = {
                          + Service = "dynamodb.amazonaws.com"
                        }
                      + Resource  = "*"
                      + Sid       = "Allow DynamoDB to get information about the CMK"
                    },
                ]
              + Version   = "2012-10-17"
            }
        )
      + tags                               = {
          + "CostCentre" = "forms-platform-scratch"
          + "Terraform"  = "true"
        }
      + tags_all                           = {
          + "CostCentre" = "forms-platform-scratch"
          + "Terraform"  = "true"
        }
    }

Plan: 2 to add, 0 to change, 0 to destroy.

Changes to Outputs:
  + kms_key_cloudwatch_arn = (known after apply)
  + kms_key_dynamodb_arn   = (known after apply)

─────────────────────────────────────────────────────────────────────────────

Saved the plan to: plan.tfplan

To perform exactly these actions, run the following command to apply:
    terraform apply "plan.tfplan"
Show Conftest results
9 tests, 9 passed, 0 warnings, 0 failures, 0 exceptions

@patheard patheard merged commit db73e2e into main Nov 3, 2021
@patheard patheard deleted the feat/terragrunt-kms branch November 3, 2021 15:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants