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

Deprecate azurerm_app_service_plan properties block for top level fields #2442

Merged
merged 5 commits into from
Dec 4, 2018
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
1 change: 1 addition & 0 deletions azurerm/resource_arm_app_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,7 @@ func resourceArmAppServiceRead(d *schema.ResourceData, meta interface{}) error {
if err := d.Set("app_settings", flattenAppServiceAppSettings(appSettingsResp.Properties)); err != nil {
return err
}

if err := d.Set("connection_string", flattenAppServiceConnectionStrings(connectionStringsResp.Properties)); err != nil {
return err
}
Expand Down
91 changes: 73 additions & 18 deletions azurerm/resource_arm_app_service_plan.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (
"log"
"regexp"

"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/suppress"

"github.com/Azure/azure-sdk-for-go/services/web/mgmt/2018-02-01/web"
"github.com/hashicorp/terraform/helper/schema"
"github.com/hashicorp/terraform/helper/validation"
Expand All @@ -17,6 +19,7 @@ func resourceArmAppServicePlan() *schema.Resource {
Read: resourceArmAppServicePlanRead,
Update: resourceArmAppServicePlanCreateUpdate,
Delete: resourceArmAppServicePlanDelete,

Importer: &schema.ResourceImporter{
State: schema.ImportStatePassthrough,
},
Expand Down Expand Up @@ -46,7 +49,7 @@ func resourceArmAppServicePlan() *schema.Resource {
"Linux",
"Windows",
}, true),
DiffSuppressFunc: ignoreCaseDiffSuppressFunc,
DiffSuppressFunc: suppress.CaseDifference,
},

"sku": {
Expand All @@ -73,31 +76,63 @@ func resourceArmAppServicePlan() *schema.Resource {
},

"properties": {
Type: schema.TypeList,
Optional: true,
Computed: true,
MaxItems: 1,
Type: schema.TypeList,
Optional: true,
Computed: true,
MaxItems: 1,
Deprecated: "These properties have been moved to the top level",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"app_service_environment_id": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
Type: schema.TypeString,
Optional: true,
ForceNew: true,
Computed: true,
Deprecated: "This property has been moved to the top level",
ConflictsWith: []string{"app_service_environment_id"},
},

"reserved": {
Type: schema.TypeBool,
Optional: true,
Default: false,
Type: schema.TypeBool,
Optional: true,
Computed: true,
Deprecated: "This property has been moved to the top level",
ConflictsWith: []string{"reserved"},
},

"per_site_scaling": {
Type: schema.TypeBool,
Optional: true,
Default: false,
Type: schema.TypeBool,
Optional: true,
Computed: true,
Deprecated: "This property has been moved to the top level",
ConflictsWith: []string{"per_site_scaling"},
},
},
},
},

"app_service_environment_id": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
Computed: true,
ConflictsWith: []string{"properties.0.app_service_environment_id"},
},

"per_site_scaling": {
Type: schema.TypeBool,
Optional: true,
Computed: true,
ConflictsWith: []string{"properties.0.per_site_scaling"},
},

"reserved": {
Type: schema.TypeBool,
Optional: true,
Computed: true,
ConflictsWith: []string{"properties.0.reserved"},
},

