Skip to content

Commit

Permalink
chore(ci-stagin): add iam role (#638)
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcoIeni authored Dec 4, 2024
1 parent 18823eb commit cdbf5b2
Show file tree
Hide file tree
Showing 5 changed files with 91 additions and 0 deletions.
25 changes: 25 additions & 0 deletions terragrunt/accounts/ci-staging/ci-runners/.terraform.lock.hcl

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions terragrunt/accounts/ci-staging/ci-runners/terragrunt.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
terraform {
source = "../../../..//terragrunt/modules/ci-runners"
}

include {
path = find_in_parent_folders()
merge_strategy = "deep"
}

inputs = {
code_connection_arn = "arn:aws:codeconnections:us-east-2:442426873467:connection/98864d5c-b905-4f8e-bd76-2f69cf181818"
}
40 changes: 40 additions & 0 deletions terragrunt/modules/ci-runners/iam.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// Grant CodeBuild project IAM role access to use the connection, as documented in
// https://docs.aws.amazon.com/codebuild/latest/userguide/connections-github-app.html#connections-github-role-access
resource "aws_iam_role" "codebuild_role" {
name = "codebuild-github-runner-role"

assume_role_policy = jsonencode({
Version = "2012-10-17"
Statement = [
{
Effect = "Allow"
Principal = {
Service = "codebuild.amazonaws.com"
}
Action = "sts:AssumeRole"
}
]
})
}

# Add inline or managed policy for the permissions
resource "aws_iam_role_policy" "codebuild_policy" {
name = "codebuild-github-runner-policy"
role = aws_iam_role.codebuild_role.id

policy = jsonencode({
Version = "2012-10-17"
Statement = [
{
Effect = "Allow"
Action = [
"codeconnections:GetConnectionToken",
"codeconnections:GetConnection"
]
Resource = [
var.code_connection_arn
]
}
]
})
}
8 changes: 8 additions & 0 deletions terragrunt/modules/ci-runners/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 5.64"
}
}
}
6 changes: 6 additions & 0 deletions terragrunt/modules/ci-runners/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// Since you can't create the connection from the terraform provider (as of Dec 2024),
// you need to create the connection manually at
// https://us-east-2.console.aws.amazon.com/codesuite/settings/connections
variable "code_connection_arn" {
description = "Arn of the GitHub CodeConnection"
}

0 comments on commit cdbf5b2

Please sign in to comment.