Skip to content

Commit

Permalink
App Service / App Service Slot / Function Apps - support for HTTPS On…
Browse files Browse the repository at this point in the history
…ly (#1080)

* `azurerm_app_service` - support for `https_only`

* `d/app_service_plan`: support for https_only

* `r/app_service_slot`: support for `https_only`

* `r/function_app`: support for https_only

* ForceNew-ing the fields to work around API bugs
  • Loading branch information
tombuildsstuff authored Apr 6, 2018
1 parent 1a6bf69 commit 97ddd5b
Show file tree
Hide file tree
Showing 11 changed files with 216 additions and 1 deletion.
6 changes: 6 additions & 0 deletions azurerm/data_source_app_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,11 @@ func dataSourceArmAppService() *schema.Resource {
Computed: true,
},

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

"enabled": {
Type: schema.TypeBool,
Computed: true,
Expand Down Expand Up @@ -259,6 +264,7 @@ func dataSourceArmAppServiceRead(d *schema.ResourceData, meta interface{}) error
d.Set("app_service_plan_id", props.ServerFarmID)
d.Set("client_affinity_enabled", props.ClientAffinityEnabled)
d.Set("enabled", props.Enabled)
d.Set("https_only", props.HTTPSOnly)
d.Set("default_site_hostname", props.DefaultHostName)
d.Set("outbound_ip_addresses", props.OutboundIPAddresses)
}
Expand Down
13 changes: 13 additions & 0 deletions azurerm/resource_arm_app_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,16 @@ func resourceArmAppService() *schema.Resource {
Computed: true,
},

"https_only": {
Type: schema.TypeBool,
Optional: true,
Default: false,

// TODO: (tombuildsstuff) support Update once the API is fixed:
// https://github.com/Azure/azure-rest-api-specs/issues/1697
ForceNew: true,
},

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

siteConfig := expandAppServiceSiteConfig(d)
Expand All @@ -320,6 +331,7 @@ func resourceArmAppServiceCreate(d *schema.ResourceData, meta interface{}) error
SiteProperties: &web.SiteProperties{
ServerFarmID: utils.String(appServicePlanId),
Enabled: utils.Bool(enabled),
HTTPSOnly: utils.Bool(httpsOnly),
SiteConfig: &siteConfig,
},
}
Expand Down Expand Up @@ -487,6 +499,7 @@ func resourceArmAppServiceRead(d *schema.ResourceData, meta interface{}) error {
d.Set("app_service_plan_id", props.ServerFarmID)
d.Set("client_affinity_enabled", props.ClientAffinityEnabled)
d.Set("enabled", props.Enabled)
d.Set("https_only", props.HTTPSOnly)
d.Set("default_site_hostname", props.DefaultHostName)
d.Set("outbound_ip_addresses", props.OutboundIPAddresses)
}
Expand Down
13 changes: 13 additions & 0 deletions azurerm/resource_arm_app_service_slot.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,16 @@ func resourceArmAppServiceSlot() *schema.Resource {
ForceNew: true,
},

"https_only": {
Type: schema.TypeBool,
Optional: true,
Default: false,

// TODO: (tombuildsstuff) support Update once the API is fixed:
// https://github.com/Azure/azure-rest-api-specs/issues/1697
ForceNew: true,
},

"enabled": {
Type: schema.TypeBool,
Optional: true,
Expand Down Expand Up @@ -265,6 +275,7 @@ func resourceArmAppServiceSlotCreate(d *schema.ResourceData, meta interface{}) e
appServiceName := d.Get("app_service_name").(string)
appServicePlanId := d.Get("app_service_plan_id").(string)
enabled := d.Get("enabled").(bool)
httpsOnly := d.Get("https_only").(bool)
tags := d.Get("tags").(map[string]interface{})

siteConfig := expandAppServiceSiteConfig(d)
Expand All @@ -275,6 +286,7 @@ func resourceArmAppServiceSlotCreate(d *schema.ResourceData, meta interface{}) e
SiteProperties: &web.SiteProperties{
ServerFarmID: utils.String(appServicePlanId),
Enabled: utils.Bool(enabled),
HTTPSOnly: utils.Bool(httpsOnly),
SiteConfig: &siteConfig,
},
}
Expand Down Expand Up @@ -426,6 +438,7 @@ func resourceArmAppServiceSlotRead(d *schema.ResourceData, meta interface{}) err
d.Set("app_service_plan_id", props.ServerFarmID)
d.Set("client_affinity_enabled", props.ClientAffinityEnabled)
d.Set("enabled", props.Enabled)
d.Set("https_only", props.HTTPSOnly)
d.Set("default_site_hostname", props.DefaultHostName)
}

