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

Fixes resource_arm_application_gateway with empty string password #6742

Merged
merged 4 commits into from
May 4, 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 @@ -3209,10 +3209,6 @@ func expandApplicationGatewaySslCertificates(d *schema.ResourceData) (*[]network
// data must be base64 encoded
output.ApplicationGatewaySslCertificatePropertiesFormat.Data = utils.String(utils.Base64EncodeIfNot(data))

if password == "" {
return nil, fmt.Errorf("'password' is required if `data` is specified for the `ssl_certificate` block %q", name)
}

output.ApplicationGatewaySslCertificatePropertiesFormat.Password = utils.String(password)
} else if kvsid != "" {
if password != "" {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -573,6 +573,29 @@ func TestAccAzureRMApplicationGateway_sslCertificate_keyvault(t *testing.T) {
})
}

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

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acceptance.PreCheck(t) },
Providers: acceptance.SupportedProviders,
CheckDestroy: testCheckAzureRMApplicationGatewayDestroy,
Steps: []resource.TestStep{
{
Config: testAccAzureRMApplicationGateway_sslCertificateEmptyPassword(data),
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMApplicationGatewayExists(data.ResourceName),
),
},
// since these are read from the existing state
data.ImportStep(
"ssl_certificate.0.data",
"ssl_certificate.0.password",
),
},
})
}

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

Expand Down Expand Up @@ -3365,6 +3388,85 @@ resource "azurerm_application_gateway" "test" {
`, template, data.RandomInteger)
}

func testAccAzureRMApplicationGateway_sslCertificateEmptyPassword(data acceptance.TestData) string {
template := testAccAzureRMApplicationGateway_template(data)
return fmt.Sprintf(`
%s

# since these variables are re-used - a locals block makes this more maintainable
locals {
backend_address_pool_name = "${azurerm_virtual_network.test.name}-beap"
frontend_port_name = "${azurerm_virtual_network.test.name}-feport"
frontend_ip_configuration_name = "${azurerm_virtual_network.test.name}-feip"
http_setting_name = "${azurerm_virtual_network.test.name}-be-htst"
listener_name = "${azurerm_virtual_network.test.name}-httplstn"
request_routing_rule_name = "${azurerm_virtual_network.test.name}-rqrt"
ssl_certificate_name = "${azurerm_virtual_network.test.name}-ssl3"
}

resource "azurerm_application_gateway" "test" {
name = "acctestag-%d"
resource_group_name = azurerm_resource_group.test.name
location = azurerm_resource_group.test.location

sku {
name = "Standard_Small"
tier = "Standard"
capacity = 2
}

gateway_ip_configuration {
name = "my-gateway-ip-configuration"
subnet_id = azurerm_subnet.test.id
}

frontend_port {
name = local.frontend_port_name
port = 443
}

frontend_ip_configuration {
name = local.frontend_ip_configuration_name
public_ip_address_id = azurerm_public_ip.test.id
}

backend_address_pool {
name = local.backend_address_pool_name
}

backend_http_settings {
name = local.http_setting_name
cookie_based_affinity = "Disabled"
port = 80
protocol = "Http"
request_timeout = 1
}

http_listener {
name = local.listener_name
frontend_ip_configuration_name = local.frontend_ip_configuration_name
frontend_port_name = local.frontend_port_name
protocol = "Https"
ssl_certificate_name = local.ssl_certificate_name
}

request_routing_rule {
name = local.request_routing_rule_name
rule_type = "Basic"
http_listener_name = local.listener_name
backend_address_pool_name = local.backend_address_pool_name
backend_http_settings_name = local.http_setting_name
}

ssl_certificate {
name = local.ssl_certificate_name
data = filebase64("testdata/application_gateway_test_3.pfx")
password = ""
}
}
`, template, data.RandomInteger)
}

func testAccAzureRMApplicationGateway_webApplicationFirewall(data acceptance.TestData) string {
template := testAccAzureRMApplicationGateway_template(data)
return fmt.Sprintf(`
Expand Down
Binary file not shown.