generated from getindata/terraform-module-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.tf
114 lines (90 loc) · 3.14 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
data "snowflake_system_get_privatelink_config" "this" {
count = module.this.enabled ? 1 : 0
}
data "aws_vpc" "this" {
count = local.vpc_cidr_enabled ? 1 : 0
id = var.vpc_id
}
resource "aws_security_group" "this" {
count = module.this.enabled ? 1 : 0
vpc_id = var.vpc_id
description = "Security group for Snowflake AWS PrivateLink VPC Endpoint"
ingress {
from_port = 80
to_port = 80
cidr_blocks = local.allowed_cidrs
protocol = "tcp"
description = "Allow HTTP ingress traffic"
}
ingress {
from_port = 443
to_port = 443
cidr_blocks = local.allowed_cidrs
protocol = "tcp"
description = "Allow HTTPS ingress traffic"
}
tags = module.this.tags
}
resource "aws_vpc_endpoint" "this" {
count = module.this.enabled ? 1 : 0
vpc_id = var.vpc_id
service_name = one(data.snowflake_system_get_privatelink_config.this[*].aws_vpce_id)
vpc_endpoint_type = "Interface"
security_group_ids = [one(aws_security_group.this[*].id)]
subnet_ids = var.subnet_ids
private_dns_enabled = false
tags = merge(module.this.tags,
{
Name = local.name_from_descriptor
}
)
}
resource "aws_route53_zone" "this" {
count = module.this.enabled ? 1 : 0
name = "privatelink.snowflakecomputing.com"
comment = "Snowflake AWS PrivateLink records"
vpc {
vpc_id = var.vpc_id
}
tags = module.this.tags
}
resource "aws_route53_record" "snowflake_private_link_url" {
count = module.this.enabled ? 1 : 0
zone_id = one(aws_route53_zone.this[*].zone_id)
name = one(data.snowflake_system_get_privatelink_config.this[*].account_url)
type = "CNAME"
ttl = "300"
records = [one(aws_vpc_endpoint.this).dns_entry[0]["dns_name"]]
}
resource "aws_route53_record" "snowflake_private_link_ocsp_url" {
count = module.this.enabled ? 1 : 0
zone_id = one(aws_route53_zone.this[*].zone_id)
name = one(data.snowflake_system_get_privatelink_config.this[*].ocsp_url)
type = "CNAME"
ttl = "300"
records = [one(aws_vpc_endpoint.this).dns_entry[0]["dns_name"]]
}
resource "aws_route53_record" "snowflake_regionless_private_link_account_url" {
count = module.this.enabled && local.snowflake_account != null ? 1 : 0
zone_id = one(aws_route53_zone.this[*].zone_id)
name = "${local.snowflake_account}.privatelink.snowflakecomputing.com"
type = "CNAME"
ttl = "300"
records = [one(aws_vpc_endpoint.this).dns_entry[0]["dns_name"]]
}
resource "aws_route53_record" "snowflake_regionless_private_link_snowsight_url" {
count = module.this.enabled && local.snowflake_account != null ? 1 : 0
zone_id = one(aws_route53_zone.this[*].zone_id)
name = "app-${local.snowflake_account}.privatelink.snowflakecomputing.com"
type = "CNAME"
ttl = "300"
records = [one(aws_vpc_endpoint.this).dns_entry[0]["dns_name"]]
}
resource "aws_route53_record" "snowflake_additional_dns_records" {
for_each = module.this.enabled ? toset(var.additional_dns_records) : []
zone_id = one(aws_route53_zone.this[*].zone_id)
name = each.key
type = "CNAME"
ttl = "300"
records = [one(aws_vpc_endpoint.this).dns_entry[0]["dns_name"]]
}