Expand Down
57 changes: 57 additions & 0 deletions azurerm/resource_arm_app_service_slot_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,27 @@ func TestAccAzureRMAppServiceSlot_enabled(t *testing.T) {
})
}

func TestAccAzureRMAppServiceSlot_httpsOnly(t *testing.T) {
resourceName := "azurerm_app_service_slot.test"
ri := acctest.RandInt()
config := testAccAzureRMAppServiceSlot_httpsOnly(ri, testLocation())

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testCheckAzureRMAppServiceSlotDestroy,
Steps: []resource.TestStep{
{
Config: config,
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMAppServiceSlotExists(resourceName),
resource.TestCheckResourceAttr(resourceName, "https_only", "true"),
),
},
},
})
}

func TestAccAzureRMAppServiceSlot_localMySql(t *testing.T) {
resourceName := "azurerm_app_service_slot.test"
ri := acctest.RandInt()
Expand Down Expand Up @@ -867,6 +888,42 @@ resource "azurerm_app_service_slot" "test" {
`, rInt, location, rInt, rInt, rInt)
}

func testAccAzureRMAppServiceSlot_httpsOnly(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}"
}
resource "azurerm_app_service_slot" "test" {
name = "acctestASSlot-%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}"
app_service_name = "${azurerm_app_service.test.name}"
https_only = true
}
`, rInt, location, rInt, rInt, rInt)
}

func testAccAzureRMAppServiceSlot_localMySql(rInt int, location string) string {
return fmt.Sprintf(`
resource "azurerm_resource_group" "test" {
Expand Down
49 changes: 49 additions & 0 deletions azurerm/resource_arm_app_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,27 @@ func TestAccAzureRMAppService_alwaysOn(t *testing.T) {
})
}

func TestAccAzureRMAppService_httpsOnly(t *testing.T) {
resourceName := "azurerm_app_service.test"
ri := acctest.RandInt()
config := testAccAzureRMAppService_httpsOnly(ri, testLocation())

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testCheckAzureRMAppServiceDestroy,
Steps: []resource.TestStep{
{
Config: config,
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMAppServiceExists(resourceName),
resource.TestCheckResourceAttr(resourceName, "https_only", "true"),
),
},
},
})
}

func TestAccAzureRMAppService_appSettings(t *testing.T) {
resourceName := "azurerm_app_service.test"
ri := acctest.RandInt()
Expand Down Expand Up @@ -829,6 +850,34 @@ resource "azurerm_app_service" "test" {
`, rInt, location, rInt, rInt)
}

func testAccAzureRMAppService_httpsOnly(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}"
https_only = true
}
`, rInt, location, rInt, rInt)
}

func testAccAzureRMAppService_32Bit(rInt int, location string) string {
return fmt.Sprintf(`
resource "azurerm_resource_group" "test" {
Expand Down
10 changes: 10 additions & 0 deletions azurerm/resource_arm_function_app.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,16 @@ func resourceArmFunctionApp() *schema.Resource {
ForceNew: true,
},

"https_only": {
Type: schema.TypeBool,
Optional: true,
Default: false,

// TODO: (tombuildsstuff) support Update once the API is fixed:
// https://github.com/Azure/azure-rest-api-specs/issues/1697
ForceNew: true,
},

"site_config": {
Type: schema.TypeList,
Optional: true,
Expand Down
59 changes: 59 additions & 0 deletions azurerm/resource_arm_function_app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,29 @@ func TestAccAzureRMFunctionApp_3264bit(t *testing.T) {
})
}

