Skip to main content

Module: ssm-iam-role

Terraform module to provision an IAM role with configurable permissions to access SSM Parameter Store.

Introduction

For more information on how to control access to Systems Manager parameters by using AWS Identity and Access Management, see Controlling Access to Systems Manager Parameters.

For more information on how to use parameter hierarchies to help organize and manage parameters, see Organizing Parameters into Hierarchies.

NOTE: This module can be used to provision IAM roles with SSM permissions for chamber.

Usage

This example creates a role with the name cp-prod-app-all with permission to read all SSM parameters, and gives permission to the entities specified in assume_role_arns to assume the role.

module "ssm_iam_role" {
source = "git::https://github.com/cloudposse/terraform-aws-ssm-iam-role.git?ref=master"
namespace = "cp"
stage = "prod"
name = "app"
attributes = ["all"]
region = "us-west-2"
account_id = "XXXXXXXXXXX"
assume_role_arns = ["arn:aws:xxxxxxxxxx", "arn:aws:yyyyyyyyyyyy"]
kms_key_arn = "arn:aws:kms:us-west-2:123454095951:key/aced568e-3375-4ece-85e5-b35abc46c243"
ssm_parameters = ["*"]
ssm_actions = ["ssm:GetParametersByPath", "ssm:GetParameters"]
}

Examples

Example With Permission For Specific Resources

This example creates a role with the name cp-prod-app-secrets with permission to read the SSM parameters that begin with secret-, and gives permission to the entities specified in assume_role_arns to assume the role.

module "ssm_iam_role" {
source = "git::https://github.com/cloudposse/terraform-aws-ssm-iam-role.git?ref=master"
namespace = "cp"
stage = "prod"
name = "app"
attributes = ["secrets"]
region = "us-west-2"
account_id = "XXXXXXXXXXX"
assume_role_arns = ["arn:aws:xxxxxxxxxx", "arn:aws:yyyyyyyyyyyy"]
kms_key_arn = "arn:aws:kms:us-west-2:123454095951:key/aced568e-3375-4ece-85e5-b35abc46c243"
ssm_parameters = ["secret-*"]
ssm_actions = ["ssm:GetParameters"]
}

Complete Example

This example:

  • Provisions a KMS key to encrypt SSM Parameter Store secrets using terraform-aws-kms-key module
  • Performs Kops cluster lookup to find the ARNs of masters and nodes by using terraform-aws-kops-metadata module
  • Creates a role with the name cp-prod-chamber-kops with permission to read all SSM parameters from the path kops, and gives permission to the Kops masters and nodes to assume the role
module "kms_key" {
source = "git::https://github.com/cloudposse/terraform-aws-kms-key.git?ref=master"
namespace = "cp"
stage = "prod"
name = "chamber"
description = "KMS key for SSM"
}

module "kops_metadata" {
source = "git::https://github.com/cloudposse/terraform-aws-kops-metadata.git?ref=master"
dns_zone = "us-west-2.prod.cloudposse.co"
masters_name = "masters"
nodes_name = "nodes"
}

module "ssm_iam_role" {
source = "git::https://github.com/cloudposse/terraform-aws-ssm-iam-role.git?ref=master"
namespace = "cp"
stage = "prod"
name = "chamber"
attributes = ["kops"]
region = "us-west-2"
account_id = "XXXXXXXXXXX"
assume_role_arns = ["${module.kops_metadata.masters_role_arn}", "${module.kops_metadata.nodes_role_arn}"]
kms_key_arn = "${module.kms_key.key_arn}"
ssm_parameters = ["kops/*"]
ssm_actions = ["ssm:GetParametersByPath", "ssm:GetParameters"]
}

Requirements

No requirements.

Providers

NameVersion
awsn/a

Modules

NameSourceVersion
labelgit::https://github.com/cloudposse/terraform-terraform-label.git0.1.3

Resources

NameType
aws_iam_policy.defaultresource
aws_iam_role.defaultresource
aws_iam_role_policy_attachment.defaultresource
aws_iam_policy_document.assume_roledata source
aws_iam_policy_document.defaultdata source
aws_kms_key.defaultdata source

Inputs

NameDescriptionTypeDefaultRequired
account_idAWS account IDstringn/ayes
assume_role_arnsList of ARNs to allow assuming the role. Could be AWS services or accounts, Kops nodes, IAM users or groupslist(string)n/ayes
attributesAdditional attributes (e.g. 1)list(string)[]no
delimiterDelimiter to be used between namespace, stage, name and attributesstring"-"no
kms_key_referenceThe Key ID, Key ARN, Key Alias Name, or Key Alias ARN of the KMS key which will encrypt/decrypt SSM secret stringsanyn/ayes
max_session_durationThe maximum session duration (in seconds) for the role. Can have a value from 1 hour to 12 hoursnumber3600no
nameName (e.g. app or chamber)stringn/ayes
namespaceNamespace (e.g. cp or cloudposse)stringn/ayes
regionAWS Regionstringn/ayes
ssm_actionsSSM actions to allowlist(string)
[
"ssm:GetParametersByPath",
"ssm:GetParameters"
]
no
ssm_parametersList of SSM parameters to apply the actions. A parameter can include a path and a name pattern that you define by using forward slashes, e.g. kops/secret-*list(string)n/ayes
stageStage (e.g. prod, dev, staging)stringn/ayes
tagsAdditional tags (e.g. map(BusinessUnit,XYZ)map(string){}no

Outputs

NameDescription
role_arnThe Amazon Resource Name (ARN) specifying the role
role_idThe stable and unique string identifying the role
role_nameThe name of the crated role
role_policy_documentA copy of the IAM policy document (JSON) that grants permissions to this role.