Skip to content

Commit

Permalink
Merge pull request #9364 from ptv-logistics/master
Browse files Browse the repository at this point in the history
try to retrieve apiVersion for all sub-resources
  • Loading branch information
tombuildsstuff committed Nov 18, 2020
2 parents 9fa2a69 + 47c80f5 commit af613fe
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ func findApiVersionForResourceType(resourceType string, availableResourceTypes [
continue
}

if *item.ResourceType == resourceType {
if strings.HasPrefix(resourceType, *item.ResourceType) {
apiVersions := *item.APIVersions
apiVersion := apiVersions[0]
return &apiVersion
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,32 @@ func TestAccResourceGroupTemplateDeployment_multipleNestedItems(t *testing.T) {
})
}

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

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acceptance.PreCheck(t) },
Providers: acceptance.SupportedProviders,
CheckDestroy: testCheckResourceGroupTemplateDeploymentDestroyed,
Steps: []resource.TestStep{
{
Config: resourceGroupTemplateDeployment_childItemsConfig(data),
Check: resource.ComposeTestCheckFunc(
testCheckResourceGroupTemplateDeploymentExists(data.ResourceName),
),
},
data.ImportStep(),
{
Config: resourceGroupTemplateDeployment_childItemsConfig(data),
Check: resource.ComposeTestCheckFunc(
testCheckResourceGroupTemplateDeploymentExists(data.ResourceName),
),
},
data.ImportStep(),
},
})
}

func testCheckResourceGroupTemplateDeploymentExists(resourceName string) resource.TestCheckFunc {
return func(s *terraform.State) error {
client := acceptance.AzureProvider.Meta().(*clients.Client).Resource.DeploymentsClient
Expand Down Expand Up @@ -550,3 +576,49 @@ TEMPLATE
}
`, data.RandomInteger, data.Locations.Primary, value)
}

func resourceGroupTemplateDeployment_childItemsConfig(data acceptance.TestData) string {
return fmt.Sprintf(`
provider "azurerm" {
features {}
}
resource "azurerm_resource_group" "test" {
name = "acctestrg-%d"
location = %q
}
resource "azurerm_route_table" "test" {
name = "acctestrt%d"
location = azurerm_resource_group.test.location
resource_group_name = azurerm_resource_group.test.name
}
resource "azurerm_resource_group_template_deployment" "test" {
name = "acctest"
resource_group_name = azurerm_resource_group.test.name
deployment_mode = "Incremental"
template_content = <<TEMPLATE
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {},
"variables": {},
"resources": [
{
"type": "Microsoft.Network/routeTables/routes",
"apiVersion": "2020-06-01",
"name": "${azurerm_route_table.test.name}/child-route",
"location": "[resourceGroup().location]",
"properties": {
"addressPrefix": "10.2.0.0/16",
"nextHopType": "none"
}
}
]
}
TEMPLATE
}
`, data.RandomInteger, data.Locations.Primary, data.RandomInteger)
}

0 comments on commit af613fe

Please sign in to comment.