forked from ibm-cloud-architecture/terraform-icp-aws
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy paths3.tf
75 lines (69 loc) · 2.22 KB
/
s3.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
# configuration backup s3 bucket
resource "aws_s3_bucket" "icp_config_backup" {
bucket = "icpbackup-${random_id.clusterid.hex}"
acl = "private"
force_destroy = true # Set to false to keep the backup even if we do a terraform destroy
tags =
"${merge(
var.default_tags,
map("Name", "icp-backup-${random_id.clusterid.hex}"),
map("icp_instance", var.instance_name ))}"
}
# upload scripts to config backup bucket
resource "aws_s3_bucket_object" "bootstrap" {
bucket = "${aws_s3_bucket.icp_config_backup.id}"
key = "scripts/bootstrap.sh"
source = "${path.module}/scripts/bootstrap.sh"
}
resource "aws_s3_bucket_object" "create_client_cert" {
bucket = "${aws_s3_bucket.icp_config_backup.id}"
key = "scripts/create_client_cert.sh"
source = "${path.module}/scripts/create_client_cert.sh"
}
resource "aws_s3_bucket_object" "functions" {
bucket = "${aws_s3_bucket.icp_config_backup.id}"
key = "scripts/functions.sh"
source = "${path.module}/scripts/functions.sh"
}
resource "aws_s3_bucket_object" "start_install" {
bucket = "${aws_s3_bucket.icp_config_backup.id}"
key = "scripts/start_install.sh"
source = "${path.module}/scripts/start_install.sh"
}
# lock down bucket access to just my VPC and terraform user
resource "aws_s3_bucket_policy" "icp_config_backup_policy_allow_vpc" {
bucket = "${aws_s3_bucket.icp_config_backup.id}"
policy =<<POLICY
{
"Version": "2012-10-17",
"Id": "icp_config_backup_vpc-${random_id.clusterid.hex}",
"Statement": [
{
"Sid": "Access-to-terraform-user",
"Action": "s3:*",
"Effect": "Allow",
"Resource": ["${aws_s3_bucket.icp_config_backup.arn}",
"${aws_s3_bucket.icp_config_backup.arn}/*"],
"Principal": {
"AWS": [
"${data.aws_caller_identity.current.arn}"
]
}
},
{
"Sid": "Access-to-icp-vpc",
"Action": "s3:*",
"Effect": "Allow",
"Resource": ["${aws_s3_bucket.icp_config_backup.arn}",
"${aws_s3_bucket.icp_config_backup.arn}/*"],
"Principal": "*",
"Condition": {
"StringEquals": {
"aws:sourceVpc": "${aws_vpc.icp_vpc.id}"
}
}
}
]
}
POLICY
}