Skip to content

Commit

Permalink
Merge pull request #6496 from terraform-providers/b/mariadb-ds
Browse files Browse the repository at this point in the history
d/mariadb_server: ensuring the ID is always set
  • Loading branch information
tombuildsstuff authored Apr 16, 2020
2 parents abb2d5b + 1c3ec87 commit 8d1cc22
Show file tree
Hide file tree
Showing 14 changed files with 67 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
)

func TestAccDataSourceAzureRMDatabaseMigrationService_basic(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_database_migration_service", "test")
data := acceptance.BuildTestData(t, "data.azurerm_database_migration_service", "test")

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acceptance.PreCheck(t) },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
)

func TestAccAzureRMDataFactoryDataSource_basic(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_data_factory", "test")
data := acceptance.BuildTestData(t, "data.azurerm_data_factory", "test")

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acceptance.PreCheck(t) },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,16 @@ func dataSourceEventHubNamespaceAuthorizationRuleRead(d *schema.ResourceData, me
resp, err := client.GetAuthorizationRule(ctx, resourceGroup, namespaceName, name)
if err != nil {
if utils.ResponseWasNotFound(resp.Response) {
return fmt.Errorf("Error: Azure EventHub Authorization Rule %q (Resource Group %q / Namespace Name %q) was not found", name, resourceGroup, namespaceName)
return fmt.Errorf("EventHub Authorization Rule %q (Resource Group %q / Namespace Name %q) was not found", name, resourceGroup, namespaceName)
}
return fmt.Errorf("Error making Read request on Azure EventHub Authorization Rule %s: %+v", name, err)
return fmt.Errorf("retrieving EventHub Authorization Rule %q (Resource Group %q): %+v", name, resourceGroup, err)
}

if resp.ID == nil || *resp.ID == "" {
return fmt.Errorf("retrieving EventHub Authorization Rule %q (Resource Group %q): `id` was nil", name, resourceGroup)
}
d.SetId(*resp.ID)

d.Set("name", name)
d.Set("namespace_name", namespaceName)
d.Set("resource_group_name", resourceGroup)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@ func TestAccDataSourceAzureRMEventHubNamespaceAuthorizationRule_basic(t *testing
Steps: []resource.TestStep{
{
Config: testAccDataSourceEventHubNamespaceAuthorizationRule_basic(data, true, true, true),
Check: resource.ComposeTestCheckFunc(),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrSet(data.ResourceName, "listen"),
resource.TestCheckResourceAttrSet(data.ResourceName, "manage"),
resource.TestCheckResourceAttrSet(data.ResourceName, "send"),
),
},
},
})
Expand Down
10 changes: 8 additions & 2 deletions azurerm/internal/services/mariadb/data_source_mariadb_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,12 +111,18 @@ func dataSourceMariaDbServerRead(d *schema.ResourceData, meta interface{}) error
resp, err := client.Get(ctx, resourceGroup, name)
if err != nil {
if utils.ResponseWasNotFound(resp.Response) {
return fmt.Errorf("Error: Azure MariaDB Server %q (Resource Group %q) was not found", name, resourceGroup)
return fmt.Errorf("MariaDB Server %q (Resource Group %q) was not found", name, resourceGroup)
}

return fmt.Errorf("Error making Read request on Azure MariaDB Server %s: %+v", name, err)
return fmt.Errorf("retrieving MariaDB Server %q (Resource Group %q): %+v", name, resourceGroup, err)
}

if resp.ID == nil || *resp.ID == "" {
return fmt.Errorf("retrieving MariaDB Server %q (Resource Group %q): `id` was nil", name, resourceGroup)
}

d.SetId(*resp.ID)

d.Set("name", resp.Name)
d.Set("resource_group_name", resourceGroup)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
)

func TestAccDataSourceAzureRMMariaDbServer_basic(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_mariadb_server", "test")
data := acceptance.BuildTestData(t, "data.azurerm_mariadb_server", "test")

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acceptance.PreCheck(t) },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
)

