-
Notifications
You must be signed in to change notification settings - Fork 1
/
provisioner_iam.tf
132 lines (122 loc) · 2.99 KB
/
provisioner_iam.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
resource "aws_kms_key" "parameter_store" {
description = "Parameter store kms master key"
deletion_window_in_days = 10
enable_key_rotation = true
}
resource "aws_iam_instance_profile" "provisioner" {
role = "${aws_iam_role.provisioner.name}"
}
resource "aws_kms_alias" "parameter_store_alias" {
name = "alias/parameter_store_key"
target_key_id = "${aws_kms_key.parameter_store.id}"
}
resource "aws_iam_role" "provisioner" {
path = "/"
assume_role_policy = <<EOF
{
"Version": "2012-10-17",
"Statement": [
{
"Action": "sts:AssumeRole",
"Principal":{
"Service": [
"ec2.amazonaws.com",
"ssm.amazonaws.com"
]
},
"Effect": "Allow",
"Sid": ""
}
]
}
EOF
}
resource "aws_iam_role_policy" "provisioner" {
role = "${aws_iam_role.provisioner.id}"
policy = <<EOF
{
"Version": "2012-10-17",
"Statement": [
{
"Action": [
"ec2:Describe*",
"route53:ListHostedZones",
"route53:ListResourceRecordSets",
"rds:Describe*",
"elasticache:Describe*"
],
"Effect": "Allow",
"Resource": "*"
},
{
"Effect": "Allow",
"Action": [
"ssm:DescribeParameters",
"ssm:PutParameter",
"ssm:GetParameters",
"ssm:DeleteParameter",
"ssm:SendCommand"
],
"Resource": [
"*"
]
},
{
"Sid": "",
"Effect": "Allow",
"Action": [
"sqs:*"
],
"Resource": [
"${aws_sqs_queue.scaling.arn}"
]
},
{
"Sid": "",
"Effect": "Allow",
"Action": [
"kms:ListKeys",
"kms:ListAliases",
"kms:Describe*",
"kms:Encrypt",
"kms:Decrypt"
],
"Resource": "arn:aws:kms:*:*:key/${aws_kms_key.parameter_store.id}"
},
{
"Effect": "Allow",
"Action": [
"logs:CreateLogGroup",
"logs:CreateLogStream",
"logs:PutLogEvents",
"logs:DescribeLogStreams"
],
"Resource": [
"arn:aws:logs:*:*:*"
]
}
]
}
EOF
}
resource "aws_iam_policy_attachment" "ssm" {
name = "${var.environment}_provisioner"
roles = ["${aws_iam_role.provisioner.name}"]
policy_arn = "arn:aws:iam::aws:policy/service-role/AmazonEC2RoleforSSM"
}
resource "tls_private_key" "provisioner" {
algorithm = "RSA"
}
resource "aws_ssm_parameter" "provisioner" {
name = "${var.environment}.provisioner_id_rsa_pub"
type = "String"
value = "${tls_private_key.provisioner.public_key_openssh}"
overwrite = "true"
}
resource "aws_ssm_parameter" "provisione_private" {
name = "${var.environment}.provisioner_id_rsa"
type = "SecureString"
value = "${tls_private_key.provisioner.private_key_pem}"
overwrite = "true"
key_id = "${aws_kms_key.parameter_store.key_id}"
}