Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Recoveryservices - support for recovery_public_ip #10446

Merged
merged 11 commits into from
Feb 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -190,13 +190,21 @@ func networkInterfaceResource() *schema.Resource {
"target_static_ip": {
Type: schema.TypeString,
Optional: true,
ForceNew: false,
ValidateFunc: validation.StringIsNotEmpty,
},
"target_subnet_name": {
Type: schema.TypeString,
Optional: true,
ForceNew: false,
ValidateFunc: validation.StringIsNotEmpty,
},
"recovery_public_ip_address_id": {
Type: schema.TypeString,
Optional: true,
ForceNew: false,
ValidateFunc: azure.ValidateResourceID,
},
},
}
}
Expand Down Expand Up @@ -320,6 +328,7 @@ func resourceSiteRecoveryReplicatedItemUpdate(d *schema.ResourceData, meta inter
sourceNicId := vmNicInput["source_network_interface_id"].(string)
targetStaticIp := vmNicInput["target_static_ip"].(string)
targetSubnetName := vmNicInput["target_subnet_name"].(string)
recoveryPublicIPAddressID := vmNicInput["recovery_public_ip_address_id"].(string)

nicId := findNicId(state, sourceNicId)
if nicId == nil {
Expand All @@ -329,6 +338,7 @@ func resourceSiteRecoveryReplicatedItemUpdate(d *schema.ResourceData, meta inter
NicID: nicId,
RecoveryVMSubnetName: &targetSubnetName,
ReplicaNicStaticIPAddress: &targetStaticIp,
RecoveryPublicIPAddressID: &recoveryPublicIPAddressID,
})
}

Expand Down Expand Up @@ -462,6 +472,9 @@ func resourceSiteRecoveryReplicatedItemRead(d *schema.ResourceData, meta interfa
if nic.RecoveryVMSubnetName != nil {
nicOutput["target_subnet_name"] = *nic.RecoveryVMSubnetName
}
if nic.RecoveryPublicIPAddressID != nil {
nicOutput["recovery_public_ip_address_id"] = *nic.RecoveryPublicIPAddressID
}
nicsOutput = append(nicsOutput, nicOutput)
}
d.Set("network_interface", schema.NewSet(schema.HashResource(networkInterfaceResource()), nicsOutput))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ resource "azurerm_subnet" "test1" {
name = "snet-%[1]d"
resource_group_name = azurerm_resource_group.test.name
virtual_network_name = azurerm_virtual_network.test1.name
address_prefix = "192.168.1.0/24"
address_prefixes = ["192.168.1.0/24"]
}

