Skip to content

Commit 18acf6b

Browse files
authored
configure artifacts.k8s.io to use atlantis + atlantis IAM changes in management account (#8686)
1 parent 2772722 commit 18acf6b

File tree

10 files changed

+129
-59
lines changed

10 files changed

+129
-59
lines changed

infra/aws/terraform/.gitignore

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,6 @@ plan.out
1313
# Crash log files
1414
crash.log
1515

16-
# Exclude all .tfvars files, which are likely to contain sentitive data, such as
17-
# password, private keys, and other secrets. These should not be part of version
18-
# control as they are data points which are potentially sensitive and subject
19-
# to change depending on the environment.
20-
*.tfvars
21-
2216
# Ignore override files as they are usually used to override resources locally and so
2317
# are not checked in
2418
override.tf
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
assume_role = {
2+
role_arn = "arn:aws:iam::354561287328:role/OrganizationAccountAccessRole"
3+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
atlantis_role_arn = "arn:aws:iam::354561287328:role/OrganizationAccountAccessRole"

infra/aws/terraform/artifacts.k8s.io/main.tf

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ terraform {
2020
required_providers {
2121
aws = {
2222
source = "hashicorp/aws"
23-
version = "~> 4.0"
23+
version = "~> 5.0"
2424
}
2525
}
2626

@@ -34,90 +34,144 @@ terraform {
3434
# Provider for AWS non-region-specific operations
3535
provider "aws" {
3636
region = "us-east-2"
37+
assume_role {
38+
role_arn = var.atlantis_role_arn
39+
}
3740
}
3841

3942
# Per-region providers
4043
provider "aws" {
4144
alias = "ap-northeast-1"
4245
region = "ap-northeast-1"
46+
assume_role {
47+
role_arn = var.atlantis_role_arn
48+
}
4349
}
4450

4551
provider "aws" {
4652
alias = "ap-northeast-2"
4753
region = "ap-northeast-2"
54+
assume_role {
55+
role_arn = var.atlantis_role_arn
56+
}
4857
}
4958

5059
provider "aws" {
5160
alias = "ap-northeast-3"
5261
region = "ap-northeast-3"
62+
assume_role {
63+
role_arn = var.atlantis_role_arn
64+
}
5365
}
5466

5567
provider "aws" {
5668
alias = "ap-south-1"
5769
region = "ap-south-1"
70+
assume_role {
71+
role_arn = var.atlantis_role_arn
72+
}
5873
}
5974

6075
provider "aws" {
6176
alias = "ap-southeast-1"
6277
region = "ap-southeast-1"
78+
assume_role {
79+
role_arn = var.atlantis_role_arn
80+
}
6381
}
6482

6583
provider "aws" {
6684
alias = "ap-southeast-2"
6785
region = "ap-southeast-2"
86+
assume_role {
87+
role_arn = var.atlantis_role_arn
88+
}
6889
}
6990

7091
provider "aws" {
7192
alias = "ca-central-1"
7293
region = "ca-central-1"
94+
assume_role {
95+
role_arn = var.atlantis_role_arn
96+
}
7397
}
7498

7599
provider "aws" {
76100
alias = "eu-central-1"
77101
region = "eu-central-1"
102+
assume_role {
103+
role_arn = var.atlantis_role_arn
104+
}
78105
}
79106

80107
provider "aws" {
81108
alias = "eu-north-1"
82109
region = "eu-north-1"
110+
assume_role {
111+
role_arn = var.atlantis_role_arn
112+
}
83113
}
84114

85115
provider "aws" {
86116
alias = "eu-west-1"
87117
region = "eu-west-1"
118+
assume_role {
119+
role_arn = var.atlantis_role_arn
120+
}
88121
}
89122

90123
provider "aws" {
91124
alias = "eu-west-2"
92125
region = "eu-west-2"
126+
assume_role {
127+
role_arn = var.atlantis_role_arn
128+
}
93129
}
94130

95131
provider "aws" {
96132
alias = "eu-west-3"
97133
region = "eu-west-3"
134+
assume_role {
135+
role_arn = var.atlantis_role_arn
136+
}
98137
}
99138

100139
provider "aws" {
101140
alias = "sa-east-1"
102141
region = "sa-east-1"
142+
assume_role {
143+
role_arn = var.atlantis_role_arn
144+
}
103145
}
104146

105147
provider "aws" {
106148
alias = "us-east-1"
107149
region = "us-east-1"
150+
assume_role {
151+
role_arn = var.atlantis_role_arn
152+
}
108153
}
109154

110155
provider "aws" {
111156
alias = "us-east-2"
112157
region = "us-east-2"
158+
assume_role {
159+
role_arn = var.atlantis_role_arn
160+
}
113161
}
114162

115163
provider "aws" {
116164
alias = "us-west-1"
117165
region = "us-west-1"
166+
assume_role {
167+
role_arn = var.atlantis_role_arn
168+
}
118169
}
119170

120171
provider "aws" {
121172
alias = "us-west-2"
122173
region = "us-west-2"
174+
assume_role {
175+
role_arn = var.atlantis_role_arn
176+
}
123177
}

infra/aws/terraform/artifacts.k8s.io/s3/versions.tf

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@ terraform {
1919

2020
required_providers {
2121
aws = {
22-
source = "hashicorp/aws"
23-
version = "~> 4.0"
22+
source = "hashicorp/aws"
2423
}
2524
}
2625
}

infra/aws/terraform/artifacts.k8s.io/variables.tf

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,15 @@ limitations under the License.
1717
variable "prefix" {
1818
description = "Prefix for every resource so that the resources can be created without using the same names. Useful for testing and staging"
1919
type = string
20-
default = "test-"
20+
default = "prod-"
2121

2222
validation {
2323
condition = can(regex(".*-$|^$", var.prefix))
2424
error_message = "The string must end with a hyphen or be empty."
2525
}
2626
}
27+
28+
variable "atlantis_role_arn" {
29+
description = "The ARN of the Atlantis IAM role"
30+
default = null
31+
}

infra/aws/terraform/management-account/iam-bentheelder.tf

Lines changed: 0 additions & 28 deletions
This file was deleted.

infra/aws/terraform/management-account/iam-roles.tf

Lines changed: 0 additions & 20 deletions
This file was deleted.
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/*
2+
Copyright 2023 The Kubernetes Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
// Service Linked Roles
18+
resource "aws_iam_service_linked_role" "access_analyzer" {
19+
aws_service_name = "access-analyzer.amazonaws.com"
20+
}
21+
22+
23+
// Atlantis
24+
25+
resource "aws_iam_openid_connect_provider" "utility_cluster" {
26+
url = "https://container.googleapis.com/v1/projects/k8s-infra-prow/locations/us-central1/clusters/utility"
27+
client_id_list = ["sts.amazonaws.com"]
28+
thumbprint_list = ["08745487e891c19e3078c1f2a07e452950ef36f6"]
29+
}
30+
31+
resource "aws_iam_role" "atlantis" {
32+
name = "atlantis"
33+
assume_role_policy = jsonencode({
34+
Version = "2012-10-17"
35+
Statement = [
36+
{
37+
"Effect" : "Allow",
38+
"Principal" : {
39+
"Federated" : aws_iam_openid_connect_provider.utility_cluster.arn
40+
},
41+
"Action" : "sts:AssumeRoleWithWebIdentity",
42+
"Condition" : {
43+
"StringEquals" : {
44+
"container.googleapis.com/v1/projects/k8s-infra-prow/locations/us-central1/clusters/utility:sub" : "system:serviceaccount:atlantis:atlantis"
45+
}
46+
}
47+
}
48+
]
49+
})
50+
51+
max_session_duration = 43200
52+
53+
tags = {
54+
service = "atlantis"
55+
}
56+
}
57+
58+
59+
resource "aws_iam_role_policy_attachment" "atlantis" {
60+
role = aws_iam_role.atlantis.name
61+
policy_arn = "arn:aws:iam::aws:policy/AdministratorAccess"
62+
}

infra/aws/terraform/management-account/provider.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ terraform {
3030
required_providers {
3131
aws = {
3232
source = "hashicorp/aws"
33-
version = "~> 5.93.0"
33+
version = "~> 6.17.0"
3434
}
3535
}
3636
}

0 commit comments

Comments
 (0)