Skip to content

Commit 2aed381

Browse files
authored
Merge pull request #4 from getindata/feat/additional_dns_records
feat: Add additional DNS records to Route53
2 parents 4830c24 + 03bcd7c commit 2aed381

File tree

6 files changed

+92
-2
lines changed

6 files changed

+92
-2
lines changed

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ more information can be found in Snowflake Documentation -
6464

6565
| Name | Description | Type | Default | Required |
6666
|------|-------------|------|---------|:--------:|
67+
| <a name="input_account_name"></a> [account\_name](#input\_account\_name) | Name of the Snowflake account, used to create regionless privatelink fqdns | `string` | `null` | no |
68+
| <a name="input_additional_dns_records"></a> [additional\_dns\_records](#input\_additional\_dns\_records) | List of additional Route53 records to be added to local `privatelink.snowflakecomputing.com` hosted zone that points to Snowflake VPC endpoint. | `list(string)` | `[]` | no |
6769
| <a name="input_additional_tag_map"></a> [additional\_tag\_map](#input\_additional\_tag\_map) | Additional key-value pairs to add to each map in `tags_as_list_of_maps`. Not added to `tags` or `id`.<br>This is for some rare cases where resources want additional configuration of tags<br>and therefore take a list of maps with tag key, value, and additional configuration. | `map(string)` | `{}` | no |
6870
| <a name="input_allow_vpc_cidr"></a> [allow\_vpc\_cidr](#input\_allow\_vpc\_cidr) | Whether allow access to the Snowflake PrivateLink endpoint from the whole VPC | `bool` | `true` | no |
6971
| <a name="input_allowed_cidrs"></a> [allowed\_cidrs](#input\_allowed\_cidrs) | List of subnet CIDRs that will be allowed to access Snowflake endpoint via PrivateLink | `list(string)` | `[]` | no |
@@ -81,6 +83,7 @@ more information can be found in Snowflake Documentation -
8183
| <a name="input_labels_as_tags"></a> [labels\_as\_tags](#input\_labels\_as\_tags) | Set of labels (ID elements) to include as tags in the `tags` output.<br>Default is to include all labels.<br>Tags with empty values will not be included in the `tags` output.<br>Set to `[]` to suppress all generated tags.<br>**Notes:**<br> The value of the `name` tag, if included, will be the `id`, not the `name`.<br> Unlike other `null-label` inputs, the initial setting of `labels_as_tags` cannot be<br> changed in later chained modules. Attempts to change it will be silently ignored. | `set(string)` | <pre>[<br> "default"<br>]</pre> | no |
8284
| <a name="input_name"></a> [name](#input\_name) | ID element. Usually the component or solution name, e.g. 'app' or 'jenkins'.<br>This is the only ID element not also included as a `tag`.<br>The "name" tag is set to the full `id` string. There is no tag with the value of the `name` input. | `string` | `null` | no |
8385
| <a name="input_namespace"></a> [namespace](#input\_namespace) | ID element. Usually an abbreviation of your organization name, e.g. 'eg' or 'cp', to help ensure generated IDs are globally unique | `string` | `null` | no |
86+
| <a name="input_organisation_name"></a> [organisation\_name](#input\_organisation\_name) | Name of the organisation, where the Snowflake account is created, used to create regionless privatelink fqdns | `string` | `null` | no |
8487
| <a name="input_regex_replace_chars"></a> [regex\_replace\_chars](#input\_regex\_replace\_chars) | Terraform regular expression (regex) string.<br>Characters matching the regex will be removed from the ID elements.<br>If not set, `"/[^a-zA-Z0-9-]/"` is used to remove all characters other than hyphens, letters and digits. | `string` | `null` | no |
8588
| <a name="input_stage"></a> [stage](#input\_stage) | ID element. Usually used to indicate role, e.g. 'prod', 'staging', 'source', 'build', 'test', 'deploy', 'release' | `string` | `null` | no |
8689
| <a name="input_subnet_ids"></a> [subnet\_ids](#input\_subnet\_ids) | List of AWS Subnet IDs where Snowflake AWS PrivateLink Endpoint interfaces will be created | `list(string)` | n/a | yes |
@@ -100,8 +103,11 @@ more information can be found in Snowflake Documentation -
100103
|------|-------------|
101104
| <a name="output_dns_private_zone"></a> [dns\_private\_zone](#output\_dns\_private\_zone) | Details of Route53 private hosted zone created for Snowflake PrivateLink |
102105
| <a name="output_security_group"></a> [security\_group](#output\_security\_group) | Details of security group assigned to Snowflake AWS PrivateLink VPC Endpoint |
106+
| <a name="output_snowflake_additional_dns_records"></a> [snowflake\_additional\_dns\_records](#output\_snowflake\_additional\_dns\_records) | List of additional DNS records added to `.privatelink.snowflakecomputing.com` hosted zone |
103107
| <a name="output_snowflake_privatelink_ocsp_url"></a> [snowflake\_privatelink\_ocsp\_url](#output\_snowflake\_privatelink\_ocsp\_url) | URL to access Snowflake OCSP endpont using AWS PrivateLink |
104108
| <a name="output_snowflake_privatelink_url"></a> [snowflake\_privatelink\_url](#output\_snowflake\_privatelink\_url) | URL to access Snowflake using AWS PrivateLink |
109+
| <a name="output_snowflake_regionless_private_link_account_url"></a> [snowflake\_regionless\_private\_link\_account\_url](#output\_snowflake\_regionless\_private\_link\_account\_url) | URL to access Snowflake account using AWS PrivateLink without specifying AWS region |
110+
| <a name="output_snowflake_regionless_private_link_snowsight_url"></a> [snowflake\_regionless\_private\_link\_snowsight\_url](#output\_snowflake\_regionless\_private\_link\_snowsight\_url) | URL to access Snowsight UI using AWS PrivateLink without specifying AWS region |
105111
| <a name="output_vpc_endpoint"></a> [vpc\_endpoint](#output\_vpc\_endpoint) | Details created Snowflake AWS PrivateLink VPC Endpoint |
106112

107113
## Providers
@@ -123,8 +129,11 @@ more information can be found in Snowflake Documentation -
123129

124130
| Name | Type |
125131
|------|------|
132+
| [aws_route53_record.snowflake_additional_dns_records](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/route53_record) | resource |
126133
| [aws_route53_record.snowflake_private_link_ocsp_url](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/route53_record) | resource |
127134
| [aws_route53_record.snowflake_private_link_url](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/route53_record) | resource |
135+
| [aws_route53_record.snowflake_regionless_private_link_account_url](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/route53_record) | resource |
136+
| [aws_route53_record.snowflake_regionless_private_link_snowsight_url](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/route53_record) | resource |
128137
| [aws_route53_zone.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/route53_zone) | resource |
129138
| [aws_security_group.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/security_group) | resource |
130139
| [aws_vpc_endpoint.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/vpc_endpoint) | resource |

examples/complete/main.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,12 @@ module "snowflake_privatelink_aws" {
5252
subnet_ids = [resource.aws_subnet.this.id]
5353
allowed_cidrs = ["10.10.0.0/16"]
5454
allow_vpc_cidr = true
55+
56+
organisation_name = "snoworg"
57+
account_name = "snowflake_tst"
58+
additional_dns_records = [
59+
"additional.dns.privatelink.snowflakecomputing.com"
60+
]
5561
}
5662

5763
# Example CloudWatch log group for Route53 zone

locals.tf

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
locals {
2-
vpc_cidr_enabled = module.this.enabled && var.allow_vpc_cidr ? 1 : 0
2+
vpc_cidr_enabled = module.this.enabled && var.allow_vpc_cidr
33

44
name_from_descriptor = module.this.enabled ? trim(replace(
55
lookup(module.this.descriptors, var.descriptor_name, module.this.id), "/${module.this.delimiter}${module.this.delimiter}+/", module.this.delimiter
@@ -9,4 +9,6 @@ locals {
99
var.allow_vpc_cidr ? [one(data.aws_vpc.this).cidr_block] : [],
1010
var.allowed_cidrs
1111
)
12+
13+
snowflake_account = var.organisation_name != null && var.account_name != null ? "${var.organisation_name}-${var.account_name}" : null
1214
}

main.tf

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ data "snowflake_system_get_privatelink_config" "this" {
33
}
44

55
data "aws_vpc" "this" {
6-
count = local.vpc_cidr_enabled
6+
count = local.vpc_cidr_enabled ? 1 : 0
77

88
id = var.vpc_id
99
}
@@ -82,3 +82,33 @@ resource "aws_route53_record" "snowflake_private_link_ocsp_url" {
8282
ttl = "300"
8383
records = [one(aws_vpc_endpoint.this).dns_entry[0]["dns_name"]]
8484
}
85+
86+
resource "aws_route53_record" "snowflake_regionless_private_link_account_url" {
87+
count = module.this.enabled && local.snowflake_account != null ? 1 : 0
88+
89+
zone_id = one(aws_route53_zone.this[*].zone_id)
90+
name = "${local.snowflake_account}.privatelink.snowflakecomputing.com"
91+
type = "CNAME"
92+
ttl = "300"
93+
records = [one(aws_vpc_endpoint.this).dns_entry[0]["dns_name"]]
94+
}
95+
96+
resource "aws_route53_record" "snowflake_regionless_private_link_snowsight_url" {
97+
count = module.this.enabled && local.snowflake_account != null ? 1 : 0
98+
99+
zone_id = one(aws_route53_zone.this[*].zone_id)
100+
name = "app-${local.snowflake_account}.privatelink.snowflakecomputing.com"
101+
type = "CNAME"
102+
ttl = "300"
103+
records = [one(aws_vpc_endpoint.this).dns_entry[0]["dns_name"]]
104+
}
105+
106+
resource "aws_route53_record" "snowflake_additional_dns_records" {
107+
for_each = module.this.enabled ? toset(var.additional_dns_records) : []
108+
109+
zone_id = one(aws_route53_zone.this[*].zone_id)
110+
name = each.key
111+
type = "CNAME"
112+
ttl = "300"
113+
records = [one(aws_vpc_endpoint.this).dns_entry[0]["dns_name"]]
114+
}

outputs.tf

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,24 @@ output "snowflake_privatelink_ocsp_url" {
4747
fqdn = one(resource.aws_route53_record.snowflake_private_link_ocsp_url[*].fqdn)
4848
}
4949
}
50+
51+
output "snowflake_regionless_private_link_account_url" {
52+
description = "URL to access Snowflake account using AWS PrivateLink without specifying AWS region"
53+
value = {
54+
fqdn = one(resource.aws_route53_record.snowflake_regionless_private_link_account_url[*].fqdn)
55+
url = module.this.enabled && local.snowflake_account != null ? "https://${one(resource.aws_route53_record.snowflake_regionless_private_link_account_url[*].fqdn)}" : null
56+
}
57+
}
58+
59+
output "snowflake_regionless_private_link_snowsight_url" {
60+
description = "URL to access Snowsight UI using AWS PrivateLink without specifying AWS region"
61+
value = {
62+
fqdn = one(resource.aws_route53_record.snowflake_regionless_private_link_snowsight_url[*].fqdn)
63+
url = module.this.enabled && local.snowflake_account != null ? "https://${one(resource.aws_route53_record.snowflake_regionless_private_link_snowsight_url[*].fqdn)}" : null
64+
}
65+
}
66+
67+
output "snowflake_additional_dns_records" {
68+
description = "List of additional DNS records added to `.privatelink.snowflakecomputing.com` hosted zone"
69+
value = [for r in resource.aws_route53_record.snowflake_additional_dns_records : r.fqdn]
70+
}

variables.tf

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,25 @@ variable "descriptor_name" {
2525
type = string
2626
default = "snowflake-privatelink"
2727
}
28+
29+
variable "additional_dns_records" {
30+
description = "List of additional Route53 records to be added to local `privatelink.snowflakecomputing.com` hosted zone that points to Snowflake VPC endpoint."
31+
type = list(string)
32+
default = []
33+
validation {
34+
condition = alltrue([for r in var.additional_dns_records : endswith(r, ".privatelink.snowflakecomputing.com")])
35+
error_message = "Each DNS record should be a subdomain of '.privatelink.snowflakecomputing.com'."
36+
}
37+
}
38+
39+
variable "organisation_name" {
40+
description = "Name of the organisation, where the Snowflake account is created, used to create regionless privatelink fqdns"
41+
type = string
42+
default = null
43+
}
44+
45+
variable "account_name" {
46+
description = "Name of the Snowflake account, used to create regionless privatelink fqdns"
47+
type = string
48+
default = null
49+
}

0 commit comments

Comments
 (0)