forked from openshift/aws-vpce-operator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.tf
132 lines (115 loc) · 3.25 KB
/
main.tf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
provider "aws" {
region = "us-east-2"
profile = "osd-staging-2"
assume_role {
role_arn = "arn:aws:iam::${var.aws_account_id}:role/OrganizationAccountAccessRole"
}
default_tags {
tags = {
owner = "terraform"
}
}
}
variable "aws_account_id" {
type = string
description = "AWS Account ID to deploy this into"
}
variable "rosa_internal_id" {
type = string
description = "Internal ID of the ROSA cluster"
}
locals {
osd_staging_2_account_id = "811685182089"
oidc_provider = "rh-oidc-staging.s3.us-east-1.amazonaws.com/${var.rosa_internal_id}"
namespace = "awscli-sts-debug"
service_account_name = "rosa-to-iam"
}
resource "aws_iam_role" "iam_test" {
name = "iam-test-aws"
assume_role_policy = data.aws_iam_policy_document.trust_policy.json
}
data "aws_iam_policy_document" "trust_policy" {
version = "2012-10-17"
statement {
sid = "LocalDev"
effect = "Allow"
actions = ["sts:AssumeRole"]
principals {
type = "AWS"
identifiers = ["arn:aws:iam::${local.osd_staging_2_account_id}:root"]
}
}
statement {
sid = "OpenshiftStsOidcTrustPolicy"
effect = "Allow"
actions = ["sts:AssumeRoleWithWebIdentity"]
principals {
type = "Federated"
identifiers = ["arn:aws:iam::${var.aws_account_id}:oidc-provider/${local.oidc_provider}"]
}
condition {
test = "StringEquals"
variable = "${local.oidc_provider}:sub"
values = ["system:serviceaccount:${local.namespace}:${local.service_account_name}"]
}
condition {
test = "StringEquals"
variable = "${local.oidc_provider}:aud"
values = ["openshift"]
}
}
}
data "aws_iam_policy_document" "iam_test" {
version = "2012-10-17"
statement {
sid = "HelloWorld"
effect = "Allow"
actions = ["sts:GetCallerIdentity"]
resources = ["*"]
}
statement {
sid = "ManageTags"
effect = "Allow"
actions = [
# Manage tags and filter based on tags
"ec2:CreateTags",
"ec2:DeleteTags",
"ec2:DescribeTags"
]
resources = ["*"]
}
statement {
sid = "ManageVPCE"
effect = "Allow"
actions = [
# Extract vpc-id by searching for subnets by tag-key
"ec2:DescribeSubnets",
# Create and manage security group in specific VPC
"ec2:CreateSecurityGroup",
"ec2:DeleteSecurityGroup",
"ec2:DescribeSecurityGroups",
# Create and manage security group rules
"ec2:AuthorizeSecurityGroupIngress",
"ec2:AuthorizeSecurityGroupEgress",
"ec2:DescribeSecurityGroupRules",
# Create and manage a VPC endpoint
"ec2:CreateVpcEndpoint",
"ec2:DeleteVpcEndpoints",
"ec2:DescribeVpcEndpoints",
"ec2:ModifyVpcEndpoint",
# Create and manage a Route53 Record
"route53:ChangeResourceRecordSets",
"route53:ListHostedZonesByName",
"route53:ListResourceRecordSets"
]
resources = ["*"]
}
}
resource "aws_iam_policy" "iam_test" {
name = "iam-test-aws"
policy = data.aws_iam_policy_document.iam_test.json
}
resource "aws_iam_role_policy_attachment" "iam_test" {
role = aws_iam_role.iam_test.name
policy_arn = aws_iam_policy.iam_test.arn
}