resource "azurerm_virtual_network" "test2" {
Expand All @@ -130,21 +130,14 @@ resource "azurerm_subnet" "test2_1" {
name = "acctest-snet-%[1]d_1"
resource_group_name = "${azurerm_resource_group.test2.name}"
virtual_network_name = "${azurerm_virtual_network.test2.name}"
address_prefix = "192.168.2.0/27"
address_prefixes = ["192.168.2.0/27"]
}

resource "azurerm_subnet" "test2_2" {
name = "snet-%[1]d_2"
resource_group_name = "${azurerm_resource_group.test2.name}"
virtual_network_name = "${azurerm_virtual_network.test2.name}"
address_prefix = "192.168.2.32/27"
}

resource "azurerm_subnet" "test2_3" {
name = "snet-%[1]d_3"
resource_group_name = "${azurerm_resource_group.test2.name}"
virtual_network_name = "${azurerm_virtual_network.test2.name}"
address_prefix = "192.168.2.64/27"
address_prefixes = ["192.168.2.32/27"]
}

resource "azurerm_site_recovery_network_mapping" "test" {
Expand All @@ -166,6 +159,7 @@ resource "azurerm_network_interface" "test" {
name = "vm-%[1]d"
subnet_id = azurerm_subnet.test1.id
private_ip_address_allocation = "Dynamic"
public_ip_address_id = azurerm_public_ip.test-source.id
}
}

Expand Down Expand Up @@ -203,6 +197,22 @@ resource "azurerm_virtual_machine" "test" {
network_interface_ids = [azurerm_network_interface.test.id]
}

resource "azurerm_public_ip" "test-source" {
name = "pubip%[1]d-source"
allocation_method = "Static"
location = azurerm_resource_group.test.location
resource_group_name = azurerm_resource_group.test.name
sku = "Basic"
}

resource "azurerm_public_ip" "test-recovery" {
name = "pubip%[1]d-recovery"
allocation_method = "Static"
location = azurerm_resource_group.test2.location
resource_group_name = azurerm_resource_group.test2.name
sku = "Basic"
}

resource "azurerm_storage_account" "test" {
name = "acct%[1]d"
location = azurerm_resource_group.test.location
Expand Down Expand Up @@ -233,8 +243,9 @@ resource "azurerm_site_recovery_replicated_vm" "test" {
}

network_interface {
source_network_interface_id = azurerm_network_interface.test.id
target_subnet_name = "snet-%[1]d_2"
source_network_interface_id = azurerm_network_interface.test.id
target_subnet_name = "snet-%[1]d_2"
recovery_public_ip_address_id = azurerm_public_ip.test-recovery.id
}

depends_on = [
Expand Down
39 changes: 39 additions & 0 deletions website/docs/r/site_recovery_replicated_vm.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -124,13 +124,43 @@ resource "azurerm_virtual_network" "primary" {
location = azurerm_resource_group.primary.location
}

resource "azurerm_virtual_network" "secondary" {
name = "network2"
resource_group_name = azurerm_resource_group.secondary.name
address_space = ["192.168.2.0/24"]
location = azurerm_resource_group.secondary.location
}

resource "azurerm_subnet" "primary" {
name = "network1-subnet"
resource_group_name = azurerm_resource_group.primary.name
virtual_network_name = azurerm_virtual_network.primary.name
address_prefixes = ["192.168.1.0/24"]
}

resource "azurerm_subnet" "secondary" {
name = "network2-subnet"
resource_group_name = azurerm_resource_group.secondary.name
virtual_network_name = azurerm_virtual_network.secondary.name
address_prefixes = ["192.168.2.0/24"]
}

resource "azurerm_public_ip" "primary" {
name = "vm-public-ip-primary"
allocation_method = "Static"
location = azurerm_resource_group.primary.location
resource_group_name = azurerm_resource_group.primary.name
sku = "Basic"
}

resource "azurerm_public_ip" "secondary" {
name = "vm-public-ip-secondary"
allocation_method = "Static"
location = azurerm_resource_group.secondary.location
resource_group_name = azurerm_resource_group.secondary.name
sku = "Basic"
}

resource "azurerm_network_interface" "vm" {
name = "vm-nic"
location = azurerm_resource_group.primary.location
Expand All @@ -140,6 +170,7 @@ resource "azurerm_network_interface" "vm" {
name = "vm"
subnet_id = azurerm_subnet.primary.id
private_ip_address_allocation = "Dynamic"
public_ip_address_id = azurerm_public_ip.primary.id
}
}

Expand All @@ -163,6 +194,12 @@ resource "azurerm_site_recovery_replicated_vm" "vm-replication" {
target_disk_type = "Premium_LRS"
target_replica_disk_type = "Premium_LRS"
}

network_interface {
source_network_interface_id = azurerm_network_interface.vm.id
target_subnet_name = "network2-subnet"
recovery_public_ip_address_id = azurerm_public_ip.secondary.id
}
}
```

Expand Down Expand Up @@ -220,6 +257,8 @@ A `network_interface` block supports the following:

* `target_subnet_name` - (Optional) Name of the subnet to to use when a failover is done.

* `recovery_public_ip_address_id` - (Optional) Id of the public IP object to use when a failover is done.

## Attributes Reference

In addition to the arguments above, the following attributes are exported:
Expand Down