Skip to content
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
48 changes: 48 additions & 0 deletions terraform/modules/spack_github/mirrors_iam.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
locals {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file doesn't need to be its own module - it's not using any of the variables it takes as input, and isn't reused anywhere. We can just move this entire file to terraform/production/mirrors_iam.tf, and that eliminates all the unncessary module boilerplate.

Essentially, exactly what we do for this file https://github.com/spack/spack-infrastructure/blob/main/terraform/production/iam.tf

github_domain = "token.actions.githubusercontent.com"

mirror_roles = {
"sts.amazonaws.com" = {
"role_name_suffix" = "SpackSourceMirror${var.deployment_name == "prod" ? "" : "-${var.deployment_name}"}-${var.deployment_stage}",
"conditions" = [
"repo:spack/spack-packages:ref:refs/heads/develop",
],
},
}
}

data "aws_caller_identity" "current" {}

data "aws_iam_policy_document" "github_oidc_assume_role" {
for_each = local.mirror_roles

statement {
effect = "Allow"
actions = ["sts:AssumeRoleWithWebIdentity"]

principals {
type = "Federated"
identifiers = ["arn:aws:iam::${data.aws_caller_identity.current.account_id}:oidc-provider/${local.github_domain}"]
}

condition {
test = "StringEquals"
variable = "${local.github_domain}:aud"
values = [each.key]
}

condition {
test = "StringEqual"
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
test = "StringEqual"
test = "StringEquals"

variable = "${local.github_domain}:sub"
values = each.value.conditions
}
}
}

resource "aws_iam_role" "source_mirror_sync" {
for_each = data.aws_iam_policy_document.github_oidc_assume_role

name = "SourceMirrorSync${local.mirror_roles[each.key].role_name_suffix}"
assume_role_policy = each.value.json
max_session_duration = 3600 * 6 # only allow a max of 6 hours for a session to be active
}
11 changes: 11 additions & 0 deletions terraform/modules/spack_github/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
variable "deployment_name" {
type = string
}

variable "deployment_stage" {
type = string
}

variable "region" {
type = string
}
Comment on lines +1 to +11
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file isn't needed (see comment about module)

Suggested change
variable "deployment_name" {
type = string
}
variable "deployment_stage" {
type = string
}
variable "region" {
type = string
}

9 changes: 9 additions & 0 deletions terraform/production/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,12 @@ module "spack_gitlab" {

gitlab_token = var.gitlab_token
}

module "spack_github" {
source = "../modules/spack_github"

deployment_name = "prod"
deployment_stage = "blue"

region = "us-east-1"
}
Comment on lines +29 to +37
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This module block isn't needed if we move the new resources into the production module directly (see comment below)

Suggested change
module "spack_github" {
source = "../modules/spack_github"
deployment_name = "prod"
deployment_stage = "blue"
region = "us-east-1"
}

2 changes: 1 addition & 1 deletion terraform/production/versions.tf
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
terraform {
required_version = "~> 1.11.3"
required_version = "~> 1.11"

required_providers {
aws = {
Expand Down
2 changes: 1 addition & 1 deletion terraform/staging/versions.tf
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
terraform {
required_version = "~> 1.11.3"
required_version = "~> 1.11"

required_providers {
aws = {
Expand Down
Loading