This repository has been archived by the owner on Jun 21, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.tf
108 lines (97 loc) · 2.47 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
# Create IAM User for infrastructure management
# Also create a IAM Role so that other people can do things
# =======================
terraform {
required_version = "~> 0.14.0"
required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 3.0"
}
}
# This already exists from s3backend/
backend "s3" {
bucket = "uwhackweek-tfstate"
key = "coiled-iam-user-config.tfstate"
region = "us-west-2"
encrypt = true
}
}
provider "aws" {
region = "us-west-2"
}
data "aws_s3_bucket" "terraform_state_bucket" {
bucket = "uwhackweek-tfstate"
}
output "access_key" {
value = aws_iam_access_key.coiled-actor.id
description = "coiled user access key"
}
output "secret_access_key" {
value = aws_iam_access_key.coiled-actor.secret
description = "coiled user access key"
}
resource "aws_iam_user" "coiled-actor" {
name = "coiled"
}
# Create ACCESS_KEY and SECRET_ACCESS_KEY
resource "aws_iam_access_key" "coiled-actor" {
user = aws_iam_user.coiled-actor.name
}
# More advanced: all required coiled permissions (read from sidecar file)
resource "aws_iam_policy" "coiled-permissions" {
name = "coiled-permissions"
policy = file("coiled-permissions.json")
}
resource "aws_iam_user_policy_attachment" "coiled-permissions" {
user = aws_iam_user.coiled-actor.name
policy_arn = aws_iam_policy.coiled-permissions.arn
}
resource "aws_iam_policy" "coiled-actor" {
name = "coiled-actions-user-policy"
description = "Allow coiled user to assume role"
policy = <<EOF
{
"Version": "2012-10-17",
"Statement": [
{
"Action": [
"sts:AssumeRole",
"sts:TagSession"
],
"Resource": "${aws_iam_role.coiled-role.arn}",
"Effect": "Allow"
}
]
}
EOF
}
resource "aws_iam_user_policy_attachment" "coiled-actor" {
user = aws_iam_user.coiled-actor.name
policy_arn = aws_iam_policy.coiled-actor.arn
}
resource "aws_iam_role" "coiled-role" {
name = "coiled-actions-role"
assume_role_policy = <<EOF
{
"Version": "2012-10-17",
"Statement": [{
"Sid": "AllowIamUserAssumeRole",
"Effect": "Allow",
"Action": "sts:AssumeRole",
"Principal": {
"AWS": "${aws_iam_user.coiled-actor.arn}"
}
},
{
"Sid": "AllowPassSessionTags",
"Effect": "Allow",
"Action": "sts:TagSession",
"Principal": {
"AWS": "${aws_iam_user.coiled-actor.arn}"
}
}
]
}
EOF
}