"maximum_number_of_workers": {
Type: schema.TypeInt,
Computed: true,
Expand Down Expand Up @@ -125,19 +160,32 @@ func resourceArmAppServicePlanCreateUpdate(d *schema.ResourceData, meta interfac

appServicePlan := web.AppServicePlan{
Location: &location,
AppServicePlanProperties: properties,
Kind: &kind,
Tags: expandTags(tags),
Sku: &sku,
Tags: expandTags(tags),
AppServicePlanProperties: properties,
}

if v, exists := d.GetOkExists("app_service_environment_id"); exists {
appServicePlan.AppServicePlanProperties.HostingEnvironmentProfile = &web.HostingEnvironmentProfile{
ID: utils.String(v.(string)),
}
}

if v, exists := d.GetOkExists("per_site_scaling"); exists {
appServicePlan.AppServicePlanProperties.PerSiteScaling = utils.Bool(v.(bool))
}

if v, exists := d.GetOkExists("reserved"); exists {
appServicePlan.AppServicePlanProperties.Reserved = utils.Bool(v.(bool))
}

future, err := client.CreateOrUpdate(ctx, resGroup, name, appServicePlan)
if err != nil {
return fmt.Errorf("Error creating/updating App Service Plan %q (Resource Group %q): %+v", name, resGroup, err)
}

err = future.WaitForCompletionRef(ctx, client.Client)
if err != nil {
if err = future.WaitForCompletionRef(ctx, client.Client); err != nil {
return fmt.Errorf("Error waiting for the create/update of App Service Plan %q (Resource Group %q): %+v", name, resGroup, err)
}

Expand Down Expand Up @@ -191,9 +239,16 @@ func resourceArmAppServicePlanRead(d *schema.ResourceData, meta interface{}) err
return fmt.Errorf("Error setting `properties`: %+v", err)
}

if profile := props.HostingEnvironmentProfile; profile != nil {
d.Set("app_service_environment_id", profile.ID)
}

if props.MaximumNumberOfWorkers != nil {
d.Set("maximum_number_of_workers", int(*props.MaximumNumberOfWorkers))
}

d.Set("per_site_scaling", props.PerSiteScaling)
d.Set("reserved", props.Reserved)
}

if err := d.Set("sku", flattenAppServicePlanSku(resp.Sku)); err != nil {
Expand Down
86 changes: 78 additions & 8 deletions azurerm/resource_arm_app_service_plan_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ func TestAccAzureRMAppServicePlan_basicWindows(t *testing.T) {
Config: testAccAzureRMAppServicePlan_basicWindows(ri, testLocation()),
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMAppServicePlanExists(resourceName),
resource.TestCheckResourceAttr(resourceName, "per_site_scaling", "false"),
resource.TestCheckResourceAttr(resourceName, "reserved", "false"),
),
},
{
Expand All @@ -89,6 +91,14 @@ func TestAccAzureRMAppServicePlan_basicLinux(t *testing.T) {
testCheckAzureRMAppServicePlanExists(resourceName),
),
},
{
Config: testAccAzureRMAppServicePlan_basicLinuxNew(ri, testLocation()),
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMAppServicePlanExists(resourceName),
resource.TestCheckResourceAttr(resourceName, "per_site_scaling", "false"),
resource.TestCheckResourceAttr(resourceName, "reserved", "true"),
),
},
{
ResourceName: resourceName,
ImportState: true,
Expand Down Expand Up @@ -150,50 +160,60 @@ func TestAccAzureRMAppServicePlan_premiumWindowsUpdated(t *testing.T) {
resourceName := "azurerm_app_service_plan.test"
ri := acctest.RandInt()
location := testLocation()
config := testAccAzureRMAppServicePlan_premiumWindows(ri, location)
updatedConfig := testAccAzureRMAppServicePlan_premiumWindowsUpdated(ri, location)

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testCheckAzureRMAppServicePlanDestroy,
Steps: []resource.TestStep{
{
Config: config,
Config: testAccAzureRMAppServicePlan_premiumWindows(ri, location),
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMAppServicePlanExists(resourceName),
resource.TestCheckResourceAttr(resourceName, "sku.0.capacity", "1"),
),
},
{
Config: updatedConfig,
Config: testAccAzureRMAppServicePlan_premiumWindowsUpdated(ri, location),
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMAppServicePlanExists(resourceName),
resource.TestCheckResourceAttr(resourceName, "sku.0.capacity", "2"),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
},
},
})
}

