Skip to content

Commit 51c4584

Browse files
authored
Merge pull request #28 from skysqlinc/DEV-259-privatelink-example
Add azure privatelink example
2 parents a4cd8b8 + 6318d4f commit 51c4584

File tree

4 files changed

+148
-0
lines changed

4 files changed

+148
-0
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
locals {
2+
dns_domain = join(".", [var.skysql_organization_id, var.skysql_base_domain])
3+
dns_link_name = join(".", [var.skysql_organization_id, replace(var.skysql_base_domain, ".", "-")])
4+
}
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
data "azurerm_subscription" "current" {}
2+
3+
data "azurerm_resource_group" "this" {
4+
name = var.resource_group_name
5+
depends_on = [azurerm_resource_group.this]
6+
}
7+
8+
data "skysql_versions" "this" {
9+
topology = var.topology
10+
}
11+
12+
data "skysql_service" "this" {
13+
service_id = skysql_service.this.id
14+
}
15+
16+
###
17+
# Create the SkySQL service
18+
###
19+
resource "skysql_service" "this" {
20+
service_type = "transactional"
21+
topology = var.topology
22+
cloud_provider = "azure"
23+
region = var.location
24+
name = var.skysql_service_name
25+
architecture = "amd64"
26+
nodes = 1
27+
size = "sky-2x8"
28+
storage = 100
29+
ssl_enabled = true
30+
version = data.skysql_versions.this.versions[0].name
31+
endpoint_mechanism = "privateconnect"
32+
endpoint_allowed_accounts = [data.azurerm_subscription.current.subscription_id]
33+
wait_for_creation = true
34+
# The following line will be required when tearing down the skysql service
35+
# deletion_protection = false
36+
}
37+
38+
resource "azurerm_resource_group" "this" {
39+
count = var.create_resource_group ? 1 : 0
40+
name = var.resource_group_name
41+
location = var.location
42+
}
43+
44+
resource "azurerm_private_dns_zone" "this" {
45+
name = local.dns_domain
46+
resource_group_name = data.azurerm_resource_group.this.name
47+
}
48+
49+
resource "azurerm_private_dns_zone_virtual_network_link" "this" {
50+
name = local.dns_link_name
51+
resource_group_name = data.azurerm_resource_group.this.name
52+
private_dns_zone_name = azurerm_private_dns_zone.this.name
53+
virtual_network_id = var.virtual_network_id
54+
}
55+
56+
resource "azurerm_private_endpoint" "this" {
57+
name = var.skysql_service_name
58+
location = data.azurerm_resource_group.this.location
59+
resource_group_name = data.azurerm_resource_group.this.name
60+
subnet_id = var.subnet_id
61+
62+
private_service_connection {
63+
name = var.database_name
64+
private_connection_resource_alias = data.skysql_service.this.endpoints[0].endpoint_service
65+
is_manual_connection = true
66+
request_message = "PL"
67+
68+
}
69+
}
70+
71+
resource "azurerm_private_dns_a_record" "this" {
72+
name = skysql_service.this.id
73+
zone_name = azurerm_private_dns_zone.this.name
74+
resource_group_name = data.azurerm_resource_group.this.name
75+
ttl = 300
76+
records = [azurerm_private_endpoint.this.private_service_connection[0].private_ip_address]
77+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
terraform {
2+
required_providers {
3+
skysql = {
4+
source = "registry.terraform.io/skysqlinc/skysql"
5+
version = "1.0.0"
6+
}
7+
azurerm = {
8+
source = "hashicorp/azurerm"
9+
version = "3.96.0"
10+
}
11+
}
12+
}
13+
14+
provider "skysql" {}
15+
provider "azurerm" {
16+
features {}
17+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
variable "location" {
2+
description = "The Azure Region in which all resources will be created."
3+
type = string
4+
default = "eastus"
5+
}
6+
7+
variable "resource_group_name" {
8+
description = "The name of the resource group in which all resources will be created."
9+
type = string
10+
default = "skysql-private-link"
11+
}
12+
13+
variable "create_resource_group" {
14+
description = "Create a new resource group or use an existing one."
15+
type = bool
16+
default = true
17+
}
18+
19+
variable "skysql_organization_id" {
20+
description = "The SkySQL Organization ID."
21+
type = string
22+
}
23+
24+
variable "skysql_base_domain" {
25+
description = "The base domain for SkySQL database endpoints."
26+
default = "db3.skysql.com"
27+
type = string
28+
}
29+
30+
variable "virtual_network_id" {
31+
description = "The ID of the virtual network where the private endpoint will be created."
32+
type = string
33+
}
34+
35+
variable "subnet_id" {
36+
description = "The ID of the subnet where the private endpoint will be created."
37+
type = string
38+
}
39+
40+
variable "skysql_service_name" {
41+
description = "The name of the database to create."
42+
type = string
43+
default = "skysql-private-link"
44+
}
45+
46+
variable "topology" {
47+
description = "The SkySQL topology to deploy."
48+
type = string
49+
default = "es-single"
50+
}

0 commit comments

Comments
 (0)