|
| 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 | +} |
0 commit comments