func TestAccAzureRMFunctionApp_httpsOnly(t *testing.T) {
resourceName := "azurerm_function_app.test"
ri := acctest.RandInt()
rs := strings.ToLower(acctest.RandString(11))
location := testLocation()
config := testAccAzureRMFunctionApp_httpsOnly(ri, rs, location)

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testCheckAzureRMFunctionAppDestroy,
Steps: []resource.TestStep{
{
Config: config,
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMFunctionAppExists(resourceName),
resource.TestCheckResourceAttr(resourceName, "https_only", "true"),
),
},
},
})
}

func TestAccAzureRMFunctionApp_consumptionPlan(t *testing.T) {
resourceName := "azurerm_function_app.test"
ri := acctest.RandInt()
Expand Down Expand Up @@ -683,6 +706,42 @@ resource "azurerm_function_app" "test" {
`, rInt, location, rString, rInt, rInt)
}

func testAccAzureRMFunctionApp_httpsOnly(rInt int, rString string, location string) string {
return fmt.Sprintf(`
resource "azurerm_resource_group" "test" {
name = "acctestRG-%d"
location = "%s"
}
resource "azurerm_storage_account" "test" {
name = "acctestsa%s"
resource_group_name = "${azurerm_resource_group.test.name}"
location = "${azurerm_resource_group.test.location}"
account_tier = "Standard"
account_replication_type = "LRS"
}
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_function_app" "test" {
name = "acctest-%d-func"
location = "${azurerm_resource_group.test.location}"
resource_group_name = "${azurerm_resource_group.test.name}"
app_service_plan_id = "${azurerm_app_service_plan.test.id}"
storage_connection_string = "${azurerm_storage_account.test.primary_connection_string}"
https_only = true
}
`, rInt, location, rString, rInt, rInt)
}

func testAccAzureRMFunctionApp_consumptionPlan(rInt int, rString string, 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 @@ -45,6 +45,8 @@ output "app_service_id" {

* `enabled` - Is the App Service Enabled?

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

* `site_config` - A `site_config` object 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 @@ -125,6 +125,8 @@ The following arguments are supported:

* `enabled` - (Optional) Is the App Service Enabled? Changing this forces a new resource to be created.

* `https_only` - (Optional) Can the App Service only be accessed via HTTPS? Defaults to `false`. Changing this forces a new resource to be created.

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

* `tags` - (Optional) A mapping of tags to assign to the resource. Changing this forces a new resource to be created.
Expand Down
2 changes: 2 additions & 0 deletions website/docs/r/app_service_slot.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,8 @@ The following arguments are supported:

* `enabled` - (Optional) Is the App Service Slot Enabled? Changing this forces a new resource to be created.

* `https_only` - (Optional) Can the App Service Slot only be accessed via HTTPS? Defaults to `false`. Changing this forces a new resource to be created.

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

* `tags` - (Optional) A mapping of tags to assign to the resource. Changing this forces a new resource to be created.
Expand Down
4 changes: 3 additions & 1 deletion website/docs/r/function_app.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,11 @@ The following arguments are supported:

* `connection_string` - (Optional) An `connection_string` block as defined below.

* `client_affinity_enabled` - (Optional) Should the Function App send session affinity cookies, which route client requests in the same session to the same instance? Changing this forces a new resource to be created.

* `enabled` - (Optional) Is the Function App enabled? Changing this forces a new resource to be created.

* `client_affinity_enabled` - (Optional) Should the Function App send session affinity cookies, which route client requests in the same session to the same instance? Changing this forces a new resource to be created.
* `https_only` - (Optional) Can the Function App only be accessed via HTTPS? Defaults to `false`. Changing this forces a new resource to be created.

* `version` - (Optional) The runtime version associated with the Function App. Possible values are `~1` and `beta`. Defaults to `~1`.

Expand Down

0 comments on commit 97ddd5b

Please sign in to comment.