Created
December 20, 2019 21:04
-
-
Save bdashrad/ced2e234927a2fd80c1880e13dde070b to your computer and use it in GitHub Desktop.
k8s assume role
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
variable "environment" { | |
type = string | |
description = "A name identifying a type of resource i.e., qa, staging, release" | |
} | |
variable "name" { | |
type = string | |
description = "Name of service" | |
} | |
variable "worker_role" { | |
type = string | |
description = "The IAM role arn for the EKS worker nodes" | |
} | |
locals { | |
target_roles = compact([var.worker_role]) | |
} | |
# current account | |
data "aws_caller_identity" "current" { | |
} | |
# IAM role, profile, and policy associated with the service | |
data "aws_iam_policy_document" "ec2" { | |
statement { | |
actions = ["sts:AssumeRole"] | |
principals { | |
type = "Service" | |
identifiers = ["ec2.amazonaws.com"] | |
} | |
effect = "Allow" | |
} | |
statement { | |
effect = "Allow" | |
actions = [ | |
"sts:AssumeRole", | |
] | |
principals { | |
type = "AWS" | |
identifiers = local.target_roles | |
} | |
} | |
} | |
resource "aws_iam_role" "app" { | |
name = "${var.environment}-${var.name}" | |
assume_role_policy = data.aws_iam_policy_document.ec2.json | |
} | |
output "arn" { | |
value = aws_iam_role.app.arn | |
} | |
output "id" { | |
value = aws_iam_role.app.id | |
} | |
output "unique_id" { | |
value = aws_iam_role.app.unique_id | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment