This repository has been archived by the owner on Jul 23, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 34
/
backups.tf
93 lines (78 loc) · 2.52 KB
/
backups.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
data "aws_iam_policy_document" "jenkins-backup-bucket-policy" {
statement {
effect = "Deny"
actions = [
"s3:*",
]
principals {
type = "AWS"
identifiers = ["*"]
}
resources = [
"${aws_s3_bucket.jenkins-duplicity-backup.arn}",
"${aws_s3_bucket.jenkins-duplicity-backup.arn}/*",
]
condition {
test = "StringNotLike"
variable = "aws:userId"
values = [
"${aws_iam_role.admin-access-role.unique_id}:*",
"${lookup(var.unmanaged_role_ids, "admin-ec2-role")}:*",
"${lookup(var.unmanaged_role_ids, "InfosecSecurityAuditRole")}:*",
"${var.aws_account_id}"
]
}
}
}
data "aws_iam_policy_document" "jenkins-public-backup-bucket-policy" {
statement {
effect = "Deny"
actions = [
"s3:*",
]
principals {
type = "AWS"
identifiers = ["*"]
}
resources = [
"${aws_s3_bucket.jenkins-public-duplicity-backup.arn}",
"${aws_s3_bucket.jenkins-public-duplicity-backup.arn}/*"
]
condition {
test = "StringNotLike"
variable = "aws:userId"
values = [
"${aws_iam_role.admin-access-role.unique_id}:*",
"${lookup(var.unmanaged_role_ids, "admin-ec2-role")}:*",
"${lookup(var.unmanaged_role_ids, "InfosecSecurityAuditRole")}:*",
"${var.aws_account_id}"
]
}
}
}
resource "aws_s3_bucket" "jenkins-duplicity-backup" {
bucket = "jenkins-duplicity-backup"
acl = "private"
tags = {
Name = "jenkins-duplicity-backup"
app = "duplicity"
project = "backup"
}
}
resource "aws_s3_bucket" "jenkins-public-duplicity-backup" {
bucket = "jenkins-public-duplicity-backup"
acl = "private"
tags = {
Name = "jenkins-public-duplicity-backup"
app = "duplicity"
project = "backup"
}
}
resource "aws_s3_bucket_policy" "jenkins-backup-bucket-policy-attachment" {
bucket = "${aws_s3_bucket.jenkins-duplicity-backup.id}"
policy = "${data.aws_iam_policy_document.jenkins-backup-bucket-policy.json}"
}
resource "aws_s3_bucket_policy" "jenkins-public-backup-bucket-policy-attachment" {
bucket = "${aws_s3_bucket.jenkins-public-duplicity-backup.id}"
policy = "${data.aws_iam_policy_document.jenkins-public-backup-bucket-policy.json}"
}