Skip to content

Commit

Permalink
azurerm_app_service: Allow to turn off/on "Incoming client certificat…
Browse files Browse the repository at this point in the history
…es" (#2765)

The PR has changes to fix #2004 .
  • Loading branch information
maniSbindra authored and katbyte committed Jan 29, 2019
1 parent 29cc137 commit a281281
Show file tree
Hide file tree
Showing 5 changed files with 115 additions and 0 deletions.
6 changes: 6 additions & 0 deletions azurerm/data_source_app_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ func dataSourceArmAppService() *schema.Resource {
Computed: true,
},

"client_cert_enabled": {
Type: schema.TypeBool,
Computed: true,
},

"app_settings": {
Type: schema.TypeMap,
Computed: true,
Expand Down Expand Up @@ -187,6 +192,7 @@ func dataSourceArmAppServiceRead(d *schema.ResourceData, meta interface{}) error
d.Set("client_affinity_enabled", props.ClientAffinityEnabled)
d.Set("enabled", props.Enabled)
d.Set("https_only", props.HTTPSOnly)
d.Set("client_cert_enabled", props.ClientCertEnabled)
d.Set("default_site_hostname", props.DefaultHostName)
d.Set("outbound_ip_addresses", props.OutboundIPAddresses)
d.Set("possible_outbound_ip_addresses", props.PossibleOutboundIPAddresses)
Expand Down
16 changes: 16 additions & 0 deletions azurerm/resource_arm_app_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,11 @@ func resourceArmAppService() *schema.Resource {
Default: false,
},

"client_cert_enabled": {
Type: schema.TypeBool,
Optional: true,
},

"enabled": {
Type: schema.TypeBool,
Optional: true,
Expand Down Expand Up @@ -250,6 +255,11 @@ func resourceArmAppServiceCreate(d *schema.ResourceData, meta interface{}) error
siteEnvelope.SiteProperties.ClientAffinityEnabled = utils.Bool(enabled)
}

if v, ok := d.GetOkExists("client_cert_enabled"); ok {
certEnabled := v.(bool)
siteEnvelope.SiteProperties.ClientCertEnabled = utils.Bool(certEnabled)
}

createFuture, err := client.CreateOrUpdate(ctx, resGroup, name, siteEnvelope)
if err != nil {
return err
Expand Down Expand Up @@ -303,6 +313,11 @@ func resourceArmAppServiceUpdate(d *schema.ResourceData, meta interface{}) error
},
}

if v, ok := d.GetOkExists("client_cert_enabled"); ok {
certEnabled := v.(bool)
siteEnvelope.SiteProperties.ClientCertEnabled = utils.Bool(certEnabled)
}

future, err := client.CreateOrUpdate(ctx, resGroup, name, siteEnvelope)
if err != nil {
return err
Expand Down Expand Up @@ -453,6 +468,7 @@ func resourceArmAppServiceRead(d *schema.ResourceData, meta interface{}) error {
d.Set("client_affinity_enabled", props.ClientAffinityEnabled)
d.Set("enabled", props.Enabled)
d.Set("https_only", props.HTTPSOnly)
d.Set("client_cert_enabled", props.ClientCertEnabled)
d.Set("default_site_hostname", props.DefaultHostName)
d.Set("outbound_ip_addresses", props.OutboundIPAddresses)
d.Set("possible_outbound_ip_addresses", props.PossibleOutboundIPAddresses)
Expand Down
89 changes: 89 additions & 0 deletions azurerm/resource_arm_app_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,40 @@ func TestAccAzureRMAppService_httpsOnly(t *testing.T) {
})
}

func TestAccAzureRMAppService_clientCertEnabled(t *testing.T) {
resourceName := "azurerm_app_service.test"
ri := tf.AccRandTimeInt()
configClientCertEnabled := testAccAzureRMAppService_clientCertEnabled(ri, testLocation())
configClientCertEnabledNotSet := testAccAzureRMAppService_clientCertEnabledNotSet(ri, testLocation())

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testCheckAzureRMAppServiceDestroy,
Steps: []resource.TestStep{
{
Config: configClientCertEnabled,
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMAppServiceExists(resourceName),
resource.TestCheckResourceAttr(resourceName, "client_cert_enabled", "true"),
),
},
{
Config: configClientCertEnabledNotSet,
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMAppServiceExists(resourceName),
resource.TestCheckResourceAttr(resourceName, "client_cert_enabled", "false"),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
},
},
})
}

func TestAccAzureRMAppService_appSettings(t *testing.T) {
resourceName := "azurerm_app_service.test"
ri := tf.AccRandTimeInt()
Expand Down Expand Up @@ -1397,6 +1431,61 @@ resource "azurerm_app_service" "test" {
`, rInt, location, rInt, rInt)
}

func testAccAzureRMAppService_clientCertEnabled(rInt int, location string) string {
return fmt.Sprintf(`
resource "azurerm_resource_group" "test" {
name = "acctestRG-%d"
location = "%s"
}
resource "azurerm_app_service_plan" "test" {
name = "acctestASP-%d"
location = "${azurerm_resource_group.test.location}"
resource_group_name = "${azurerm_resource_group.test.name}"
sku {
tier = "Standard"
size = "S1"
}
}
resource "azurerm_app_service" "test" {
name = "acctestAS-%d"
location = "${azurerm_resource_group.test.location}"
resource_group_name = "${azurerm_resource_group.test.name}"
app_service_plan_id = "${azurerm_app_service_plan.test.id}"
client_cert_enabled = true
}
`, rInt, location, rInt, rInt)
}

func testAccAzureRMAppService_clientCertEnabledNotSet(rInt int, location string) string {
return fmt.Sprintf(`
resource "azurerm_resource_group" "test" {
name = "acctestRG-%d"
location = "%s"
}
resource "azurerm_app_service_plan" "test" {
name = "acctestASP-%d"
location = "${azurerm_resource_group.test.location}"
resource_group_name = "${azurerm_resource_group.test.name}"
sku {
tier = "Standard"
size = "S1"
}
}
resource "azurerm_app_service" "test" {
name = "acctestAS-%d"
location = "${azurerm_resource_group.test.location}"
resource_group_name = "${azurerm_resource_group.test.name}"
app_service_plan_id = "${azurerm_app_service_plan.test.id}"
}
`, rInt, location, rInt, rInt)
}

func testAccAzureRMAppService_32Bit(rInt int, location string) string {
return fmt.Sprintf(`
resource "azurerm_resource_group" "test" {
Expand Down
2 changes: 2 additions & 0 deletions website/docs/d/app_service.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ output "app_service_id" {

* `https_only` - Can the App Service only be accessed via HTTPS?

* `client_cert_enabled` - Does the App Service require client certificates for incoming requests?

* `site_config` - A `site_config` block as defined below.

* `tags` - A mapping of tags to assign to the resource.
Expand Down
2 changes: 2 additions & 0 deletions website/docs/r/app_service.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@ The following arguments are supported:

* `https_only` - (Optional) Can the App Service only be accessed via HTTPS? Defaults to `false`.

* `client_cert_enabled` - (Optional) Does the App Service require client certificates for incoming requests? Defaults to `false`.

* `site_config` - (Optional) A `site_config` block as defined below.

* `tags` - (Optional) A mapping of tags to assign to the resource.
Expand Down

0 comments on commit a281281

Please sign in to comment.