This repository has been archived by the owner on Dec 18, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathredirect.tf
61 lines (52 loc) · 1.75 KB
/
redirect.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
locals {
s3_website_endpoint_zone_id = var.s3_website_endpoint_zone_ids[var.aws_region]
}
resource "aws_route53_zone" "private" {
count = var.create_redirect ? 1 : 0
name = var.route53_hosted_zone_name
dynamic "vpc" {
for_each = var.vpc_ids
content {
vpc_id = vpc.value
}
}
lifecycle {
ignore_changes = [
# Ignore changes to vpcs, e.g. because a management agent
# updates these based on some ruleset managed elsewhere.
vpc,
]
}
tags = var.aws_route53_zone_tags
}
resource "aws_route53_record" "s3_alias" {
count = var.create_redirect ? 1 : 0
name = aws_s3_bucket.amg_bucket[0].bucket
type = "A"
zone_id = aws_route53_zone.private[0].zone_id
alias {
name = aws_s3_bucket_website_configuration.amg_bucket_website[0].website_endpoint
zone_id = local.s3_website_endpoint_zone_id
evaluate_target_health = false
}
}
# tfsec:ignore:aws-s3-enable-bucket-logging tfsec:ignore:aws-s3-enable-versioning tfsec:ignore:aws-s3-enable-bucket-encryption tfsec:ignore:aws-s3-encryption-customer-key
resource "aws_s3_bucket" "amg_bucket" {
count = var.create_redirect ? 1 : 0
bucket = "grafana.${var.route53_hosted_zone_name}"
}
resource "aws_s3_bucket_public_access_block" "amg_bucket" {
count = var.create_redirect ? 1 : 0
bucket = aws_s3_bucket.amg_bucket[0].id
block_public_acls = true
block_public_policy = true
ignore_public_acls = true
restrict_public_buckets = true
}
resource "aws_s3_bucket_website_configuration" "amg_bucket_website" {
count = var.create_redirect ? 1 : 0
bucket = aws_s3_bucket.amg_bucket[0].bucket
redirect_all_requests_to {
host_name = var.amg_redirect_hostname
}
}