Skip to content
Merged
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
6 changes: 0 additions & 6 deletions infra/aws/terraform/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,6 @@ plan.out
# Crash log files
crash.log

# Exclude all .tfvars files, which are likely to contain sentitive data, such as
# password, private keys, and other secrets. These should not be part of version
# control as they are data points which are potentially sensitive and subject
# to change depending on the environment.
*.tfvars

# Ignore override files as they are usually used to override resources locally and so
# are not checked in
override.tf
Expand Down
3 changes: 3 additions & 0 deletions infra/aws/terraform/artifacts.k8s.io/atlantis.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
assume_role = {
role_arn = "arn:aws:iam::354561287328:role/OrganizationAccountAccessRole"
}
1 change: 1 addition & 0 deletions infra/aws/terraform/artifacts.k8s.io/atlantis.tfvars
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
atlantis_role_arn = "arn:aws:iam::354561287328:role/OrganizationAccountAccessRole"
56 changes: 55 additions & 1 deletion infra/aws/terraform/artifacts.k8s.io/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 4.0"
version = "~> 5.0"
}
}

Expand All @@ -34,90 +34,144 @@ terraform {
# Provider for AWS non-region-specific operations
provider "aws" {
region = "us-east-2"
assume_role {
role_arn = var.atlantis_role_arn
Copy link
Member

Choose a reason for hiding this comment

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

Why not use a data resource for this ?
We could avoid use a tf.vars with a disclosed account ID.

Copy link
Member Author

Choose a reason for hiding this comment

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

It has to be specified before the API calls are made. Also, account ids are everywhere in this repo and in test-infra

}
}

# Per-region providers
provider "aws" {
alias = "ap-northeast-1"
region = "ap-northeast-1"
assume_role {
role_arn = var.atlantis_role_arn
}
}

provider "aws" {
alias = "ap-northeast-2"
region = "ap-northeast-2"
assume_role {
role_arn = var.atlantis_role_arn
}
}

provider "aws" {
alias = "ap-northeast-3"
region = "ap-northeast-3"
assume_role {
role_arn = var.atlantis_role_arn
}
}

provider "aws" {
alias = "ap-south-1"
region = "ap-south-1"
assume_role {
role_arn = var.atlantis_role_arn
}
}

provider "aws" {
alias = "ap-southeast-1"
region = "ap-southeast-1"
assume_role {
role_arn = var.atlantis_role_arn
}
}

provider "aws" {
alias = "ap-southeast-2"
region = "ap-southeast-2"
assume_role {
role_arn = var.atlantis_role_arn
}
}

provider "aws" {
alias = "ca-central-1"
region = "ca-central-1"
assume_role {
role_arn = var.atlantis_role_arn
}
}

provider "aws" {
alias = "eu-central-1"
region = "eu-central-1"
assume_role {
role_arn = var.atlantis_role_arn
}
}

provider "aws" {
alias = "eu-north-1"
region = "eu-north-1"
assume_role {
role_arn = var.atlantis_role_arn
}
}

provider "aws" {
alias = "eu-west-1"
region = "eu-west-1"
assume_role {
role_arn = var.atlantis_role_arn
}
}

provider "aws" {
alias = "eu-west-2"
region = "eu-west-2"
assume_role {
role_arn = var.atlantis_role_arn
}
}

provider "aws" {
alias = "eu-west-3"
region = "eu-west-3"
assume_role {
role_arn = var.atlantis_role_arn
}
}

provider "aws" {
alias = "sa-east-1"
region = "sa-east-1"
assume_role {
role_arn = var.atlantis_role_arn
}
}

provider "aws" {
alias = "us-east-1"
region = "us-east-1"
assume_role {
role_arn = var.atlantis_role_arn
}
}

provider "aws" {
alias = "us-east-2"
region = "us-east-2"
assume_role {
role_arn = var.atlantis_role_arn
}
}

provider "aws" {
alias = "us-west-1"
region = "us-west-1"
assume_role {
role_arn = var.atlantis_role_arn
}
}

provider "aws" {
alias = "us-west-2"
region = "us-west-2"
assume_role {
role_arn = var.atlantis_role_arn
}
}
3 changes: 1 addition & 2 deletions infra/aws/terraform/artifacts.k8s.io/s3/versions.tf
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ terraform {

required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 4.0"
source = "hashicorp/aws"
}
}
}
7 changes: 6 additions & 1 deletion infra/aws/terraform/artifacts.k8s.io/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,15 @@ limitations under the License.
variable "prefix" {
description = "Prefix for every resource so that the resources can be created without using the same names. Useful for testing and staging"
type = string
default = "test-"
default = "prod-"

validation {
condition = can(regex(".*-$|^$", var.prefix))
error_message = "The string must end with a hyphen or be empty."
}
}

variable "atlantis_role_arn" {
description = "The ARN of the Atlantis IAM role"
default = null
}
28 changes: 0 additions & 28 deletions infra/aws/terraform/management-account/iam-bentheelder.tf

This file was deleted.

20 changes: 0 additions & 20 deletions infra/aws/terraform/management-account/iam-roles.tf

This file was deleted.

62 changes: 62 additions & 0 deletions infra/aws/terraform/management-account/iam.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
Copyright 2023 The Kubernetes Authors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

// Service Linked Roles
resource "aws_iam_service_linked_role" "access_analyzer" {
aws_service_name = "access-analyzer.amazonaws.com"
}


// Atlantis

resource "aws_iam_openid_connect_provider" "utility_cluster" {
url = "https://container.googleapis.com/v1/projects/k8s-infra-prow/locations/us-central1/clusters/utility"
client_id_list = ["sts.amazonaws.com"]
thumbprint_list = ["08745487e891c19e3078c1f2a07e452950ef36f6"]
}

resource "aws_iam_role" "atlantis" {
name = "atlantis"
assume_role_policy = jsonencode({
Version = "2012-10-17"
Statement = [
{
"Effect" : "Allow",
"Principal" : {
"Federated" : aws_iam_openid_connect_provider.utility_cluster.arn
},
"Action" : "sts:AssumeRoleWithWebIdentity",
"Condition" : {
"StringEquals" : {
"container.googleapis.com/v1/projects/k8s-infra-prow/locations/us-central1/clusters/utility:sub" : "system:serviceaccount:atlantis:atlantis"
}
}
}
]
})

max_session_duration = 43200

tags = {
service = "atlantis"
}
}


resource "aws_iam_role_policy_attachment" "atlantis" {
role = aws_iam_role.atlantis.name
policy_arn = "arn:aws:iam::aws:policy/AdministratorAccess"
}
2 changes: 1 addition & 1 deletion infra/aws/terraform/management-account/provider.tf
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 5.93.0"
version = "~> 6.17.0"
}
}
}