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

Update private_dns_zone_virtual_network_link_resource.go #8617

Merged
merged 3 commits into from
Oct 29, 2020
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 @@ -10,7 +10,9 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/helper/validation"

"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/suppress"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/tags"
Expand All @@ -37,10 +39,11 @@ func resourceArmPrivateDnsZoneVirtualNetworkLink() *schema.Resource {

Schema: map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
ValidateFunc: validation.StringIsNotEmpty,
Type: schema.TypeString,
Required: true,
ForceNew: true,
// TODO: make this case sensitive once the API's fixed https://github.com/Azure/azure-rest-api-specs/issues/10933
DiffSuppressFunc: suppress.CaseDifference,
},

"private_dns_zone_name": {
Expand All @@ -63,6 +66,7 @@ func resourceArmPrivateDnsZoneVirtualNetworkLink() *schema.Resource {
Default: false,
},

// TODO: make this case sensitive once the API's fixed https://github.com/Azure/azure-rest-api-specs/issues/10933
"resource_group_name": azure.SchemaResourceGroupNameDiffSuppress(),

"tags": tags.Schema(),
Expand All @@ -85,7 +89,7 @@ func resourceArmPrivateDnsZoneVirtualNetworkLinkCreateUpdate(d *schema.ResourceD
existing, err := client.Get(ctx, resGroup, dnsZoneName, name)
if err != nil {
if !utils.ResponseWasNotFound(existing.Response) {
return fmt.Errorf("error checking for presence of existing Private DNS Zone Virtual network link %q (Resource Group %q): %s", name, resGroup, err)
return fmt.Errorf("checking for presence of existing Virtual Network Link %q (Private DNS Zone %q / Resource Group %q): %s", name, dnsZoneName, resGroup, err)
}
}

Expand Down Expand Up @@ -113,20 +117,20 @@ func resourceArmPrivateDnsZoneVirtualNetworkLinkCreateUpdate(d *schema.ResourceD

future, err := client.CreateOrUpdate(ctx, resGroup, dnsZoneName, name, parameters, etag, ifNoneMatch)
if err != nil {
return fmt.Errorf("error creating/updating Private DNS Zone Virtual network link %q (Resource Group %q): %s", name, resGroup, err)
return fmt.Errorf("creating/updating Virtual Network Link %q (Private DNS Zone %q / Resource Group %q): %s", name, dnsZoneName, resGroup, err)
}

if err = future.WaitForCompletionRef(ctx, client.Client); err != nil {
return fmt.Errorf("error waiting for Private DNS Zone Virtual network link %q to become available: %+v", name, err)
return fmt.Errorf("waiting for Private DNS Zone Virtual Network Link %q to become available: %+v", name, err)
}

resp, err := client.Get(ctx, resGroup, dnsZoneName, name)
if err != nil {
return fmt.Errorf("error retrieving Private DNS Zone Virtual network link %q (Resource Group %q): %s", name, resGroup, err)
return fmt.Errorf("retrieving Virtual Network Link %q (Private DNS Zone %q / Resource Group %q): %s", name, dnsZoneName, resGroup, err)
}

if resp.ID == nil {
return fmt.Errorf("cannot read Private DNS Zone Virtual network link %q (Resource Group %q) ID", name, resGroup)
return fmt.Errorf("cannot read Virtual Network Link %q (Private DNS Zone %q / Resource Group %q) ID", name, dnsZoneName, resGroup)
}

d.SetId(*resp.ID)
Expand Down Expand Up @@ -154,7 +158,7 @@ func resourceArmPrivateDnsZoneVirtualNetworkLinkRead(d *schema.ResourceData, met
d.SetId("")
return nil
}
return fmt.Errorf("error reading Private DNS Zone Virtual network link %q (Resource Group %q): %+v", name, resGroup, err)
return fmt.Errorf("reading Virtual Network Link %q (Private DNS Zone %q / Resource Group %q): %+v", name, dnsZoneName, resGroup, err)
}

d.Set("name", name)
Expand Down Expand Up @@ -191,7 +195,7 @@ func resourceArmPrivateDnsZoneVirtualNetworkLinkDelete(d *schema.ResourceData, m
if response.WasNotFound(future.Response()) {
return nil
}
return fmt.Errorf("error deleting Virtual Network Link %q (Private DNS Zone %q / Resource Group %q): %+v", name, dnsZoneName, resGroup, err)
return fmt.Errorf("deleting Virtual Network Link %q (Private DNS Zone %q / Resource Group %q): %+v", name, dnsZoneName, resGroup, err)
}

// whilst the Delete above returns a Future, the Azure API's broken such that even though it's marked as "gone"
Expand Down Expand Up @@ -222,7 +226,7 @@ func resourceArmPrivateDnsZoneVirtualNetworkLinkDelete(d *schema.ResourceData, m
}

if _, err := stateConf.WaitForState(); err != nil {
return fmt.Errorf("error waiting for deletion of Virtual Network Link %q (Private DNS Zone %q / Resource Group %q): %+v", name, dnsZoneName, resGroup, err)
return fmt.Errorf("waiting for deletion of Virtual Network Link %q (Private DNS Zone %q / Resource Group %q): %+v", name, dnsZoneName, resGroup, err)
}

return nil
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,14 +159,14 @@ resource "azurerm_virtual_network" "test" {

resource "azurerm_private_dns_zone" "test" {
name = "acctestzone%d.com"
resource_group_name = "${azurerm_resource_group.test.name}"
resource_group_name = azurerm_resource_group.test.name
}

resource "azurerm_private_dns_zone_virtual_network_link" "test" {
name = "acctest%d"
private_dns_zone_name = "${azurerm_private_dns_zone.test.name}"
virtual_network_id = "${azurerm_virtual_network.test.id}"
resource_group_name = "${azurerm_resource_group.test.name}"
name = "acctestVnetZone%d.com"
private_dns_zone_name = azurerm_private_dns_zone.test.name
virtual_network_id = azurerm_virtual_network.test.id
resource_group_name = azurerm_resource_group.test.name
}

`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger)
Expand Down Expand Up @@ -215,10 +215,10 @@ resource "azurerm_private_dns_zone" "test" {
}

resource "azurerm_private_dns_zone_virtual_network_link" "test" {
name = "acctest%d"
private_dns_zone_name = "${azurerm_private_dns_zone.test.name}"
virtual_network_id = "${azurerm_virtual_network.test.id}"
resource_group_name = "${azurerm_resource_group.test.name}"
name = "acctestVnetZone%d.com"
private_dns_zone_name = azurerm_private_dns_zone.test.name
virtual_network_id = azurerm_virtual_network.test.id
resource_group_name = azurerm_resource_group.test.name

tags = {
environment = "Production"
Expand Down Expand Up @@ -257,10 +257,10 @@ resource "azurerm_private_dns_zone" "test" {
}

resource "azurerm_private_dns_zone_virtual_network_link" "test" {
name = "acctestzone%d.com"
private_dns_zone_name = "${azurerm_private_dns_zone.test.name}"
virtual_network_id = "${azurerm_virtual_network.test.id}"
resource_group_name = "${azurerm_resource_group.test.name}"
name = "acctestVnetZone%d.com"
private_dns_zone_name = azurerm_private_dns_zone.test.name
virtual_network_id = azurerm_virtual_network.test.id
resource_group_name = azurerm_resource_group.test.name

tags = {
environment = "staging"
Expand Down