func TestAccAzureRMAppServicePlan_completeWindows(t *testing.T) {
resourceName := "azurerm_app_service_plan.test"
ri := acctest.RandInt()
config := testAccAzureRMAppServicePlan_completeWindows(ri, testLocation())

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testCheckAzureRMAppServicePlanDestroy,
Steps: []resource.TestStep{
{
Config: config,
Config: testAccAzureRMAppServicePlan_completeWindows(ri, testLocation()),
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMAppServicePlanExists(resourceName),
resource.TestCheckResourceAttr(resourceName, "properties.0.per_site_scaling", "true"),
resource.TestCheckResourceAttr(resourceName, "properties.0.reserved", "false"),
),
},
{
Config: testAccAzureRMAppServicePlan_completeWindowsNew(ri, testLocation()),
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMAppServicePlanExists(resourceName),
resource.TestCheckResourceAttr(resourceName, "per_site_scaling", "true"),
resource.TestCheckResourceAttr(resourceName, "reserved", "false"),
),
},
{
ResourceName: resourceName,
ImportState: true,
Expand All @@ -206,15 +226,14 @@ func TestAccAzureRMAppServicePlan_completeWindows(t *testing.T) {
func TestAccAzureRMAppServicePlan_consumptionPlan(t *testing.T) {
resourceName := "azurerm_app_service_plan.test"
ri := acctest.RandInt()
config := testAccAzureRMAppServicePlan_consumptionPlan(ri, testLocation())

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testCheckAzureRMAppServicePlanDestroy,
Steps: []resource.TestStep{
{
Config: config,
Config: testAccAzureRMAppServicePlan_consumptionPlan(ri, testLocation()),
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMAppServicePlanExists(resourceName),
resource.TestCheckResourceAttr(resourceName, "sku.0.tier", "Dynamic"),
Expand Down Expand Up @@ -326,6 +345,29 @@ resource "azurerm_app_service_plan" "test" {
`, rInt, location, rInt)
}

func testAccAzureRMAppServicePlan_basicLinuxNew(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}"
kind = "Linux"

sku {
tier = "Basic"
size = "B1"
}

reserved = true
}
`, rInt, location, rInt)
}

func testAccAzureRMAppServicePlan_standardWindows(rInt int, location string) string {
return fmt.Sprintf(`
resource "azurerm_resource_group" "test" {
Expand Down Expand Up @@ -417,6 +459,34 @@ resource "azurerm_app_service_plan" "test" {
`, rInt, location, rInt)
}

func testAccAzureRMAppServicePlan_completeWindowsNew(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}"
kind = "Windows"

sku {
tier = "Standard"
size = "S1"
}

per_site_scaling = true
reserved = false

tags {
environment = "Test"
}
}
`, rInt, location, rInt)
}

func testAccAzureRMAppServicePlan_consumptionPlan(rInt int, location string) string {
return fmt.Sprintf(`
resource "azurerm_resource_group" "test" {
Expand Down
16 changes: 7 additions & 9 deletions website/docs/r/app_service_plan.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,13 @@ The following arguments are supported:

* `sku` - (Required) A `sku` block as documented below.

* `properties` - (Optional) A `properties` block as documented below.
* `app_service_environment_id` - (Optional) The ID of the App Service Environment where the App Service Plan should be located. Changing forces a new resource to be created.

~> **NOTE:** Attaching to an App Service Environment requires the App Service Plan use a `Premium` SKU (when using an ASEv1) and the `Isolated` SKU (for an ASEv2).

* `reserved` - (Optional) Is this App Service Plan `Reserved`. Defaults to `false`.

* `per_site_scaling` - (Optional) Can Apps assigned to this App Service Plan be scaled independently? If set to `false` apps assigned to this plan will scale to all instances of the plan. Defaults to `false`.

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

Expand All @@ -104,15 +110,7 @@ The following arguments are supported:

* `capacity` - (Optional) Specifies the number of workers associated with this App Service Plan.

`properties` supports the following:

* `app_service_environment_id` - (Optional) The ID of the App Service Environment where the App Service Plan should be located. Changing forces a new resource to be created.

~> **NOTE:** Attaching to an App Service Environment requires the App Service Plan use a `Premium` SKU (when using an ASEv1) and the `Isolated` SKU (for an ASEv2).

* `reserved` - (Optional) Is this App Service Plan `Reserved`. Defaults to `false`.

* `per_site_scaling` - (Optional) Can Apps assigned to this App Service Plan be scaled independently? If set to `false` apps assigned to this plan will scale to all instances of the plan. Defaults to `false`.

## Attributes Reference

Expand Down