This repository has been archived by the owner on Jul 19, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.tf
115 lines (93 loc) · 2.76 KB
/
main.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
111
112
113
114
provider "aws" {
version = "~> 2.60.0"
region = "us-east-1"
}
resource "aws_acm_certificate" "certificate" {
domain_name = var.primary_domain
validation_method = "DNS"
tags = {
Environment = "dropshare"
}
lifecycle {
create_before_destroy = true
}
subject_alternative_names = [
"*.${var.primary_domain}"
]
}
data "aws_route53_zone" "primary" {
name = "${var.primary_domain}."
private_zone = false
}
resource "aws_route53_record" "rebrandly" {
zone_id = data.aws_route53_zone.primary.zone_id
name = var.primary_domain
type = "A"
ttl = "300"
records = ["52.72.49.79"]
}
resource "aws_route53_record" "cert_verification" {
name = aws_acm_certificate.certificate.domain_validation_options.0.resource_record_name
type = aws_acm_certificate.certificate.domain_validation_options.0.resource_record_type
zone_id = data.aws_route53_zone.primary.zone_id
records = ["${aws_acm_certificate.certificate.domain_validation_options.0.resource_record_value}"]
ttl = 60
}
resource "aws_acm_certificate_validation" "validation" {
certificate_arn = aws_acm_certificate.certificate.arn
validation_record_fqdns = ["${aws_route53_record.cert_verification.fqdn}"]
}
module "cloudfront-s3-cdn" {
name = "${replace(var.primary_domain, ".", "-")}"
source = "cloudposse/cloudfront-s3-cdn/aws"
version = "0.23.1"
aliases = ["share.${var.primary_domain}"]
parent_zone_name = var.primary_domain
logging_enabled = false
price_class = "PriceClass_All"
minimum_protocol_version = "TLSv1.2_2018"
acm_certificate_arn = "${aws_acm_certificate_validation.validation.certificate_arn}"
}
resource "aws_iam_user" "dropshare_user" {
name = "dropshare"
tags = {
Environment = "dropshare"
}
}
resource "aws_iam_user_policy" "dropshare_origin_access" {
name = "test"
user = aws_iam_user.dropshare_user.name
policy = <<EOF
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": "s3:*",
"Resource": [
"arn:aws:s3:::${module.cloudfront-s3-cdn.s3_bucket}/*",
"arn:aws:s3:::${module.cloudfront-s3-cdn.s3_bucket}"
]
}
]
}
EOF
}
resource "aws_iam_access_key" "dropshare_user" {
user = aws_iam_user.dropshare_user.name
}
output "bucket_name" {
value = module.cloudfront-s3-cdn.s3_bucket
}
output "aws_access_key_id" {
value = aws_iam_access_key.dropshare_user.id
}
output "aws_secret_access_key" {
value = aws_iam_access_key.dropshare_user.secret
}
output "region" {
value = "us-east-1 (N. Virginia)"
}
output "domain_alias" {
value = module.cloudfront-s3-cdn.aliases.0
}