Created
May 4, 2022 12:57
-
-
Save aravindputrevu/728aae6e8f69713a6bee1199bd37cd5d to your computer and use it in GitHub Desktop.
A Simple Terraform Script for creating a Azure Private Link Endpoint & A Private DNS Zone
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
terraform { | |
required_providers { | |
azurerm = { | |
source = "hashicorp/azurerm" | |
version = "<LATEST_VERSION_FROM_REGISTRY_TERRAFORM_IO>" | |
} | |
} | |
} | |
provider "azurerm" { | |
features {} | |
} | |
data "azurerm_resource_group" "rg" { | |
name = "<RESOURCE_GROUP_NAME>" | |
} | |
resource "azurerm_virtual_network" "vn" { | |
name = "elastic-byte-vnet" | |
location = "Central India" | |
resource_group_name = data.azurerm_resource_group.rg.name | |
address_space = ["10.1.0.0/16"] | |
} | |
resource "azurerm_subnet" "subnet" { | |
name = "default" | |
virtual_network_name = azurerm_virtual_network.vn.name | |
resource_group_name = data.azurerm_resource_group.rg.name | |
address_prefixes = ["10.1.0.0/24"] | |
} | |
resource "azurerm_private_endpoint" "pe" { | |
name = "elastic-byte-endpoint" | |
location = "Central India" | |
resource_group_name = data.azurerm_resource_group.rg.name | |
subnet_id = azurerm_subnet.subnet.id | |
private_service_connection { | |
name = "esbyte-privateserviceconnection" | |
private_connection_resource_alias = "centralindia-prod-016-privatelink-service.071806ca-8101-425b-ae86-737935a719d3.centralindia.azure.privatelinkservice" | |
is_manual_connection = true | |
request_message = "Please approve this request to connect to the private endpoint" | |
} | |
tags{ | |
owner = "[email protected]" | |
} | |
} | |
resource "azurerm_private_dns_zone" "pvt-dns-zone" { | |
name = "privatelink.centralindia.azure.elastic-cloud.com" | |
resource_group_name = data.azurerm_resource_group.rg.name | |
tags = { | |
user = "[email protected]" | |
} | |
} | |
resource "azurerm_private_dns_zone_virtual_network_link" "pvt-dns-zone-vnet-link" { | |
name = "elastic-byte-vnet-link" | |
resource_group_name = data.azurerm_resource_group.rg.name | |
private_dns_zone_name = azurerm_private_dns_zone.pvt-dns-zone.name | |
virtual_network_id = azurerm_virtual_network.vn.id | |
} | |
resource "azurerm_private_dns_a_record" "pvt-dns-a-record" { | |
name = "*" | |
zone_name = azurerm_private_dns_zone.pvt-dns-zone.name | |
resource_group_name = data.azurerm_resource_group.rg.name | |
ttl = 3600 | |
records = ["10.1.0.4"] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment