The Azure peering connection resource allows you to manage a peering connection between an HVN and a peer Azure VNet.
resource "hcp_hvn" "hvn" {
hvn_id = "main-hvn"
cloud_provider = "azure"
region = "westus2"
cidr_block = "172.25.16.0/20"
}
// This resource initially returns in a Pending state, because its application_id is required to complete acceptance of the connection.
resource "hcp_azure_peering_connection" "peer" {
hvn_link = hcp_hvn.hvn.self_link
peering_id = "dev"
peer_vnet_name = azurerm_virtual_network.vnet.name
peer_subscription_id = azurerm_subscription.sub.subscription_id
peer_tenant_id = "<tenant UUID>"
peer_resource_group_name = azurerm_resource_group.rg.name
peer_vnet_region = azurerm_virtual_network.vnet.location
}
// This data source is the same as the resource above, but waits for the connection to be Active before returning.
data "hcp_azure_peering_connection" "peer" {
hvn_link = hcp_hvn.hvn.self_link
peering_id = hcp_azure_peering_connection.peer.peering_id
wait_for_active_state = true
}
// The route depends on the data source, rather than the resource, to ensure the peering is in an Active state.
resource "hcp_hvn_route" "route" {
hvn_link = hcp_hvn.hvn.self_link
hvn_route_id = "azure-route"
destination_cidr = "172.31.0.0/16"
target_link = data.hcp_azure_peering_connection.peer.self_link
}
provider "azurerm" {
features {}
}
provider "azuread" {}
data "azurerm_subscription" "sub" {
subscription_id = "<subscription UUID>"
}
resource "azurerm_resource_group" "rg" {
name = "resource-group-test"
location = "West US"
}
resource "azurerm_virtual_network" "vnet" {
name = "vnet-test"
location = azurerm_resource_group.rg.location
resource_group_name = azurerm_resource_group.rg.name
address_space = [
"10.0.0.0/16"
]
}
resource "azuread_service_principal" "principal" {
application_id = hcp_azure_peering_connection.peer.application_id
}
resource "azurerm_role_definition" "definition" {
name = "hcp-hvn-peering-access"
scope = azurerm_virtual_network.vnet.id
assignable_scopes = [
azurerm_virtual_network.vnet.id
]
permissions {
actions = [
"Microsoft.Network/virtualNetworks/peer/action",
"Microsoft.Network/virtualNetworks/virtualNetworkPeerings/read",
"Microsoft.Network/virtualNetworks/virtualNetworkPeerings/write"
]
}
}
resource "azurerm_role_assignment" "assignment" {
principal_id = azuread_service_principal.principal.id
scope = azurerm_virtual_network.vnet.id
role_definition_id = azurerm_role_definition.definition.role_definition_resource_id
}
hvn_link
(String) The self_link
of the HashiCorp Virtual Network (HVN).peer_resource_group_name
(String) The resource group name of the peer VNet in Azure.peer_subscription_id
(String) The subscription ID of the peer VNet in Azure.peer_tenant_id
(String) The tenant ID of the peer VNet in Azure.peer_vnet_name
(String) The name of the peer VNet in Azure.peer_vnet_region
(String) The region of the peer VNet in Azure.peering_id
(String) The ID of the peering connection.allow_forwarded_traffic
(Boolean) Whether the forwarded traffic originating from the peered VNet is allowed in the HVNtimeouts
(Block, Optional) (see below for nested schema)use_remote_gateways
(Boolean) If the HVN should use the gateway of the peered VNetapplication_id
(String) The ID of the Azure application whose credentials are used to peer the HCP HVN's underlying VNet with the customer VNet.azure_peering_id
(String) The peering connection ID used by Azure.created_at
(String) The time that the peering connection was created.expires_at
(String) The time after which the peering connection will be considered expired if it hasn't transitioned into ACCEPTED
or ACTIVE
state.id
(String) The ID of this resource.organization_id
(String) The ID of the HCP organization where the peering connection is located. Always matches the HVN's organization.project_id
(String) The ID of the HCP project where the peering connection is located. Always matches the HVN's project.self_link
(String) A unique URL identifying the peering connection.state
(String) The state of the Azure peering connection.timeouts
Optional:
create
(String)default
(String)delete
(String)Import is supported using the following syntax:
# Using an explicit project ID, the import ID is:
# {project_id}:{hvn_id}:{peering_id}
terraform import hcp_azure_peering_connection.peer f709ec73-55d4-46d8-897d-816ebba28778:main-hvn:199e7e96-4d5f-4456-91f3-b6cc71f1e561
# Using the provider-default project ID, the import ID is:
# {hvn_id}:{peering_id}
terraform import hcp_azure_peering_connection.peer main-hvn:199e7e96-4d5f-4456-91f3-b6cc71f1e561