forked from CodelyTV/terraform-course
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.tf
More file actions
executable file
·47 lines (40 loc) · 909 Bytes
/
main.tf
File metadata and controls
executable file
·47 lines (40 loc) · 909 Bytes
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
locals {
whitelist_cidr = ["0.0.0.0/0"]
}
resource "aws_s3_bucket" "example_bucket" {
bucket = var.bucket_name
tags = {
Environment = "Dev"
Project = "Codely course"
}
}
resource "aws_s3_object" "object" {
bucket = aws_s3_bucket.example_bucket.id
key = "hello-world"
source = "hello-world.html"
content_type = "text/html"
}
resource "aws_s3_bucket_policy" "main" {
bucket = aws_s3_bucket.example_bucket.id
policy = data.aws_iam_policy_document.main.json
}
data "aws_iam_policy_document" "main" {
statement {
effect = "Allow"
actions = [
"s3:GetObject"
]
resources = [
"${aws_s3_bucket.example_bucket.arn}/*"
]
condition {
variable = "aws:sourceIp"
test = "IpAddress"
values = local.whitelist_cidr #Restrict to your IP"
}
principals {
type = "AWS"
identifiers = ["*"]
}
}
}