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

First attempt to replace template_file #82

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .bumpversion.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[bumpversion]
current_version = 4.3.3
current_version = 5.0.0
commit = True
message = Bumps version to {new_version}
tag = False
Expand Down
8 changes: 3 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -365,11 +365,9 @@ statement {

At the moment, testing is manual:

```
# Replace "xxx" with an actual AWS profile, then execute the integration tests.
export AWS_PROFILE=xxx
make terraform/pytest PYTEST_ARGS="-v --nomock"
```
Start the mockstack test environment: make mockstack/up
Run the tests: make mockstack/pytest
Shutdown mockstack after testing: make mockstack/clean

## Authors

Expand Down
32 changes: 2 additions & 30 deletions modules/_internal/runner/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -37,30 +37,6 @@ locals {

# IAM resources for CodeBuild

data "template_file" "codebuild_policy_override" {
template = var.policy_override

vars = {
repo_name = var.repo_name
partition = data.aws_partition.current.partition
region = data.aws_region.current.name
account_id = data.aws_caller_identity.current.account_id
}
}

data "template_file" "policy_arns" {
count = length(var.policy_arns)

template = var.policy_arns[count.index]

vars = {
repo_name = var.repo_name
partition = data.aws_partition.current.partition
region = data.aws_region.current.name
account_id = data.aws_caller_identity.current.account_id
}
}

data "aws_iam_policy_document" "codebuild_assume_role" {
statement {
actions = ["sts:AssumeRole"]
Expand All @@ -73,7 +49,7 @@ data "aws_iam_policy_document" "codebuild_assume_role" {
}

data "aws_iam_policy_document" "codebuild" {
override_policy_documents = compact([data.template_file.codebuild_policy_override.rendered])
override_json = var.policy_override

statement {
actions = [
Expand Down Expand Up @@ -109,7 +85,7 @@ resource "aws_iam_role_policy" "codebuild" {
data "aws_iam_policy" "codebuild" {
count = length(var.policy_arns)

arn = data.template_file.policy_arns[count.index].rendered
arn = var.policy_arns[count.index]
}

resource "aws_iam_role_policy_attachment" "codebuild" {
Expand Down Expand Up @@ -172,8 +148,4 @@ resource "aws_codebuild_project" "this" {
location = local.repo_url
buildspec = var.buildspec
}

lifecycle {
ignore_changes = [project_visibility]
}
}
34 changes: 17 additions & 17 deletions tests/branch/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,26 @@ module "test_branch" {
compute_type = "BUILD_GENERAL1_LARGE"
}

policy_override = <<-OVERRIDE
policy_override = jsonencode(
{
"Version": "2012-10-17",
"Statement": [
{
"Action": "codecommit:GitPush",
"Condition": {
"StringLikeIfExists": {
"codecommit:References": [
"refs/tags/*"
]
}
},
"Effect": "Allow",
"Resource": "arn:${data.aws_partition.current.partition}:codecommit:${data.aws_region.current.name}:${data.aws_caller_identity.current.account_id}:${local.repo_name}",
"Sid": ""
"Version" : "2012-10-17",
"Statement" : [
{
"Action" : "codecommit:GitPush",
"Condition" : {
"StringLikeIfExists" : {
"codecommit:References" : [
"refs/tags/*"
]
}
]
},
"Effect" : "Allow",
"Resource" : "arn:${data.aws_partition.current.partition}:codecommit:${data.aws_region.current.name}:${data.aws_caller_identity.current.account_id}:${local.repo_name}",
"Sid" : ""
}
]
}
OVERRIDE
)
}

locals {
Expand Down
34 changes: 17 additions & 17 deletions tests/main/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,26 @@ module "test_branch" {
compute_type = "BUILD_GENERAL1_LARGE"
}

policy_override = <<-OVERRIDE
policy_override = jsonencode(
{
"Version": "2012-10-17",
"Statement": [
{
"Action": "codecommit:GitPush",
"Condition": {
"StringLikeIfExists": {
"codecommit:References": [
"refs/tags/*"
]
}
},
"Effect": "Allow",
"Resource": "arn:${data.aws_partition.current.partition}:codecommit:${data.aws_region.current.name}:${data.aws_caller_identity.current.account_id}:${local.branch_repo_name}",
"Sid": ""
"Version" : "2012-10-17",
"Statement" : [
{
"Action" : "codecommit:GitPush",
"Condition" : {
"StringLikeIfExists" : {
"codecommit:References" : [
"refs/tags/*"
]
}
]
},
"Effect" : "Allow",
"Resource" : "arn:${data.aws_partition.current.partition}:codecommit:${data.aws_region.current.name}:${data.aws_caller_identity.current.account_id}:${local.branch_repo_name}",
"Sid" : ""
}
]
}
OVERRIDE
)
}

module "test_review" {
Expand Down