-
Notifications
You must be signed in to change notification settings - Fork 13
/
terraform.tf
110 lines (93 loc) · 2.05 KB
/
terraform.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
variable "region" { default = "us-east-1" }
variable "repository" { default = "openvpn-bosh-release" }
variable "owner" { default = "dpb587" }
provider "aws" {
region = "${var.region}"
}
#
# output
#
output "ci_access_key" {
value = "${aws_iam_access_key.ci.id}"
}
output "ci_secret_key" {
value = "${aws_iam_access_key.ci.secret}"
sensitive = true
}
output "ci_deploy_ssh_key" {
value = "${tls_private_key.ci_deploy_ssh_key.private_key_pem}"
sensitive = true
}
output "ci_deploy_ssh_key_pub" {
value = "${trimspace(tls_private_key.ci_deploy_ssh_key.public_key_openssh)} ci@terraform"
}
#
# github
#
resource "tls_private_key" "ci_deploy_ssh_key" {
algorithm = "RSA"
rsa_bits = 4096
}
#
# iam
#
resource "aws_iam_user" "ci" {
name = "${var.repository}-ci"
}
resource "aws_iam_access_key" "ci" {
user = "${aws_iam_user.ci.name}"
}
#
# s3
#
resource "aws_s3_bucket" "bucket" {
# bucket = "${var.owner}-${var.repository}-${var.region}"
# this is an old bucket with atypical naming conventions :(
bucket = "dpb587-bosh-release-openvpn-us-east-1"
logging {
target_bucket = "${var.owner}-aws-s3-${var.region}"
# target_prefix = "${aws_s3_bucket.bucket.id}/"
target_prefix = "dpb587-bosh-release-openvpn-us-east-1/"
}
versioning {
enabled = true
}
}
data "aws_iam_policy_document" "public_read" {
statement {
actions = [
"s3:GetObject",
]
effect = "Allow"
principals = {
type = "*"
identifiers = [
"*"
]
}
resources = [
"${aws_s3_bucket.bucket.arn}/*",
]
}
}
resource "aws_s3_bucket_policy" "bucket" {
bucket = "${aws_s3_bucket.bucket.id}"
policy = "${data.aws_iam_policy_document.public_read.json}"
}
data "aws_iam_policy_document" "ci_s3" {
statement {
actions = [
"s3:GetObject",
"s3:PutObject",
]
effect = "Allow"
resources = [
"${aws_s3_bucket.bucket.arn}/*",
]
}
}
resource "aws_iam_user_policy" "ci_s3" {
name = "s3"
user = "${aws_iam_user.ci.name}"
policy = "${data.aws_iam_policy_document.ci_s3.json}"
}