-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Create dynamodb table * ddb table codacy ignores * ddb table codacy ignores
- Loading branch information
1 parent
516adbc
commit e076878
Showing
9 changed files
with
267 additions
and
181 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,3 +32,4 @@ override.tf.json | |
# Ignore CLI configuration files | ||
.terraformrc | ||
terraform.rc | ||
.validate |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
default: all | ||
|
||
TERRAFORM_ENVIRONMENTS := aws github wildsea | ||
TERRAFOM_VALIDATE := $(addsuffix /.validate,$(addprefix terraform/environment/, $(TERRAFORM_ENVIRONMENTS))) | ||
|
||
all: $(TERRAFOM_VALIDATE) | ||
|
||
terraform/environment/%/.validate: terraform/environment/%/*.tf | ||
cd terraform/environment/$* ; terraform fmt | ||
cd terraform/environment/$* ; terraform validate | ||
touch $@ |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
data "aws_iam_policy_document" "ro" { | ||
statement { | ||
sid = "ReadState" | ||
actions = [ | ||
"s3:GetObject" | ||
] | ||
resources = [ | ||
"${aws_s3_bucket.state.arn}/${var.environment}/terraform.tfstate" | ||
] | ||
} | ||
|
||
statement { | ||
sid = "ListState" | ||
actions = [ | ||
"s3:ListBucket" | ||
] | ||
resources = [ | ||
aws_s3_bucket.state.arn | ||
] | ||
} | ||
|
||
statement { | ||
sid = "Dynamodb" | ||
actions = [ | ||
"dynamodb:DescribeTable*" | ||
] | ||
resources = [ | ||
"arn:${data.aws_partition.current.id}:dynamodb:${data.aws_region.current.id}:${data.aws_caller_identity.current.account_id}:table/${var.app_name}-${var.environment}" | ||
] | ||
} | ||
} | ||
|
||
data "aws_iam_policy_document" "rw" { | ||
statement { | ||
sid = "WriteState" | ||
actions = [ | ||
"s3:PutObject" | ||
] | ||
resources = [ | ||
"${aws_s3_bucket.state.arn}/${var.environment}/terraform.tfstate" | ||
] | ||
} | ||
|
||
statement { | ||
sid = "Dynamodb" | ||
actions = [ | ||
"dynamodb:CreateTable", | ||
"dynamodb:DeleteTable", | ||
] | ||
resources = [ | ||
"arn:${data.aws_partition.current.id}:dynamodb:${data.aws_region.current.id}:${data.aws_caller_identity.current.account_id}:table/${var.app_name}-${var.environment}" | ||
] | ||
} | ||
} | ||
|
||
data "aws_iam_policy_document" "rw_boundary" { | ||
statement { | ||
sid = "s3" | ||
actions = [ | ||
"s3:GetObject", | ||
"s3:PutObject" | ||
] | ||
resources = [ | ||
"${aws_s3_bucket.state.arn}/${var.environment}/terraform.tfstate", | ||
"arn:${data.aws_partition.current.id}:s3:::${var.app_name}-${var.environment}-*/*" | ||
] | ||
} | ||
|
||
statement { | ||
sid = "ListState" | ||
actions = [ | ||
"s3:ListBucket" | ||
] | ||
resources = [ | ||
"arn:${data.aws_partition.current.id}:s3:::${var.app_name}-${var.environment}-*/*" | ||
] | ||
} | ||
|
||
statement { | ||
sid = "Dynamodb" | ||
actions = [ | ||
"dynamodb:DescribeTable", | ||
"dynamodb:CreateTable", | ||
"dynamodb:DeleteTable", | ||
"dynamodb:BatchGet*", | ||
"dynamodb:GetItem", | ||
"dynamodb:Query", | ||
"dynamodb:DeleteItem", | ||
"dynamodb:UpdateItem*", | ||
"dynamodb:PutItem*", | ||
] | ||
resources = [ | ||
"arn:${data.aws_partition.current.id}:dynamodb:${data.aws_region.current.id}:${data.aws_caller_identity.current.account_id}:table/${var.app_name}-${var.environment}" | ||
] | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,168 +1,110 @@ | ||
resource "aws_iam_openid_connect_provider" "oidc" { | ||
url = "https://token.actions.githubusercontent.com" | ||
client_id_list = [ | ||
"sts.${data.aws_partition.current.dns_suffix}" | ||
] | ||
thumbprint_list = [ | ||
"d89e3bd43d5d909b47a18977aa9d5ce36cee184c" | ||
] | ||
url = "https://token.actions.githubusercontent.com" | ||
client_id_list = [ | ||
"sts.${data.aws_partition.current.dns_suffix}" | ||
] | ||
thumbprint_list = [ | ||
"d89e3bd43d5d909b47a18977aa9d5ce36cee184c" | ||
] | ||
} | ||
|
||
resource "aws_iam_role" "ro" { | ||
name = "${var.action_prefix}-${var.app_name}-ro-${var.environment}" | ||
assume_role_policy = data.aws_iam_policy_document.ro_assume.json | ||
name = "${var.action_prefix}-${var.app_name}-ro-${var.environment}" | ||
assume_role_policy = data.aws_iam_policy_document.ro_assume.json | ||
|
||
tags = { | ||
Name = "${var.action_prefix}-${var.app_name}-ro-${var.environment}" | ||
} | ||
tags = { | ||
Name = "${var.action_prefix}-${var.app_name}-ro-${var.environment}" | ||
} | ||
} | ||
|
||
data "aws_iam_policy_document" "ro_assume" { | ||
statement { | ||
actions = ["sts:AssumeRoleWithWebIdentity"] | ||
principals { | ||
type = "Federated" | ||
identifiers = [ aws_iam_openid_connect_provider.oidc.arn ] | ||
} | ||
condition { | ||
test = "StringEquals" | ||
variable = "token.actions.githubusercontent.com:aud" | ||
values = ["sts.${data.aws_partition.current.dns_suffix}"] | ||
} | ||
condition { | ||
test = "StringEquals" | ||
variable = "token.actions.githubusercontent.com:sub" | ||
values = ["repo:${var.workspace}/${var.repo}:environment:${var.environment}-ro"] | ||
} | ||
statement { | ||
actions = ["sts:AssumeRoleWithWebIdentity"] | ||
principals { | ||
type = "Federated" | ||
identifiers = [aws_iam_openid_connect_provider.oidc.arn] | ||
} | ||
condition { | ||
test = "StringEquals" | ||
variable = "token.actions.githubusercontent.com:aud" | ||
values = ["sts.${data.aws_partition.current.dns_suffix}"] | ||
} | ||
condition { | ||
test = "StringEquals" | ||
variable = "token.actions.githubusercontent.com:sub" | ||
values = ["repo:${var.workspace}/${var.repo}:environment:${var.environment}-ro"] | ||
} | ||
} | ||
} | ||
|
||
resource "aws_iam_policy" "ro" { | ||
name = aws_iam_role.ro.name | ||
policy = data.aws_iam_policy_document.ro.json | ||
name = aws_iam_role.ro.name | ||
policy = data.aws_iam_policy_document.ro.json | ||
|
||
tags = { | ||
Name = aws_iam_role.ro.name | ||
} | ||
tags = { | ||
Name = aws_iam_role.ro.name | ||
} | ||
} | ||
|
||
resource "aws_iam_role_policy_attachment" "ro-ro" { | ||
role = aws_iam_role.ro.name | ||
policy_arn = aws_iam_policy.ro.arn | ||
} | ||
|
||
data "aws_iam_policy_document" "ro" { | ||
statement { | ||
sid = "ReadState" | ||
actions = [ | ||
"s3:GetObject" | ||
] | ||
resources = [ | ||
"${aws_s3_bucket.state.arn}/${var.environment}/terraform.tfstate" | ||
] | ||
} | ||
|
||
statement { | ||
sid = "ListState" | ||
actions = [ | ||
"s3:ListBucket" | ||
] | ||
resources = [ | ||
aws_s3_bucket.state.arn | ||
] | ||
} | ||
role = aws_iam_role.ro.name | ||
policy_arn = aws_iam_policy.ro.arn | ||
} | ||
|
||
resource "aws_iam_role" "rw" { | ||
name = "${var.action_prefix}-${var.app_name}-rw-${var.environment}" | ||
assume_role_policy = data.aws_iam_policy_document.rw_assume.json | ||
permissions_boundary = aws_iam_policy.rw_boundary.arn | ||
name = "${var.action_prefix}-${var.app_name}-rw-${var.environment}" | ||
assume_role_policy = data.aws_iam_policy_document.rw_assume.json | ||
permissions_boundary = aws_iam_policy.rw_boundary.arn | ||
|
||
tags = { | ||
Name = "${var.action_prefix}-${var.app_name}-rw-${var.environment}" | ||
} | ||
tags = { | ||
Name = "${var.action_prefix}-${var.app_name}-rw-${var.environment}" | ||
} | ||
} | ||
|
||
data "aws_iam_policy_document" "rw_assume" { | ||
statement { | ||
actions = ["sts:AssumeRoleWithWebIdentity"] | ||
principals { | ||
type = "Federated" | ||
identifiers = [ aws_iam_openid_connect_provider.oidc.arn ] | ||
} | ||
condition { | ||
test = "StringEquals" | ||
variable = "token.actions.githubusercontent.com:aud" | ||
values = ["sts.${data.aws_partition.current.dns_suffix}"] | ||
} | ||
condition { | ||
test = "StringEquals" | ||
variable = "token.actions.githubusercontent.com:sub" | ||
values = ["repo:${var.workspace}/${var.repo}:environment:${var.environment}-rw"] | ||
} | ||
statement { | ||
actions = ["sts:AssumeRoleWithWebIdentity"] | ||
principals { | ||
type = "Federated" | ||
identifiers = [aws_iam_openid_connect_provider.oidc.arn] | ||
} | ||
condition { | ||
test = "StringEquals" | ||
variable = "token.actions.githubusercontent.com:aud" | ||
values = ["sts.${data.aws_partition.current.dns_suffix}"] | ||
} | ||
condition { | ||
test = "StringEquals" | ||
variable = "token.actions.githubusercontent.com:sub" | ||
values = ["repo:${var.workspace}/${var.repo}:environment:${var.environment}-rw"] | ||
} | ||
} | ||
} | ||
|
||
resource "aws_iam_policy" "rw" { | ||
name = aws_iam_role.rw.name | ||
policy = data.aws_iam_policy_document.rw.json | ||
name = aws_iam_role.rw.name | ||
policy = data.aws_iam_policy_document.rw.json | ||
|
||
tags = { | ||
Name = aws_iam_role.rw.name | ||
} | ||
tags = { | ||
Name = aws_iam_role.rw.name | ||
} | ||
} | ||
|
||
resource "aws_iam_role_policy_attachment" "rw-ro" { | ||
role = aws_iam_role.rw.name | ||
policy_arn = aws_iam_policy.ro.arn | ||
role = aws_iam_role.rw.name | ||
policy_arn = aws_iam_policy.ro.arn | ||
} | ||
|
||
resource "aws_iam_role_policy_attachment" "rw-rw" { | ||
role = aws_iam_role.rw.name | ||
policy_arn = aws_iam_policy.rw.arn | ||
} | ||
|
||
data "aws_iam_policy_document" "rw" { | ||
statement { | ||
sid = "WriteState" | ||
actions = [ | ||
"s3:PutObject" | ||
] | ||
resources = [ | ||
"${aws_s3_bucket.state.arn}/${var.environment}/terraform.tfstate" | ||
] | ||
} | ||
role = aws_iam_role.rw.name | ||
policy_arn = aws_iam_policy.rw.arn | ||
} | ||
|
||
resource "aws_iam_policy" "rw_boundary" { | ||
name = "${var.action_prefix}-${var.app_name}-rw-${var.environment}-boundary" | ||
policy = data.aws_iam_policy_document.rw_boundary.json | ||
name = "${var.action_prefix}-${var.app_name}-rw-${var.environment}-boundary" | ||
policy = data.aws_iam_policy_document.rw_boundary.json | ||
|
||
tags = { | ||
Name = "${var.action_prefix}-${var.app_name}-rw-${var.environment}-boundary" | ||
} | ||
} | ||
|
||
data "aws_iam_policy_document" "rw_boundary" { | ||
statement { | ||
sid = "s3" | ||
actions = [ | ||
"s3:GetObject", | ||
"s3:PutObject" | ||
] | ||
resources = [ | ||
"${aws_s3_bucket.state.arn}/${var.environment}/terraform.tfstate", | ||
"arn:${data.aws_partition.current.id}:s3:::${var.app_name}-${var.environment}-*/*" | ||
] | ||
} | ||
|
||
statement { | ||
sid = "ListState" | ||
actions = [ | ||
"s3:ListBucket" | ||
] | ||
resources = [ | ||
aws_s3_bucket.state.arn | ||
] | ||
} | ||
tags = { | ||
Name = "${var.action_prefix}-${var.app_name}-rw-${var.environment}-boundary" | ||
} | ||
} |
Oops, something went wrong.