Skip to content

JamesWoolfenden/terraform-aws-kms

Repository files navigation

terraform-aws-kms

Build Status Latest Release GitHub tag (latest SemVer) Terraform Version Infrastructure Tests pre-commit checkov Infrastructure Tests


Terraform module - Create and optionally shares kms key to other accounts.


It's 100% Open Source and licensed under the APACHE2.

alt text

Usage

Include this repository as a module in your existing Terraform code:

module "efs" {
  source      = "JamesWoolfenden/kms/aws"
  version     = "v0.0.11"
  common_tags = var.common_tags
  key         = var.key
  user_policy = data.aws_iam_policy_document.kms.json
  alias       = var.alias
}

The example in the examplea folder shows how to pass your own policy in when creating your key.

If you want to share to other AWS accounts add values to a list called accounts to the module reference with the account ids, and set your own values to the map key.

Requirements

No requirements.

Providers

Name Version
aws n/a

Modules

No modules.

Resources

Name Type
aws_kms_alias.key resource
aws_kms_key.secure resource

Inputs

Name Description Type Default Required
alias KMS alias string "alias/ami-sharing" no
common_tags This is to help you add tags to your cloud objects map(any) n/a yes
is_enabled n/a bool true no
key Details of the key
object({
description = string
deletion_window_in_days = number
key_usage = string
customer_master_key_spec = string
})
{
"customer_master_key_spec": "SYMMETRIC_DEFAULT",
"deletion_window_in_days": 10,
"description": "KMS key 1",
"key_usage": "ENCRYPT_DECRYPT"
}
no
user_policy Allow Key policies to be user supplied string "" no

Outputs

Name Description
alias n/a
secure n/a

Policy

This is the policy required to build this project:

The Terraform resource required is:

resource "aws_iam_policy" "terraform_pike" {
  name_prefix = "terraform_pike"
  path        = "/"
  description = "Pike Autogenerated policy from IAC"

  policy = jsonencode({
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "VisualEditor0",
            "Effect": "Allow",
            "Action": [
                "kms:CreateAlias",
                "kms:CreateKey",
                "kms:DeleteAlias",
                "kms:DescribeKey",
                "kms:DisableKey",
                "kms:EnableKey",
                "kms:EnableKeyRotation",
                "kms:GetKeyPolicy",
                "kms:GetKeyRotationStatus",
                "kms:ListAliases",
                "kms:ListResourceTags",
                "kms:PutKeyPolicy",
                "kms:ScheduleKeyDeletion",
                "kms:TagResource",
                "kms:UntagResource"
            ],
            "Resource": "*"
        }
    ]
})
}

Related Projects

Check out these related projects.

Help

Got a question?

File a GitHub issue.

Contributing

Bug Reports & Feature Requests

Please use the issue tracker to report any bugs or file feature requests.

Copyrights

Copyright © 2019-2022 James Woolfenden

License

License

See LICENSE for full details.

Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

https://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Contributors

James Woolfenden
James Woolfenden