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

azurerm_app_service: Allow to turn off/on "Incoming client certificates" #2765

Merged
merged 3 commits into from
Jan 29, 2019
Merged
Show file tree
Hide file tree
Changes from 2 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
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
27 changes: 19 additions & 8 deletions azurerm/resource_arm_app_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,12 @@ func resourceArmAppService() *schema.Resource {
Default: false,
},

"client_cert_enabled": {
Type: schema.TypeBool,
Optional: true,
Default: false,
maniSbindra marked this conversation as resolved.
Show resolved Hide resolved
},

"enabled": {
Type: schema.TypeBool,
Optional: true,
Expand Down Expand Up @@ -225,6 +231,7 @@ func resourceArmAppServiceCreate(d *schema.ResourceData, meta interface{}) error
appServicePlanId := d.Get("app_service_plan_id").(string)
enabled := d.Get("enabled").(bool)
httpsOnly := d.Get("https_only").(bool)
clientCertEnabled := d.Get("client_cert_enabled").(bool)
tags := d.Get("tags").(map[string]interface{})

siteConfig := azure.ExpandAppServiceSiteConfig(d.Get("site_config"))
Expand All @@ -233,10 +240,11 @@ func resourceArmAppServiceCreate(d *schema.ResourceData, meta interface{}) error
Location: &location,
Tags: expandTags(tags),
SiteProperties: &web.SiteProperties{
ServerFarmID: utils.String(appServicePlanId),
Enabled: utils.Bool(enabled),
HTTPSOnly: utils.Bool(httpsOnly),
SiteConfig: &siteConfig,
ServerFarmID: utils.String(appServicePlanId),
Enabled: utils.Bool(enabled),
HTTPSOnly: utils.Bool(httpsOnly),
ClientCertEnabled: utils.Bool(clientCertEnabled),
maniSbindra marked this conversation as resolved.
Show resolved Hide resolved
SiteConfig: &siteConfig,
},
}

Expand Down Expand Up @@ -289,17 +297,19 @@ func resourceArmAppServiceUpdate(d *schema.ResourceData, meta interface{}) error
appServicePlanId := d.Get("app_service_plan_id").(string)
enabled := d.Get("enabled").(bool)
httpsOnly := d.Get("https_only").(bool)
clientCertEnabled := d.Get("client_cert_enabled").(bool)
tags := d.Get("tags").(map[string]interface{})

siteConfig := azure.ExpandAppServiceSiteConfig(d.Get("site_config"))
siteEnvelope := web.Site{
Location: &location,
Tags: expandTags(tags),
SiteProperties: &web.SiteProperties{
ServerFarmID: utils.String(appServicePlanId),
Enabled: utils.Bool(enabled),
HTTPSOnly: utils.Bool(httpsOnly),
SiteConfig: &siteConfig,
ServerFarmID: utils.String(appServicePlanId),
Enabled: utils.Bool(enabled),
HTTPSOnly: utils.Bool(httpsOnly),
ClientCertEnabled: utils.Bool(clientCertEnabled),
maniSbindra marked this conversation as resolved.
Show resolved Hide resolved
SiteConfig: &siteConfig,
},
}

Expand Down Expand Up @@ -453,6 +463,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
54 changes: 54 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,32 @@ func TestAccAzureRMAppService_httpsOnly(t *testing.T) {
})
}

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

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testCheckAzureRMAppServiceDestroy,
Steps: []resource.TestStep{
{
Config: config,
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMAppServiceExists(resourceName),
resource.TestCheckResourceAttr(resourceName, "client_cert_enabled", "true"),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
},
},
maniSbindra marked this conversation as resolved.
Show resolved Hide resolved
})
}

func TestAccAzureRMAppService_appSettings(t *testing.T) {
resourceName := "azurerm_app_service.test"
ri := tf.AccRandTimeInt()
Expand Down Expand Up @@ -1397,6 +1423,34 @@ 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
maniSbindra marked this conversation as resolved.
Show resolved Hide resolved
}
`, 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