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

Bug Fix: azurerm_api_management_backend - a nil certificates object is sent to the api instead of an empty one #3931

Merged
merged 1 commit into from
Jul 26, 2019
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
5 changes: 4 additions & 1 deletion azurerm/resource_arm_api_management_backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,10 @@ func expandApiManagementBackendCredentials(input []interface{}) *apimanagement.B
contract.Authorization = authorization
}
if certificate := v["certificate"]; certificate != nil {
contract.Certificate = utils.ExpandStringSlice(certificate.([]interface{}))
certificates := utils.ExpandStringSlice(certificate.([]interface{}))
if certificates != nil && len(*certificates) > 0 {
contract.Certificate = certificates
}
}
if headerRaw := v["header"]; headerRaw != nil {
header := expandApiManagementBackendCredentialsObject(headerRaw.(map[string]interface{}))
Expand Down
66 changes: 66 additions & 0 deletions azurerm/resource_arm_api_management_backend_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,31 @@ func TestAccAzureRMApiManagementBackend_allProperties(t *testing.T) {
})
}

func TestAccAzureRMApiManagementBackend_credentialsNoCertificate(t *testing.T) {
resourceName := "azurerm_api_management_backend.test"
ri := tf.AccRandTimeInt()
location := testLocation()

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testCheckAzureRMApiManagementBackendDestroy,
Steps: []resource.TestStep{
{
Config: testAccAzureRMApiManagementBackend_credentialsNoCertificate(ri, location),
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMApiManagementBackendExists(resourceName),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
},
},
})
}

func TestAccAzureRMApiManagementBackend_update(t *testing.T) {
resourceName := "azurerm_api_management_backend.test"
ri := tf.AccRandTimeInt()
Expand Down Expand Up @@ -465,3 +490,44 @@ resource "azurerm_api_management" "test" {
}
`, rInt, testName, location, rInt, testName)
}

func testAccAzureRMApiManagementBackend_credentialsNoCertificate(rInt int, location string) string {
template := testAccAzureRMApiManagementBackend_template(rInt, "all", location)
return fmt.Sprintf(`
%s

resource "azurerm_api_management_backend" "test" {
name = "acctestapi-%d"
resource_group_name = "${azurerm_resource_group.test.name}"
api_management_name = "${azurerm_api_management.test.name}"
protocol = "http"
url = "https://acctest"
description = "description"
resource_id = "https://resourceid"
title = "title"
credentials {
authorization {
parameter = "parameter"
scheme = "scheme"
}
header = {
header1 = "header1value1,header1value2"
header2 = "header2value1,header2value2"
}
query = {
query1 = "query1value1,query1value2"
query2 = "query2value1,query2value2"
}
}
proxy {
url = "http://192.168.1.1:8080"
username = "username"
password = "password"
}
tls {
validate_certificate_chain = false
validate_certificate_name = true
}
}
`, template, rInt)
}