func TestAccDataSourceAzureRMUserAssignedIdentity_basic(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_user_assigned_identity", "test")
data := acceptance.BuildTestData(t, "data.azurerm_user_assigned_identity", "test")

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acceptance.PreCheck(t) },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,27 +51,32 @@ func dataSourceNetworkDDoSProtectionPlanRead(d *schema.ResourceData, meta interf
name := d.Get("name").(string)
resourceGroup := d.Get("resource_group_name").(string)

plan, err := client.Get(ctx, resourceGroup, name)
resp, err := client.Get(ctx, resourceGroup, name)
if err != nil {
if utils.ResponseWasNotFound(plan.Response) {
return fmt.Errorf("Error DDoS Protection Plan %q (Resource Group %q) was not found", name, resourceGroup)
if utils.ResponseWasNotFound(resp.Response) {
return fmt.Errorf("DDoS Protection Plan %q (Resource Group %q) was not found", name, resourceGroup)
}

return fmt.Errorf("Error making Read request on DDoS Protection Plan %q (Resource Group %q): %+v", name, resourceGroup, err)
return fmt.Errorf("retrieving DDoS Protection Plan %q (Resource Group %q): %+v", name, resourceGroup, err)
}

d.Set("name", plan.Name)
if resp.ID == nil || *resp.ID == "" {
return fmt.Errorf("retrieving DDoS Protection Plan %q (Resource Group %q): `id` was nil", name, resourceGroup)
}
d.SetId(*resp.ID)

d.Set("name", resp.Name)
d.Set("resource_group_name", resourceGroup)
if location := plan.Location; location != nil {
if location := resp.Location; location != nil {
d.Set("location", azure.NormalizeLocation(*location))
}

if props := plan.DdosProtectionPlanPropertiesFormat; props != nil {
if props := resp.DdosProtectionPlanPropertiesFormat; props != nil {
vNetIDs := flattenArmNetworkDDoSProtectionPlanVirtualNetworkIDs(props.VirtualNetworks)
if err := d.Set("virtual_network_ids", vNetIDs); err != nil {
return fmt.Errorf("Error setting `virtual_network_ids`: %+v", err)
}
}

return tags.FlattenAndSet(d, plan.Tags)
return tags.FlattenAndSet(d, resp.Tags)
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ func TestAccDataSourceAzureRMNatGateway_basic(t *testing.T) {
Steps: []resource.TestStep{
{
Config: testAccDataSourceNatGateway_basic(data),
Check: resource.ComposeTestCheckFunc(),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrSet(data.ResourceName, "location"),
),
},
},
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
)

func testAccAzureRMNetworkDDoSProtectionPlanDataSource_basic(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_network_ddos_protection_plan", "test")
data := acceptance.BuildTestData(t, "data.azurerm_network_ddos_protection_plan", "test")

resource.Test(t, resource.TestCase{
PreCheck: func() { acceptance.PreCheck(t) },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ func TestAccDataSourceAzureRMPublicIPs_namePrefix(t *testing.T) {
Steps: []resource.TestStep{
{
Config: testAccDataSourceAzureRMPublicIPs_prefix(data),
Check: resource.ComposeTestCheckFunc(),
},
{
Config: testAccDataSourceAzureRMPublicIPs_prefixDataSource(data),
Expand All @@ -44,7 +43,6 @@ func TestAccDataSourceAzureRMPublicIPs_assigned(t *testing.T) {
Steps: []resource.TestStep{
{
Config: testAccDataSourceAzureRMPublicIPs_attached(data),
Check: resource.ComposeTestCheckFunc(),
},
{
Config: testAccDataSourceAzureRMPublicIPs_attachedDataSource(data),
Expand Down Expand Up @@ -72,7 +70,6 @@ func TestAccDataSourceAzureRMPublicIPs_allocationType(t *testing.T) {
Steps: []resource.TestStep{
{
Config: testAccDataSourceAzureRMPublicIPs_allocationType(data),
Check: resource.ComposeTestCheckFunc(),
},
{
Config: testAccDataSourceAzureRMPublicIPs_allocationTypeDataSources(data),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
)

func TestAccAzureRMDataSourceVirtualNetworkGatewayConnection_sitetosite(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_virtual_network_gateway_connection", "test")
data := acceptance.BuildTestData(t, "data.azurerm_virtual_network_gateway_connection", "test")
sharedKey := "4-v3ry-53cr37-1p53c-5h4r3d-k3y"

resource.ParallelTest(t, resource.TestCase{
Expand All @@ -32,8 +32,8 @@ func TestAccAzureRMDataSourceVirtualNetworkGatewayConnection_sitetosite(t *testi
}

func TestAccAzureRMDataSourceVirtualNetworkGatewayConnection_vnettovnet(t *testing.T) {
data1 := acceptance.BuildTestData(t, "azurerm_virtual_network_gateway_connection", "test_1")
data2 := acceptance.BuildTestData(t, "azurerm_virtual_network_gateway_connection", "test_2")
data1 := acceptance.BuildTestData(t, "data.azurerm_virtual_network_gateway_connection", "test_1")
data2 := acceptance.BuildTestData(t, "data.azurerm_virtual_network_gateway_connection", "test_2")

sharedKey := "4-v3ry-53cr37-1p53c-5h4r3d-k3y"

Expand All @@ -58,7 +58,7 @@ func TestAccAzureRMDataSourceVirtualNetworkGatewayConnection_vnettovnet(t *testi
}

func TestAccAzureRMDataSourceVirtualNetworkGatewayConnection_ipsecpolicy(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_virtual_network_gateway_connection", "test")
data := acceptance.BuildTestData(t, "data.azurerm_virtual_network_gateway_connection", "test")
sharedKey := "4-v3ry-53cr37-1p53c-5h4r3d-k3y"

resource.ParallelTest(t, resource.TestCase{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ func TestAccAzureRMBackupProtectedFileShare_basic(t *testing.T) {
),
},
data.ImportStep(),
{ // vault cannot be deleted unless we unregister all backups
{
// vault cannot be deleted unless we unregister all backups
Config: testAccAzureRMBackupProtectedFileShare_base(data),
Check: resource.ComposeTestCheckFunc(),
},
},
})
Expand All @@ -59,9 +59,9 @@ func TestAccAzureRMBackupProtectedFileShare_requiresImport(t *testing.T) {
),
},
data.RequiresImportErrorStep(testAccAzureRMBackupProtectedFileShare_requiresImport),
{ // vault cannot be deleted unless we unregister all backups
{
// vault cannot be deleted unless we unregister all backups
Config: testAccAzureRMBackupProtectedFileShare_base(data),
Check: resource.ComposeTestCheckFunc(),
},
},
})
Expand All @@ -78,22 +78,24 @@ func TestAccAzureRMBackupProtectedFileShare_updateBackupPolicyId(t *testing.T) {
Providers: acceptance.SupportedProviders,
CheckDestroy: testCheckAzureRMBackupProtectedFileShareDestroy,
Steps: []resource.TestStep{
{ // Create resources and link first backup policy id
{
// Create resources and link first backup policy id
Config: testAccAzureRMBackupProtectedFileShare_basic(data),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrPair(data.ResourceName, "backup_policy_id", fBackupPolicyResourceName, "id"),
),
},
{ // Modify backup policy id to the second one
{
// Modify backup policy id to the second one
// Set Destroy false to prevent error from cleaning up dangling resource
Config: testAccAzureRMBackupProtectedFileShare_updatePolicy(data),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrPair(data.ResourceName, "backup_policy_id", sBackupPolicyResourceName, "id"),
),
},
{ // Remove protected items first before the associated policies are deleted
{
// Remove protected items first before the associated policies are deleted
Config: testAccAzureRMBackupProtectedFileShare_base(data),
Check: resource.ComposeTestCheckFunc(),
},
},
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ func TestAccAzureRMBackupProtectedVm_basic(t *testing.T) {
),
},
data.ImportStep(),
{ // vault cannot be deleted unless we unregister all backups
{
// vault cannot be deleted unless we unregister all backups
Config: testAccAzureRMBackupProtectedVm_base(data),
Check: resource.ComposeTestCheckFunc(),
},
},
})
Expand All @@ -58,9 +58,9 @@ func TestAccAzureRMBackupProtectedVm_requiresImport(t *testing.T) {
),
},
data.RequiresImportErrorStep(testAccAzureRMBackupProtectedVm_requiresImport),
{ // vault cannot be deleted unless we unregister all backups
{
// vault cannot be deleted unless we unregister all backups
Config: testAccAzureRMBackupProtectedVm_base(data),
Check: resource.ComposeTestCheckFunc(),
},
},
})
Expand All @@ -82,9 +82,9 @@ func TestAccAzureRMBackupProtectedVm_separateResourceGroups(t *testing.T) {
),
},
data.ImportStep(),
{ // vault cannot be deleted unless we unregister all backups
{
// vault cannot be deleted unless we unregister all backups
Config: testAccAzureRMBackupProtectedVm_additionalVault(data),
Check: resource.ComposeTestCheckFunc(),
},
},
})
Expand Down Expand Up @@ -116,22 +116,22 @@ func TestAccAzureRMBackupProtectedVm_updateBackupPolicyId(t *testing.T) {
resource.TestCheckResourceAttrPair(data.ResourceName, "backup_policy_id", sBackupPolicyResourceName, "id"),
),
},
{ // Remove backup policy link
{
// Remove backup policy link
// Backup policy link will need to be removed first so the VM's backup policy subsequently reverts to Default
// Azure API is quite sensitive, adding the step to control resource cleanup order
ResourceName: fBackupPolicyResourceName,
Config: testAccAzureRMBackupProtectedVm_withVM(data),
Check: resource.ComposeTestCheckFunc(),
},
{ // Then VM can be removed
{
// Then VM can be removed
ResourceName: virtualMachine,
Config: testAccAzureRMBackupProtectedVm_withSecondPolicy(data),
Check: resource.ComposeTestCheckFunc(),
},
{ // Remove backup policies and vault
{
// Remove backup policies and vault
ResourceName: data.ResourceName,
Config: testAccAzureRMBackupProtectedVm_basePolicyTest(data),
Check: resource.ComposeTestCheckFunc(),
},
},
})
Expand Down

0 comments on commit 8d1cc22

Please sign in to comment.