From cf0726f8b50a82472311ff2716b9582e1e4f5c57 Mon Sep 17 00:00:00 2001 From: lstolyarov Date: Sun, 11 Jun 2017 14:15:02 +0100 Subject: [PATCH 01/31] Adding azure app service resource --- azurerm/provider.go | 1 + azurerm/resource_arm_app_service.go | 165 ++++++++++++++++++++++++++++ 2 files changed, 166 insertions(+) create mode 100644 azurerm/resource_arm_app_service.go diff --git a/azurerm/provider.go b/azurerm/provider.go index f06b6e165b25..57f8028db12c 100644 --- a/azurerm/provider.go +++ b/azurerm/provider.go @@ -71,6 +71,7 @@ func Provider() terraform.ResourceProvider { ResourcesMap: map[string]*schema.Resource{ "azurerm_application_insights": resourceArmApplicationInsights(), + "azurerm_app_service": resourceArmAppService(), "azurerm_app_service_plan": resourceArmAppServicePlan(), "azurerm_availability_set": resourceArmAvailabilitySet(), "azurerm_cdn_endpoint": resourceArmCdnEndpoint(), diff --git a/azurerm/resource_arm_app_service.go b/azurerm/resource_arm_app_service.go new file mode 100644 index 000000000000..cbe704ba9b1c --- /dev/null +++ b/azurerm/resource_arm_app_service.go @@ -0,0 +1,165 @@ +package azurerm + +import ( + "fmt" + "log" + "net/http" + + "github.com/Azure/azure-sdk-for-go/arm/web" + "github.com/hashicorp/terraform/helper/schema" +) + +func resourceArmAppService() *schema.Resource { + return &schema.Resource{ + Create: resourceArmAppServiceCreateUpdate, + Read: resourceArmAppServiceRead, + Update: resourceArmAppServiceCreateUpdate, + Delete: resourceArmAppServiceDelete, + + Schema: map[string]*schema.Schema{ + "resource_group_name": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + }, + "name": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + }, + "skip_dns_registration": { + Type: schema.TypeBool, + Optional: true, + Default: true, + }, + "skip_custom_domain_verification": { + Type: schema.TypeBool, + Optional: true, + Default: true, + }, + "force_dns_registration": { + Type: schema.TypeBool, + Optional: true, + Default: false, + }, + "ttl_in_seconds": { + Type: schema.TypeString, + Optional: true, + Default: "", + }, + "app_service_plan_id": { + Type: schema.TypeString, + Optional: true, + }, + "always_on": { + Type: schema.TypeBool, + Optional: true, + }, + "location": locationSchema(), + "tags": tagsSchema(), + }, + } +} + +func resourceArmAppServiceCreateUpdate(d *schema.ResourceData, meta interface{}) error { + client := meta.(*ArmClient) + appClient := client.appsClient + + log.Printf("[INFO] preparing arguments for Azure ARM Web App creation.") + + resGroup := d.Get("resource_group_name").(string) + name := d.Get("name").(string) + location := d.Get("location").(string) + skipDNSRegistration := d.Get("skip_dns_registration").(bool) + skipCustomDomainVerification := d.Get("skip_custom_domain_verification").(bool) + forceDNSRegistration := d.Get("force_dns_registration").(bool) + ttlInSeconds := d.Get("ttl_in_seconds").(string) + tags := d.Get("tags").(map[string]interface{}) + + siteConfig := web.SiteConfig{} + if v, ok := d.GetOk("always_on"); ok { + alwaysOn := v.(bool) + siteConfig.AlwaysOn = &alwaysOn + } + + siteProps := web.SiteProperties{ + SiteConfig: &siteConfig, + } + if v, ok := d.GetOk("app_service_plan_id"); ok { + serverFarmID := v.(string) + siteProps.ServerFarmID = &serverFarmID + } + + siteEnvelope := web.Site{ + Location: &location, + Tags: expandTags(tags), + SiteProperties: &siteProps, + } + + _, error := appClient.CreateOrUpdate(resGroup, name, siteEnvelope, &skipDNSRegistration, &skipCustomDomainVerification, &forceDNSRegistration, ttlInSeconds, make(chan struct{})) + err := <-error + if err != nil { + return err + } + + read, err := appClient.Get(resGroup, name) + if err != nil { + return err + } + if read.ID == nil { + return fmt.Errorf("Cannot read App Service %s (resource group %s) ID", name, resGroup) + } + + d.SetId(*read.ID) + + return resourceArmAppServiceRead(d, meta) +} + +func resourceArmAppServiceRead(d *schema.ResourceData, meta interface{}) error { + appClient := meta.(*ArmClient).appsClient + + id, err := parseAzureResourceID(d.Id()) + if err != nil { + return err + } + + log.Printf("[DEBUG] Reading App Service details %s", id) + + resGroup := id.ResourceGroup + name := id.Path["sites"] + + resp, err := appClient.Get(resGroup, name) + if err != nil { + if resp.StatusCode == http.StatusNotFound { + d.SetId("") + return nil + } + return fmt.Errorf("Error making Read request on AzureRM App Service %s: %s", name, err) + } + + d.Set("name", name) + d.Set("resource_group_name", resGroup) + + return nil +} + +func resourceArmAppServiceDelete(d *schema.ResourceData, meta interface{}) error { + appClient := meta.(*ArmClient).appsClient + + id, err := parseAzureResourceID(d.Id()) + if err != nil { + return err + } + resGroup := id.ResourceGroup + name := id.Path["sites"] + + log.Printf("[DEBUG] Deleting App Service %s: %s", resGroup, name) + + deleteMetrics := true + deleteEmptyServerFarm := true + skipDNSRegistration := true + + _, err = appClient.Delete(resGroup, name, &deleteMetrics, &deleteEmptyServerFarm, &skipDNSRegistration) + + return err +} From ceaf0d77057d4854ca554bbbb0130ab52e9c4e29 Mon Sep 17 00:00:00 2001 From: lstolyarov Date: Sat, 19 Aug 2017 15:47:07 +0100 Subject: [PATCH 02/31] adding importer --- azurerm/resource_arm_app_service.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/azurerm/resource_arm_app_service.go b/azurerm/resource_arm_app_service.go index cbe704ba9b1c..e36a08deefa9 100644 --- a/azurerm/resource_arm_app_service.go +++ b/azurerm/resource_arm_app_service.go @@ -15,6 +15,9 @@ func resourceArmAppService() *schema.Resource { Read: resourceArmAppServiceRead, Update: resourceArmAppServiceCreateUpdate, Delete: resourceArmAppServiceDelete, + Importer: &schema.ResourceImporter{ + State: schema.ImportStatePassthrough, + }, Schema: map[string]*schema.Schema{ "resource_group_name": { From 6f8869b9bb16d879f26c936a10305cade6bb09ad Mon Sep 17 00:00:00 2001 From: lstolyarov Date: Sat, 19 Aug 2017 15:47:33 +0100 Subject: [PATCH 03/31] adding some tests --- azurerm/import_arm_app_service_test.go | 32 +++++++ azurerm/resource_arm_app_service_test.go | 103 +++++++++++++++++++++++ 2 files changed, 135 insertions(+) create mode 100644 azurerm/import_arm_app_service_test.go create mode 100644 azurerm/resource_arm_app_service_test.go diff --git a/azurerm/import_arm_app_service_test.go b/azurerm/import_arm_app_service_test.go new file mode 100644 index 000000000000..2f88ba5fd497 --- /dev/null +++ b/azurerm/import_arm_app_service_test.go @@ -0,0 +1,32 @@ +package azurerm + +import ( + "testing" + + "github.com/hashicorp/terraform/helper/acctest" + "github.com/hashicorp/terraform/helper/resource" +) + +func TestAccAzureRMAppService_importBasic(t *testing.T) { + resourceName := "azurerm_app_service.test" + + ri := acctest.RandInt() + config := testAccAzureRMAppService_basic(ri) + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testCheckAzureRMAppServiceDestroy, + Steps: []resource.TestStep{ + resource.TestStep{ + Config: config, + }, + + resource.TestStep{ + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} diff --git a/azurerm/resource_arm_app_service_test.go b/azurerm/resource_arm_app_service_test.go new file mode 100644 index 000000000000..6536018b40a3 --- /dev/null +++ b/azurerm/resource_arm_app_service_test.go @@ -0,0 +1,103 @@ +package azurerm + +import ( + "fmt" + "net/http" + "testing" + + "github.com/hashicorp/terraform/helper/acctest" + "github.com/hashicorp/terraform/helper/resource" + "github.com/hashicorp/terraform/terraform" +) + +func TestAccAzureRMAppService_basic(t *testing.T) { + ri := acctest.RandInt() + config := testAccAzureRMAppService_basic(ri) + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testCheckAzureRMAppServiceDestroy, + Steps: []resource.TestStep{ + { + Config: config, + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMAppServiceExists("azurerm_app_service.test"), + ), + }, + }, + }) +} + +func testCheckAzureRMAppServiceDestroy(s *terraform.State) error { + conn := testAccProvider.Meta().(*ArmClient).appsClient + + for _, rs := range s.RootModule().Resources { + if rs.Type != "azurerm_app_service" { + continue + } + + name := rs.Primary.Attributes["name"] + resourceGroup := rs.Primary.Attributes["resource_group_name"] + + resp, err := conn.Get(resourceGroup, name) + + if err != nil { + return nil + } + + if resp.StatusCode != http.StatusNotFound { + return fmt.Errorf("App Service still exists:\n%#v", resp) + } + } + + return nil +} + +func testCheckAzureRMAppServiceExists(name string) resource.TestCheckFunc { + return func(s *terraform.State) error { + // Ensure we have enough information in state to look up in API + rs, ok := s.RootModule().Resources[name] + if !ok { + return fmt.Errorf("Not found: %s", name) + } + + appServiceName := rs.Primary.Attributes["name"] + resourceGroup, hasResourceGroup := rs.Primary.Attributes["resource_group_name"] + if !hasResourceGroup { + return fmt.Errorf("Bad: no resource group found in state for App Service: %s", appServiceName) + } + + conn := testAccProvider.Meta().(*ArmClient).appsClient + + resp, err := conn.Get(resourceGroup, appServiceName) + if err != nil { + return fmt.Errorf("Bad: Get on appsClient: %s", err) + } + + if resp.StatusCode == http.StatusNotFound { + return fmt.Errorf("Bad: App Service %q (resource group: %q) does not exist", appServiceName, resourceGroup) + } + + return nil + } +} + +func testAccAzureRMAppService_basic(rInt int) string { + return fmt.Sprintf(` +resource "azurerm_resource_group" "test" { + name = "acctestRG-%d" + location = "West Europe" +} + +resource "azurerm_app_service" "test" { + name = "acctestAS-%d" + location = "West Europe" + resource_group_name = "${azurerm_resource_group.test.name}" + + tags { + environment = "Production" + } +} +`, rInt, rInt) +} From 27c36269dde16be8d8c2b2e494b21db2aac9db80 Mon Sep 17 00:00:00 2001 From: lstolyarov Date: Sat, 19 Aug 2017 16:06:16 +0100 Subject: [PATCH 04/31] updating tests to use testlocation() --- azurerm/import_arm_app_service_test.go | 2 +- azurerm/resource_arm_app_service_test.go | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/azurerm/import_arm_app_service_test.go b/azurerm/import_arm_app_service_test.go index 2f88ba5fd497..915fe162d884 100644 --- a/azurerm/import_arm_app_service_test.go +++ b/azurerm/import_arm_app_service_test.go @@ -11,7 +11,7 @@ func TestAccAzureRMAppService_importBasic(t *testing.T) { resourceName := "azurerm_app_service.test" ri := acctest.RandInt() - config := testAccAzureRMAppService_basic(ri) + config := testAccAzureRMAppService_basic(ri, testLocation()) resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, diff --git a/azurerm/resource_arm_app_service_test.go b/azurerm/resource_arm_app_service_test.go index 6536018b40a3..8709d3505ce4 100644 --- a/azurerm/resource_arm_app_service_test.go +++ b/azurerm/resource_arm_app_service_test.go @@ -12,7 +12,7 @@ import ( func TestAccAzureRMAppService_basic(t *testing.T) { ri := acctest.RandInt() - config := testAccAzureRMAppService_basic(ri) + config := testAccAzureRMAppService_basic(ri, testLocation()) resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, @@ -83,21 +83,21 @@ func testCheckAzureRMAppServiceExists(name string) resource.TestCheckFunc { } } -func testAccAzureRMAppService_basic(rInt int) string { +func testAccAzureRMAppService_basic(rInt int, location string) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" - location = "West Europe" + location = "%s" } resource "azurerm_app_service" "test" { name = "acctestAS-%d" - location = "West Europe" + location = "${azurerm_resource_group.test.location}" resource_group_name = "${azurerm_resource_group.test.name}" tags { environment = "Production" } } -`, rInt, rInt) +`, rInt, location, rInt) } From fbcb7837c59f8c055e00795b4fa5e3a99eb9b7a5 Mon Sep 17 00:00:00 2001 From: lstolyarov Date: Sat, 19 Aug 2017 20:03:16 +0100 Subject: [PATCH 05/31] setting tags --- azurerm/config.go | 12 ++++++++++-- azurerm/resource_arm_app_service.go | 5 ++++- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/azurerm/config.go b/azurerm/config.go index c04712b5792b..771676971490 100644 --- a/azurerm/config.go +++ b/azurerm/config.go @@ -133,12 +133,11 @@ type ArmClient struct { sqlServersClient sql.ServersClient appServicePlansClient web.AppServicePlansClient + appsClient web.AppsClient appInsightsClient appinsights.ComponentsClient servicePrincipalsClient graphrbac.ServicePrincipalsClient - - appsClient web.AppsClient } func withRequestLogging() autorest.SendDecorator { @@ -630,6 +629,15 @@ func (c *Config) getArmClient() (*ArmClient, error) { sqlepc.Sender = sender client.sqlElasticPoolsClient = sqlepc +<<<<<<< HEAD +======= + ac := web.NewAppsClientWithBaseURI(endpoint, c.SubscriptionID) + setUserAgent(&ac.Client) + ac.Authorizer = auth + ac.Sender = autorest.CreateSender(withRequestLogging()) + client.appsClient = ac + +>>>>>>> setting tags sqlsrv := sql.NewServersClientWithBaseURI(endpoint, c.SubscriptionID) setUserAgent(&sqlsrv.Client) sqlsrv.Authorizer = auth diff --git a/azurerm/resource_arm_app_service.go b/azurerm/resource_arm_app_service.go index e36a08deefa9..1f6472328538 100644 --- a/azurerm/resource_arm_app_service.go +++ b/azurerm/resource_arm_app_service.go @@ -137,11 +137,14 @@ func resourceArmAppServiceRead(d *schema.ResourceData, meta interface{}) error { d.SetId("") return nil } - return fmt.Errorf("Error making Read request on AzureRM App Service %s: %s", name, err) + return fmt.Errorf("Error making Read request on AzureRM App Service %s: %+v", name, err) } d.Set("name", name) d.Set("resource_group_name", resGroup) + d.Set("location", azureRMNormalizeLocation(*resp.Location)) + + flattenAndSetTags(d, resp.Tags) return nil } From 2165bd0236aaf5f2f9907f47f1d6e8ea08a7b780 Mon Sep 17 00:00:00 2001 From: Maninderjit Bindra Date: Wed, 23 Aug 2017 16:00:39 +0530 Subject: [PATCH 06/31] Resolve App Service Import Acceptance test failure --- azurerm/import_arm_app_service_test.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/azurerm/import_arm_app_service_test.go b/azurerm/import_arm_app_service_test.go index 915fe162d884..27801043043f 100644 --- a/azurerm/import_arm_app_service_test.go +++ b/azurerm/import_arm_app_service_test.go @@ -23,9 +23,10 @@ func TestAccAzureRMAppService_importBasic(t *testing.T) { }, resource.TestStep{ - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"force_dns_registration", "skip_custom_domain_verification", "skip_dns_registration"}, }, }, }) From 92b89a0929d9525f56430d21b5ee37a102fdd8af Mon Sep 17 00:00:00 2001 From: Maninderjit Bindra Date: Wed, 23 Aug 2017 16:34:47 +0530 Subject: [PATCH 07/31] removed additional spaces which were inserted by editor --- azurerm/import_arm_app_service_test.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/azurerm/import_arm_app_service_test.go b/azurerm/import_arm_app_service_test.go index 27801043043f..4a8d9b704bef 100644 --- a/azurerm/import_arm_app_service_test.go +++ b/azurerm/import_arm_app_service_test.go @@ -23,9 +23,9 @@ func TestAccAzureRMAppService_importBasic(t *testing.T) { }, resource.TestStep{ - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, ImportStateVerifyIgnore: []string{"force_dns_registration", "skip_custom_domain_verification", "skip_dns_registration"}, }, }, From 74f9069f425cf268fcb6c638f1b78879e6b90f4c Mon Sep 17 00:00:00 2001 From: lstolyarov Date: Fri, 1 Sep 2017 15:29:44 +0100 Subject: [PATCH 08/31] removing duplicates --- azurerm/config.go | 21 ++++++--------------- 1 file changed, 6 insertions(+), 15 deletions(-) diff --git a/azurerm/config.go b/azurerm/config.go index 771676971490..df4fcc60ef35 100644 --- a/azurerm/config.go +++ b/azurerm/config.go @@ -629,15 +629,6 @@ func (c *Config) getArmClient() (*ArmClient, error) { sqlepc.Sender = sender client.sqlElasticPoolsClient = sqlepc -<<<<<<< HEAD -======= - ac := web.NewAppsClientWithBaseURI(endpoint, c.SubscriptionID) - setUserAgent(&ac.Client) - ac.Authorizer = auth - ac.Sender = autorest.CreateSender(withRequestLogging()) - client.appsClient = ac - ->>>>>>> setting tags sqlsrv := sql.NewServersClientWithBaseURI(endpoint, c.SubscriptionID) setUserAgent(&sqlsrv.Client) sqlsrv.Authorizer = auth @@ -650,6 +641,12 @@ func (c *Config) getArmClient() (*ArmClient, error) { aspc.Sender = sender client.appServicePlansClient = aspc + ac := web.NewAppsClientWithBaseURI(endpoint, c.SubscriptionID) + setUserAgent(&ac.Client) + ac.Authorizer = auth + ac.Sender = autorest.CreateSender(withRequestLogging()) + client.appsClient = ac + ai := appinsights.NewComponentsClientWithBaseURI(endpoint, c.SubscriptionID) setUserAgent(&ai.Client) ai.Authorizer = auth @@ -662,12 +659,6 @@ func (c *Config) getArmClient() (*ArmClient, error) { spc.Sender = sender client.servicePrincipalsClient = spc - ac := web.NewAppsClientWithBaseURI(endpoint, c.SubscriptionID) - setUserAgent(&ac.Client) - ac.Authorizer = auth - ac.Sender = sender - client.appsClient = ac - kvc := keyvault.NewVaultsClientWithBaseURI(endpoint, c.SubscriptionID) setUserAgent(&kvc.Client) kvc.Authorizer = auth From f5f45a142bf3f1ac8600978c026f254499e6c1fc Mon Sep 17 00:00:00 2001 From: lstolyarov Date: Fri, 1 Sep 2017 15:31:05 +0100 Subject: [PATCH 09/31] adding documentation --- website/azurerm.erb | 4 ++ website/docs/r/app_service.html.markdown | 64 ++++++++++++++++++++++++ 2 files changed, 68 insertions(+) create mode 100644 website/docs/r/app_service.html.markdown diff --git a/website/azurerm.erb b/website/azurerm.erb index 77770ede3b4e..fd7cefb08013 100644 --- a/website/azurerm.erb +++ b/website/azurerm.erb @@ -63,6 +63,10 @@ azurerm_app_service_plan + > + azurerm_app_service + + diff --git a/website/docs/r/app_service.html.markdown b/website/docs/r/app_service.html.markdown new file mode 100644 index 000000000000..81bf4464f22f --- /dev/null +++ b/website/docs/r/app_service.html.markdown @@ -0,0 +1,64 @@ +--- +layout: "azurerm" +page_title: "Azure Resource Manager: azurerm_app_service" +sidebar_current: "docs-azurerm-resource-app-service" +description: |- + Create an App Service component. +--- + +# azurerm\_app\_service + +Create an App Service component. + +## Example Usage + +```hcl +resource "azurerm_resource_group" "test" { + name = "api-rg-pro" + location = "West Europe" +} + +resource "azurerm_app_service" "test" { + name = "api-appservice-pro" + location = "West Europe" + resource_group_name = "${azurerm_resource_group.test.name}" +} +``` + +## Argument Reference + +The following arguments are supported: + +* `name` - (Required) Specifies the name of the App Service Plan component. Changing this forces a new resource to be created. + +* `resource_group_name` - (Required) The name of the resource group in which to create the App Service Plan component. + +* `location` - (Required) Specifies the supported Azure location where the resource exists. Changing this forces a new resource to be created. + +* `app_service_plan_id` - (Optional) The resource ID of the app service plan. + +* `always_on` - (Optional) Alows the app to be loaded all the time. + +* `skip_dns_registration` - (Optional) If true, DNS registration is skipped. + +* `skip_custom_domain_verification` - (Optional) If true, custom (non .azurewebsites.net) domains associated with web app are not verified. + +* `force_dns_registration` - (Optional) If true, web app hostname is force registered with DNS. + +* `ttl_in_seconds` - (Optional) Time to live in seconds for web app's default domain name. + +* `tags` - (Optional) A mapping of tags to assign to the resource. + +## Attributes Reference + +The following attributes are exported: + +* `id` - The ID of the App Service component. + +## Import + +App Service instances can be imported using the `resource id`, e.g. + +``` +terraform import azurerm_app_service.instance1 /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/mygroup1/providers/Microsoft.Web/sites/instance1 +``` From 58be15a4d4de4cd8bbf7b0e84246b2686088a2eb Mon Sep 17 00:00:00 2001 From: lstolyarov Date: Fri, 1 Sep 2017 15:33:43 +0100 Subject: [PATCH 10/31] running fmt --- azurerm/config.go | 2 +- azurerm/import_arm_app_service_test.go | 6 +++--- azurerm/provider.go | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/azurerm/config.go b/azurerm/config.go index df4fcc60ef35..a2448b2b5e3d 100644 --- a/azurerm/config.go +++ b/azurerm/config.go @@ -133,7 +133,7 @@ type ArmClient struct { sqlServersClient sql.ServersClient appServicePlansClient web.AppServicePlansClient - appsClient web.AppsClient + appsClient web.AppsClient appInsightsClient appinsights.ComponentsClient diff --git a/azurerm/import_arm_app_service_test.go b/azurerm/import_arm_app_service_test.go index 4a8d9b704bef..27801043043f 100644 --- a/azurerm/import_arm_app_service_test.go +++ b/azurerm/import_arm_app_service_test.go @@ -23,9 +23,9 @@ func TestAccAzureRMAppService_importBasic(t *testing.T) { }, resource.TestStep{ - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, ImportStateVerifyIgnore: []string{"force_dns_registration", "skip_custom_domain_verification", "skip_dns_registration"}, }, }, diff --git a/azurerm/provider.go b/azurerm/provider.go index 57f8028db12c..c5e9e2c9ea29 100644 --- a/azurerm/provider.go +++ b/azurerm/provider.go @@ -71,7 +71,7 @@ func Provider() terraform.ResourceProvider { ResourcesMap: map[string]*schema.Resource{ "azurerm_application_insights": resourceArmApplicationInsights(), - "azurerm_app_service": resourceArmAppService(), + "azurerm_app_service": resourceArmAppService(), "azurerm_app_service_plan": resourceArmAppServicePlan(), "azurerm_availability_set": resourceArmAvailabilitySet(), "azurerm_cdn_endpoint": resourceArmCdnEndpoint(), From 5141e2ab851d1b68b787d612e89419b54c610516 Mon Sep 17 00:00:00 2001 From: lstolyarov Date: Fri, 1 Sep 2017 15:44:50 +0100 Subject: [PATCH 11/31] updating app service resource --- azurerm/resource_arm_app_service.go | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/azurerm/resource_arm_app_service.go b/azurerm/resource_arm_app_service.go index 1f6472328538..cba99dc2f8e0 100644 --- a/azurerm/resource_arm_app_service.go +++ b/azurerm/resource_arm_app_service.go @@ -4,6 +4,7 @@ import ( "fmt" "log" "net/http" + "strconv" "github.com/Azure/azure-sdk-for-go/arm/web" "github.com/hashicorp/terraform/helper/schema" @@ -46,7 +47,7 @@ func resourceArmAppService() *schema.Resource { Default: false, }, "ttl_in_seconds": { - Type: schema.TypeString, + Type: schema.TypeInt, Optional: true, Default: "", }, @@ -57,6 +58,7 @@ func resourceArmAppService() *schema.Resource { "always_on": { Type: schema.TypeBool, Optional: true, + Computed: true, }, "location": locationSchema(), "tags": tagsSchema(), @@ -65,10 +67,9 @@ func resourceArmAppService() *schema.Resource { } func resourceArmAppServiceCreateUpdate(d *schema.ResourceData, meta interface{}) error { - client := meta.(*ArmClient) - appClient := client.appsClient + appClient := meta.(*ArmClient).appsClient - log.Printf("[INFO] preparing arguments for Azure ARM Web App creation.") + log.Printf("[INFO] preparing arguments for Azure ARM App Service creation.") resGroup := d.Get("resource_group_name").(string) name := d.Get("name").(string) @@ -76,7 +77,7 @@ func resourceArmAppServiceCreateUpdate(d *schema.ResourceData, meta interface{}) skipDNSRegistration := d.Get("skip_dns_registration").(bool) skipCustomDomainVerification := d.Get("skip_custom_domain_verification").(bool) forceDNSRegistration := d.Get("force_dns_registration").(bool) - ttlInSeconds := d.Get("ttl_in_seconds").(string) + ttlInSeconds := d.Get("ttl_in_seconds").(int) tags := d.Get("tags").(map[string]interface{}) siteConfig := web.SiteConfig{} @@ -99,7 +100,7 @@ func resourceArmAppServiceCreateUpdate(d *schema.ResourceData, meta interface{}) SiteProperties: &siteProps, } - _, error := appClient.CreateOrUpdate(resGroup, name, siteEnvelope, &skipDNSRegistration, &skipCustomDomainVerification, &forceDNSRegistration, ttlInSeconds, make(chan struct{})) + _, error := appClient.CreateOrUpdate(resGroup, name, siteEnvelope, &skipDNSRegistration, &skipCustomDomainVerification, &forceDNSRegistration, strconv.Itoa(ttlInSeconds), make(chan struct{})) err := <-error if err != nil { return err From 1ebf2e57de848c1bc2b78581011c6a2f34f317e7 Mon Sep 17 00:00:00 2001 From: lstolyarov Date: Sun, 3 Sep 2017 13:01:10 +0100 Subject: [PATCH 12/31] updating app service code --- azurerm/resource_arm_app_service.go | 93 +++++++++++++++++++++-------- 1 file changed, 69 insertions(+), 24 deletions(-) diff --git a/azurerm/resource_arm_app_service.go b/azurerm/resource_arm_app_service.go index cba99dc2f8e0..9439e42020dd 100644 --- a/azurerm/resource_arm_app_service.go +++ b/azurerm/resource_arm_app_service.go @@ -8,6 +8,7 @@ import ( "github.com/Azure/azure-sdk-for-go/arm/web" "github.com/hashicorp/terraform/helper/schema" + "github.com/jen20/riviera/azure" ) func resourceArmAppService() *schema.Resource { @@ -49,19 +50,33 @@ func resourceArmAppService() *schema.Resource { "ttl_in_seconds": { Type: schema.TypeInt, Optional: true, - Default: "", }, - "app_service_plan_id": { - Type: schema.TypeString, + "site_config": { + Type: schema.TypeList, Optional: true, + MaxItems: 1, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "app_service_plan_id": { + Type: schema.TypeString, + Optional: true, + ForceNew: true, + }, + "always_on": { + Type: schema.TypeBool, + Optional: true, + Default: false, + }, + }, + }, }, - "always_on": { + "location": locationSchema(), + "tags": tagsSchema(), + "delete_metrics": { Type: schema.TypeBool, Optional: true, - Computed: true, + Default: true, }, - "location": locationSchema(), - "tags": tagsSchema(), }, } } @@ -73,26 +88,17 @@ func resourceArmAppServiceCreateUpdate(d *schema.ResourceData, meta interface{}) resGroup := d.Get("resource_group_name").(string) name := d.Get("name").(string) - location := d.Get("location").(string) skipDNSRegistration := d.Get("skip_dns_registration").(bool) skipCustomDomainVerification := d.Get("skip_custom_domain_verification").(bool) forceDNSRegistration := d.Get("force_dns_registration").(bool) - ttlInSeconds := d.Get("ttl_in_seconds").(int) - tags := d.Get("tags").(map[string]interface{}) - - siteConfig := web.SiteConfig{} - if v, ok := d.GetOk("always_on"); ok { - alwaysOn := v.(bool) - siteConfig.AlwaysOn = &alwaysOn + ttlInSeconds := 0 + if v, ok := d.GetOk("ttl_in_seconds"); ok { + ttlInSeconds = v.(int) } + location := d.Get("location").(string) + tags := d.Get("tags").(map[string]interface{}) - siteProps := web.SiteProperties{ - SiteConfig: &siteConfig, - } - if v, ok := d.GetOk("app_service_plan_id"); ok { - serverFarmID := v.(string) - siteProps.ServerFarmID = &serverFarmID - } + siteProps := expandAzureRmAppServiceSiteProps(d) siteEnvelope := web.Site{ Location: &location, @@ -145,6 +151,10 @@ func resourceArmAppServiceRead(d *schema.ResourceData, meta interface{}) error { d.Set("resource_group_name", resGroup) d.Set("location", azureRMNormalizeLocation(*resp.Location)) + // if siteProps := resp.SiteProperties; siteProps != nil { + // d.Set("site_config", flattenAzureRmAppServiceSiteProps(siteProps)) + // } + flattenAndSetTags(d, resp.Tags) return nil @@ -162,11 +172,46 @@ func resourceArmAppServiceDelete(d *schema.ResourceData, meta interface{}) error log.Printf("[DEBUG] Deleting App Service %s: %s", resGroup, name) - deleteMetrics := true + deleteMetrics := d.Get("delete_metrics").(bool) deleteEmptyServerFarm := true - skipDNSRegistration := true + skipDNSRegistration := d.Get("skip_dns_registration").(bool) _, err = appClient.Delete(resGroup, name, &deleteMetrics, &deleteEmptyServerFarm, &skipDNSRegistration) return err } + +func expandAzureRmAppServiceSiteProps(d *schema.ResourceData) web.SiteProperties { + configs := d.Get("site_config").([]interface{}) + siteProps := web.SiteProperties{} + if len(configs) == 0 { + return siteProps + } + config := configs[0].(map[string]interface{}) + + siteConfig := web.SiteConfig{} + alwaysOn := config["always_on"].(bool) + siteConfig.AlwaysOn = azure.Bool(alwaysOn) + siteProps.SiteConfig = &siteConfig + + serverFarmID := config["app_service_plan_id"].(string) + siteProps.ServerFarmID = &serverFarmID + + return siteProps +} + +func flattenAzureRmAppServiceSiteProps(siteProps *web.SiteProperties) []interface{} { + result := make([]interface{}, 0, 1) + site_config := make(map[string]interface{}, 0) + + if siteProps.ServerFarmID != nil { + site_config["app_service_plan_id"] = *siteProps.ServerFarmID + } + + if siteProps.SiteConfig.AlwaysOn != nil { + site_config["app_service_plan_id"] = *siteProps.ServerFarmID + } + + result = append(result, site_config) + return result +} From be6793ddcacf3638daa01f7a5f192667df112063 Mon Sep 17 00:00:00 2001 From: lstolyarov Date: Sun, 3 Sep 2017 13:01:35 +0100 Subject: [PATCH 13/31] updating tests --- azurerm/import_arm_app_service_test.go | 27 +++++++- azurerm/resource_arm_app_service_test.go | 85 +++++++++++++++++++----- 2 files changed, 94 insertions(+), 18 deletions(-) diff --git a/azurerm/import_arm_app_service_test.go b/azurerm/import_arm_app_service_test.go index 27801043043f..bc2520c76122 100644 --- a/azurerm/import_arm_app_service_test.go +++ b/azurerm/import_arm_app_service_test.go @@ -26,7 +26,32 @@ func TestAccAzureRMAppService_importBasic(t *testing.T) { ResourceName: resourceName, ImportState: true, ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"force_dns_registration", "skip_custom_domain_verification", "skip_dns_registration"}, + ImportStateVerifyIgnore: []string{"force_dns_registration", "skip_custom_domain_verification", "skip_dns_registration", "delete_metrics"}, + }, + }, + }) +} + +func TestAccAzureRMAppService_importComplete(t *testing.T) { + resourceName := "azurerm_app_service.test" + + ri := acctest.RandInt() + config := testAccAzureRMAppService_complete(ri, testLocation()) + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testCheckAzureRMAppServiceDestroy, + Steps: []resource.TestStep{ + resource.TestStep{ + Config: config, + }, + + resource.TestStep{ + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"force_dns_registration", "skip_custom_domain_verification", "skip_dns_registration", "delete_metrics"}, }, }, }) diff --git a/azurerm/resource_arm_app_service_test.go b/azurerm/resource_arm_app_service_test.go index 8709d3505ce4..cfb492b8afb5 100644 --- a/azurerm/resource_arm_app_service_test.go +++ b/azurerm/resource_arm_app_service_test.go @@ -2,12 +2,12 @@ package azurerm import ( "fmt" - "net/http" "testing" "github.com/hashicorp/terraform/helper/acctest" "github.com/hashicorp/terraform/helper/resource" "github.com/hashicorp/terraform/terraform" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" ) func TestAccAzureRMAppService_basic(t *testing.T) { @@ -29,6 +29,25 @@ func TestAccAzureRMAppService_basic(t *testing.T) { }) } +func TestAccAzureRMAppService_complete(t *testing.T) { + ri := acctest.RandInt() + config := testAccAzureRMAppService_complete(ri, testLocation()) + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testCheckAzureRMAppServiceDestroy, + Steps: []resource.TestStep{ + { + Config: config, + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMAppServiceExists("azurerm_app_service.test"), + ), + }, + }, + }) +} + func testCheckAzureRMAppServiceDestroy(s *terraform.State) error { conn := testAccProvider.Meta().(*ArmClient).appsClient @@ -43,12 +62,13 @@ func testCheckAzureRMAppServiceDestroy(s *terraform.State) error { resp, err := conn.Get(resourceGroup, name) if err != nil { - return nil + if utils.ResponseWasNotFound(resp.Response) { + return nil + } + return err } - if resp.StatusCode != http.StatusNotFound { - return fmt.Errorf("App Service still exists:\n%#v", resp) - } + return fmt.Errorf("App Service still exists:\n%#v", resp) } return nil @@ -72,11 +92,11 @@ func testCheckAzureRMAppServiceExists(name string) resource.TestCheckFunc { resp, err := conn.Get(resourceGroup, appServiceName) if err != nil { - return fmt.Errorf("Bad: Get on appsClient: %s", err) - } + if utils.ResponseWasNotFound(resp.Response) { + return fmt.Errorf("Bad: App Service %q (resource group: %q) does not exist", appServiceName, resourceGroup) + } - if resp.StatusCode == http.StatusNotFound { - return fmt.Errorf("Bad: App Service %q (resource group: %q) does not exist", appServiceName, resourceGroup) + return fmt.Errorf("Bad: Get on appsClient: %+v", err) } return nil @@ -86,18 +106,49 @@ func testCheckAzureRMAppServiceExists(name string) resource.TestCheckFunc { func testAccAzureRMAppService_basic(rInt int, location string) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { - name = "acctestRG-%d" - location = "%s" + name = "acctestRG-%d" + location = "%s" } resource "azurerm_app_service" "test" { - name = "acctestAS-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + name = "acctestAS-%d" + location = "${azurerm_resource_group.test.location}" + resource_group_name = "${azurerm_resource_group.test.name}" - tags { - environment = "Production" - } + tags { + environment = "Production" + } } `, rInt, location, rInt) } + +func testAccAzureRMAppService_complete(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}" + + site_config { + app_service_plan_id = "${azurerm_app_service_plan.test.id}" + always_on = true + } +} +`, rInt, location, rInt, rInt) +} From 2c8b16e744256d16219912fb5627799da70417e3 Mon Sep 17 00:00:00 2001 From: lstolyarov Date: Sun, 3 Sep 2017 13:02:03 +0100 Subject: [PATCH 14/31] updating documentation --- website/docs/r/app_service.html.markdown | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/website/docs/r/app_service.html.markdown b/website/docs/r/app_service.html.markdown index 81bf4464f22f..e2c53cc1dad4 100644 --- a/website/docs/r/app_service.html.markdown +++ b/website/docs/r/app_service.html.markdown @@ -3,12 +3,12 @@ layout: "azurerm" page_title: "Azure Resource Manager: azurerm_app_service" sidebar_current: "docs-azurerm-resource-app-service" description: |- - Create an App Service component. + Manage an App Service (within an App Service Plan). --- # azurerm\_app\_service -Create an App Service component. +Manage an App Service (within an App Service Plan). ## Example Usage @@ -20,7 +20,7 @@ resource "azurerm_resource_group" "test" { resource "azurerm_app_service" "test" { name = "api-appservice-pro" - location = "West Europe" + location = "${azurerm_resource_group.test.location}" resource_group_name = "${azurerm_resource_group.test.name}" } ``` @@ -35,6 +35,8 @@ The following arguments are supported: * `location` - (Required) Specifies the supported Azure location where the resource exists. Changing this forces a new resource to be created. +`site_config` supports the following: + * `app_service_plan_id` - (Optional) The resource ID of the app service plan. * `always_on` - (Optional) Alows the app to be loaded all the time. @@ -45,7 +47,7 @@ The following arguments are supported: * `force_dns_registration` - (Optional) If true, web app hostname is force registered with DNS. -* `ttl_in_seconds` - (Optional) Time to live in seconds for web app's default domain name. +* `ttl_in_seconds` - (Optional) Time to live in seconds for app service's default domain name. * `tags` - (Optional) A mapping of tags to assign to the resource. From 007c21bbd4f1f4034d0b3374724d1b53235f1578 Mon Sep 17 00:00:00 2001 From: lstolyarov Date: Sun, 3 Sep 2017 16:25:16 +0100 Subject: [PATCH 15/31] setting site config --- azurerm/resource_arm_app_service.go | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/azurerm/resource_arm_app_service.go b/azurerm/resource_arm_app_service.go index 9439e42020dd..4a56124f78fb 100644 --- a/azurerm/resource_arm_app_service.go +++ b/azurerm/resource_arm_app_service.go @@ -54,6 +54,7 @@ func resourceArmAppService() *schema.Resource { "site_config": { Type: schema.TypeList, Optional: true, + Computed: true, MaxItems: 1, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ @@ -65,7 +66,7 @@ func resourceArmAppService() *schema.Resource { "always_on": { Type: schema.TypeBool, Optional: true, - Default: false, + Computed: true, }, }, }, @@ -151,9 +152,9 @@ func resourceArmAppServiceRead(d *schema.ResourceData, meta interface{}) error { d.Set("resource_group_name", resGroup) d.Set("location", azureRMNormalizeLocation(*resp.Location)) - // if siteProps := resp.SiteProperties; siteProps != nil { - // d.Set("site_config", flattenAzureRmAppServiceSiteProps(siteProps)) - // } + if siteProps := resp.SiteProperties; siteProps != nil { + d.Set("site_config", flattenAzureRmAppServiceSiteProps(siteProps)) + } flattenAndSetTags(d, resp.Tags) @@ -208,8 +209,12 @@ func flattenAzureRmAppServiceSiteProps(siteProps *web.SiteProperties) []interfac site_config["app_service_plan_id"] = *siteProps.ServerFarmID } - if siteProps.SiteConfig.AlwaysOn != nil { - site_config["app_service_plan_id"] = *siteProps.ServerFarmID + siteConfig := siteProps.SiteConfig + log.Printf("[DEBUG] SiteConfig is %s", siteConfig) + if siteConfig != nil { + if siteConfig.AlwaysOn != nil { + site_config["always_on"] = *siteConfig.AlwaysOn + } } result = append(result, site_config) From f2d292dd7f146f009e363bc3efe42c9f71b55fc1 Mon Sep 17 00:00:00 2001 From: lstolyarov Date: Sun, 3 Sep 2017 16:25:36 +0100 Subject: [PATCH 16/31] adding more tests --- azurerm/import_arm_app_service_test.go | 25 ++++++++++++ azurerm/resource_arm_app_service_test.go | 50 ++++++++++++++++++++++++ 2 files changed, 75 insertions(+) diff --git a/azurerm/import_arm_app_service_test.go b/azurerm/import_arm_app_service_test.go index bc2520c76122..c37f32ec309d 100644 --- a/azurerm/import_arm_app_service_test.go +++ b/azurerm/import_arm_app_service_test.go @@ -56,3 +56,28 @@ func TestAccAzureRMAppService_importComplete(t *testing.T) { }, }) } + +func TestAccAzureRMAppService_importCompleteAlwaysOn(t *testing.T) { + resourceName := "azurerm_app_service.test" + + ri := acctest.RandInt() + config := testAccAzureRMAppService_completeAlwaysOn(ri, testLocation()) + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testCheckAzureRMAppServiceDestroy, + Steps: []resource.TestStep{ + resource.TestStep{ + Config: config, + }, + + resource.TestStep{ + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"force_dns_registration", "skip_custom_domain_verification", "skip_dns_registration", "delete_metrics"}, + }, + }, + }) +} diff --git a/azurerm/resource_arm_app_service_test.go b/azurerm/resource_arm_app_service_test.go index cfb492b8afb5..360ff470f469 100644 --- a/azurerm/resource_arm_app_service_test.go +++ b/azurerm/resource_arm_app_service_test.go @@ -48,6 +48,25 @@ func TestAccAzureRMAppService_complete(t *testing.T) { }) } +func TestAccAzureRMAppService_completeAlwaysOn(t *testing.T) { + ri := acctest.RandInt() + config := testAccAzureRMAppService_completeAlwaysOn(ri, testLocation()) + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testCheckAzureRMAppServiceDestroy, + Steps: []resource.TestStep{ + { + Config: config, + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMAppServiceExists("azurerm_app_service.test"), + ), + }, + }, + }) +} + func testCheckAzureRMAppServiceDestroy(s *terraform.State) error { conn := testAccProvider.Meta().(*ArmClient).appsClient @@ -140,6 +159,37 @@ resource "azurerm_app_service_plan" "test" { } } +resource "azurerm_app_service" "test" { + name = "acctestAS-%d" + location = "${azurerm_resource_group.test.location}" + resource_group_name = "${azurerm_resource_group.test.name}" + + site_config { + app_service_plan_id = "${azurerm_app_service_plan.test.id}" + always_on = false + } +} +`, rInt, location, rInt, rInt) +} + +func testAccAzureRMAppService_completeAlwaysOn(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}" From 2a8813ff169263238a68f88d786b1bff4098cbba Mon Sep 17 00:00:00 2001 From: lstolyarov Date: Mon, 4 Sep 2017 10:09:34 +0100 Subject: [PATCH 17/31] making use of utils module --- azurerm/resource_arm_app_service.go | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/azurerm/resource_arm_app_service.go b/azurerm/resource_arm_app_service.go index 4a56124f78fb..13870ef2fcf4 100644 --- a/azurerm/resource_arm_app_service.go +++ b/azurerm/resource_arm_app_service.go @@ -8,7 +8,7 @@ import ( "github.com/Azure/azure-sdk-for-go/arm/web" "github.com/hashicorp/terraform/helper/schema" - "github.com/jen20/riviera/azure" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" ) func resourceArmAppService() *schema.Resource { @@ -104,7 +104,7 @@ func resourceArmAppServiceCreateUpdate(d *schema.ResourceData, meta interface{}) siteEnvelope := web.Site{ Location: &location, Tags: expandTags(tags), - SiteProperties: &siteProps, + SiteProperties: siteProps, } _, error := appClient.CreateOrUpdate(resGroup, name, siteEnvelope, &skipDNSRegistration, &skipCustomDomainVerification, &forceDNSRegistration, strconv.Itoa(ttlInSeconds), make(chan struct{})) @@ -182,23 +182,24 @@ func resourceArmAppServiceDelete(d *schema.ResourceData, meta interface{}) error return err } -func expandAzureRmAppServiceSiteProps(d *schema.ResourceData) web.SiteProperties { +func expandAzureRmAppServiceSiteProps(d *schema.ResourceData) *web.SiteProperties { configs := d.Get("site_config").([]interface{}) siteProps := web.SiteProperties{} if len(configs) == 0 { - return siteProps + return &siteProps } config := configs[0].(map[string]interface{}) siteConfig := web.SiteConfig{} alwaysOn := config["always_on"].(bool) - siteConfig.AlwaysOn = azure.Bool(alwaysOn) + siteConfig.AlwaysOn = utils.Bool(alwaysOn) + siteProps.SiteConfig = &siteConfig serverFarmID := config["app_service_plan_id"].(string) siteProps.ServerFarmID = &serverFarmID - return siteProps + return &siteProps } func flattenAzureRmAppServiceSiteProps(siteProps *web.SiteProperties) []interface{} { From dd51d1519bb89105f6918b1556724e0801d9354c Mon Sep 17 00:00:00 2001 From: tombuildsstuff Date: Thu, 14 Sep 2017 11:42:54 +0100 Subject: [PATCH 18/31] WIP --- azurerm/config.go | 4 +- azurerm/import_arm_app_service_test.go | 52 +- azurerm/resource_arm_app_service.go | 580 ++++++++-- azurerm/resource_arm_app_service_test.go | 1271 ++++++++++++++++++++-- 4 files changed, 1711 insertions(+), 196 deletions(-) diff --git a/azurerm/config.go b/azurerm/config.go index a2448b2b5e3d..f560bcd6cd69 100644 --- a/azurerm/config.go +++ b/azurerm/config.go @@ -133,7 +133,7 @@ type ArmClient struct { sqlServersClient sql.ServersClient appServicePlansClient web.AppServicePlansClient - appsClient web.AppsClient + appServicesClient web.AppsClient appInsightsClient appinsights.ComponentsClient @@ -645,7 +645,7 @@ func (c *Config) getArmClient() (*ArmClient, error) { setUserAgent(&ac.Client) ac.Authorizer = auth ac.Sender = autorest.CreateSender(withRequestLogging()) - client.appsClient = ac + client.appServicesClient = ac ai := appinsights.NewComponentsClientWithBaseURI(endpoint, c.SubscriptionID) setUserAgent(&ai.Client) diff --git a/azurerm/import_arm_app_service_test.go b/azurerm/import_arm_app_service_test.go index c37f32ec309d..5c12dddc092f 100644 --- a/azurerm/import_arm_app_service_test.go +++ b/azurerm/import_arm_app_service_test.go @@ -1,5 +1,6 @@ package azurerm +/* import ( "testing" @@ -31,53 +32,4 @@ func TestAccAzureRMAppService_importBasic(t *testing.T) { }, }) } - -func TestAccAzureRMAppService_importComplete(t *testing.T) { - resourceName := "azurerm_app_service.test" - - ri := acctest.RandInt() - config := testAccAzureRMAppService_complete(ri, testLocation()) - - resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testCheckAzureRMAppServiceDestroy, - Steps: []resource.TestStep{ - resource.TestStep{ - Config: config, - }, - - resource.TestStep{ - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"force_dns_registration", "skip_custom_domain_verification", "skip_dns_registration", "delete_metrics"}, - }, - }, - }) -} - -func TestAccAzureRMAppService_importCompleteAlwaysOn(t *testing.T) { - resourceName := "azurerm_app_service.test" - - ri := acctest.RandInt() - config := testAccAzureRMAppService_completeAlwaysOn(ri, testLocation()) - - resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testCheckAzureRMAppServiceDestroy, - Steps: []resource.TestStep{ - resource.TestStep{ - Config: config, - }, - - resource.TestStep{ - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"force_dns_registration", "skip_custom_domain_verification", "skip_dns_registration", "delete_metrics"}, - }, - }, - }) -} +*/ diff --git a/azurerm/resource_arm_app_service.go b/azurerm/resource_arm_app_service.go index 13870ef2fcf4..fbe326035e06 100644 --- a/azurerm/resource_arm_app_service.go +++ b/azurerm/resource_arm_app_service.go @@ -3,117 +3,313 @@ package azurerm import ( "fmt" "log" - "net/http" - "strconv" "github.com/Azure/azure-sdk-for-go/arm/web" "github.com/hashicorp/terraform/helper/schema" + "github.com/hashicorp/terraform/helper/validation" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" ) func resourceArmAppService() *schema.Resource { return &schema.Resource{ - Create: resourceArmAppServiceCreateUpdate, + Create: resourceArmAppServiceCreate, Read: resourceArmAppServiceRead, - Update: resourceArmAppServiceCreateUpdate, + Update: resourceArmAppServiceUpdate, Delete: resourceArmAppServiceDelete, Importer: &schema.ResourceImporter{ State: schema.ImportStatePassthrough, }, Schema: map[string]*schema.Schema{ + "name": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + }, + "resource_group_name": { Type: schema.TypeString, Required: true, ForceNew: true, }, - "name": { + + "location": locationSchema(), + + "app_service_plan_id": { Type: schema.TypeString, Required: true, ForceNew: true, }, - "skip_dns_registration": { + + "site_config": { + Type: schema.TypeList, + Optional: true, + Computed: true, + MaxItems: 1, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "always_on": { + Type: schema.TypeBool, + Optional: true, + Computed: true, + }, + + "default_documents": { + Type: schema.TypeList, + Optional: true, + Computed: true, + Elem: &schema.Schema{Type: schema.TypeString}, + }, + + "dotnet_framework_version": { + Type: schema.TypeString, + Optional: true, + Default: "v4.0", + ValidateFunc: validation.StringInSlice([]string{ + "v2.0", + "v4.0", + }, true), + DiffSuppressFunc: ignoreCaseDiffSuppressFunc, + }, + + "java_version": { + Type: schema.TypeString, + Optional: true, + Computed: true, + ValidateFunc: validation.StringInSlice([]string{ + "1.7", + "1.8", + }, false), + }, + + "java_container": { + Type: schema.TypeString, + Optional: true, + Computed: true, + ValidateFunc: validation.StringInSlice([]string{ + "JETTY", + "TOMCAT", + }, true), + DiffSuppressFunc: ignoreCaseDiffSuppressFunc, + }, + + "java_container_version": { + Type: schema.TypeString, + Optional: true, + Computed: true, + }, + + "linux_app_framework_version": { + Type: schema.TypeString, + Optional: true, + Computed: true, + // TODO: should this be ForceNew? + ValidateFunc: validation.StringInSlice([]string{ + "dotnetcore|1.0", + "dotnetcore|1.1", + "node|4.4", + "node|4.5", + "node|6.2", + "node|6.6", + "node|6.9", + "node|6.10", + "node|6.11", + "node|8.0", + "node|8.1", + "php|5.6", + "php|7.0", + "ruby|2.3", + }, true), + DiffSuppressFunc: ignoreCaseDiffSuppressFunc, + }, + + "local_mysql_enabled": { + Type: schema.TypeBool, + Optional: true, + Computed: true, + }, + + "managed_pipeline_mode": { + Type: schema.TypeString, + Optional: true, + Computed: true, + ValidateFunc: validation.StringInSlice([]string{ + string(web.Classic), + string(web.Integrated), + }, true), + DiffSuppressFunc: ignoreCaseDiffSuppressFunc, + }, + + "php_version": { + Type: schema.TypeString, + Optional: true, + Computed: true, + ValidateFunc: validation.StringInSlice([]string{ + "5.5", + "5.6", + "7.0", + "7.1", + }, false), + }, + + "python_version": { + Type: schema.TypeString, + Optional: true, + Computed: true, + ValidateFunc: validation.StringInSlice([]string{ + "2.7", + "3.4", + }, false), + }, + + "use_32_bit_worker_process": { + Type: schema.TypeBool, + Optional: true, + Computed: true, + }, + + "websockets_enabled": { + Type: schema.TypeBool, + Optional: true, + Computed: true, + }, + }, + }, + }, + + "client_affinity_enabled": { Type: schema.TypeBool, Optional: true, - Default: true, + Computed: true, + ForceNew: true, // due to a bug in the Azure API :( }, - "skip_custom_domain_verification": { + + "enabled": { Type: schema.TypeBool, Optional: true, Default: true, + ForceNew: true, // due to a bug in the Azure API :( }, - "force_dns_registration": { + + "reserved": { Type: schema.TypeBool, Optional: true, - Default: false, + Computed: true, + ForceNew: true, // due to a bug in the Azure API :( }, - "ttl_in_seconds": { - Type: schema.TypeInt, + + "app_settings": { + Type: schema.TypeMap, Optional: true, + Computed: true, }, - "site_config": { + + "connection_string": { Type: schema.TypeList, Optional: true, Computed: true, - MaxItems: 1, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ - "app_service_plan_id": { + "name": { Type: schema.TypeString, - Optional: true, - ForceNew: true, + Required: true, }, - "always_on": { - Type: schema.TypeBool, - Optional: true, - Computed: true, + "value": { + Type: schema.TypeString, + Required: true, + }, + "type": { + Type: schema.TypeString, + Required: true, + ValidateFunc: validation.StringInSlice([]string{ + string(web.APIHub), + string(web.Custom), + string(web.DocDb), + string(web.EventHub), + string(web.MySQL), + string(web.NotificationHub), + string(web.PostgreSQL), + string(web.RedisCache), + string(web.ServiceBus), + string(web.SQLAzure), + string(web.SQLServer), + }, true), + DiffSuppressFunc: ignoreCaseDiffSuppressFunc, }, }, }, }, - "location": locationSchema(), - "tags": tagsSchema(), - "delete_metrics": { - Type: schema.TypeBool, - Optional: true, - Default: true, - }, + + "tags": tagsForceNewSchema(), // due to a bug in the Azure API :( }, } } -func resourceArmAppServiceCreateUpdate(d *schema.ResourceData, meta interface{}) error { - appClient := meta.(*ArmClient).appsClient +func resourceArmAppServiceCreate(d *schema.ResourceData, meta interface{}) error { + client := meta.(*ArmClient).appServicesClient - log.Printf("[INFO] preparing arguments for Azure ARM App Service creation.") + log.Printf("[INFO] preparing arguments for AzureRM App Service creation.") - resGroup := d.Get("resource_group_name").(string) name := d.Get("name").(string) - skipDNSRegistration := d.Get("skip_dns_registration").(bool) - skipCustomDomainVerification := d.Get("skip_custom_domain_verification").(bool) - forceDNSRegistration := d.Get("force_dns_registration").(bool) - ttlInSeconds := 0 - if v, ok := d.GetOk("ttl_in_seconds"); ok { - ttlInSeconds = v.(int) - } + resGroup := d.Get("resource_group_name").(string) location := d.Get("location").(string) + appServicePlanId := d.Get("app_service_plan_id").(string) + enabled := d.Get("enabled").(bool) tags := d.Get("tags").(map[string]interface{}) - siteProps := expandAzureRmAppServiceSiteProps(d) + siteConfig := expandAppServiceSiteConfig(d) + appSettings := expandAppServiceAppSettings(d) siteEnvelope := web.Site{ - Location: &location, - Tags: expandTags(tags), - SiteProperties: siteProps, + Location: &location, + Tags: expandTags(tags), + SiteProperties: &web.SiteProperties{ + ServerFarmID: utils.String(appServicePlanId), + Enabled: utils.Bool(enabled), + SiteConfig: &siteConfig, + }, } - _, error := appClient.CreateOrUpdate(resGroup, name, siteEnvelope, &skipDNSRegistration, &skipCustomDomainVerification, &forceDNSRegistration, strconv.Itoa(ttlInSeconds), make(chan struct{})) - err := <-error + if v, ok := d.GetOk("client_affinity_enabled"); ok { + enabled := v.(bool) + siteEnvelope.SiteProperties.ClientAffinityEnabled = utils.Bool(enabled) + } + + if v, ok := d.GetOk("reserved"); ok { + reserved := v.(bool) + siteEnvelope.SiteProperties.Reserved = utils.Bool(reserved) + } + + // NOTE: these seem like sensible defaults, in lieu of any better documentation. + skipDNSRegistration := false + forceDNSRegistration := false + skipCustomDomainVerification := true + ttlInSeconds := "60" + _, createErr := client.CreateOrUpdate(resGroup, name, siteEnvelope, &skipDNSRegistration, &skipCustomDomainVerification, &forceDNSRegistration, ttlInSeconds, make(chan struct{})) + err := <-createErr if err != nil { return err } - read, err := appClient.Get(resGroup, name) + settings := web.StringDictionary{ + Properties: appSettings, + } + _, err = client.UpdateApplicationSettings(resGroup, name, settings) + if err != nil { + return fmt.Errorf("Error updating Application Settings for App Service %q: %+v", name, err) + } + + connectionStrings := expandAppServiceConnectionStrings(d) + properties := web.ConnectionStringDictionary{ + Properties: connectionStrings, + } + + _, err = client.UpdateConnectionStrings(resGroup, name, properties) + if err != nil { + return fmt.Errorf("Error updating Connection Strings for App Service %q: %+v", name, err) + } + + read, err := client.Get(resGroup, name) if err != nil { return err } @@ -126,34 +322,111 @@ func resourceArmAppServiceCreateUpdate(d *schema.ResourceData, meta interface{}) return resourceArmAppServiceRead(d, meta) } -func resourceArmAppServiceRead(d *schema.ResourceData, meta interface{}) error { - appClient := meta.(*ArmClient).appsClient +func resourceArmAppServiceUpdate(d *schema.ResourceData, meta interface{}) error { + client := meta.(*ArmClient).appServicesClient id, err := parseAzureResourceID(d.Id()) if err != nil { return err } - log.Printf("[DEBUG] Reading App Service details %s", id) + resGroup := id.ResourceGroup + name := id.Path["sites"] + + if d.HasChange("site_config") { + // update the main configuration + siteConfig := expandAppServiceSiteConfig(d) + siteConfigResource := web.SiteConfigResource{ + SiteConfig: &siteConfig, + } + _, err := client.CreateOrUpdateConfiguration(resGroup, name, siteConfigResource) + if err != nil { + return fmt.Errorf("Error updating Configuration for App Service %q: %+v", name, err) + } + } + + if d.HasChange("app_settings") { + // update the AppSettings + appSettings := expandAppServiceAppSettings(d) + settings := web.StringDictionary{ + Properties: appSettings, + } + + _, err := client.UpdateApplicationSettings(resGroup, name, settings) + if err != nil { + return fmt.Errorf("Error updating Application Settings for App Service %q: %+v", name, err) + } + } + + if d.HasChange("connection_string") { + // update the ConnectionStrings + connectionStrings := expandAppServiceConnectionStrings(d) + properties := web.ConnectionStringDictionary{ + Properties: connectionStrings, + } + + _, err := client.UpdateConnectionStrings(resGroup, name, properties) + if err != nil { + return fmt.Errorf("Error updating Connection Strings for App Service %q: %+v", name, err) + } + } + + return resourceArmAppServiceRead(d, meta) +} + +func resourceArmAppServiceRead(d *schema.ResourceData, meta interface{}) error { + client := meta.(*ArmClient).appServicesClient + + id, err := parseAzureResourceID(d.Id()) + if err != nil { + return err + } resGroup := id.ResourceGroup name := id.Path["sites"] - resp, err := appClient.Get(resGroup, name) + resp, err := client.Get(resGroup, name) if err != nil { - if resp.StatusCode == http.StatusNotFound { + if utils.ResponseWasNotFound(resp.Response) { + // TODO: debug logging d.SetId("") return nil } return fmt.Errorf("Error making Read request on AzureRM App Service %s: %+v", name, err) } + configResp, err := client.GetConfiguration(resGroup, name) + if err != nil { + return fmt.Errorf("Error making Read request on AzureRM App Service Configuration %s: %+v", name, err) + } + + appSettingsResp, err := client.ListApplicationSettings(resGroup, name) + if err != nil { + return fmt.Errorf("Error making Read request on AzureRM App Service AppSettings %s: %+v", name, err) + } + + connectionStringsResp, err := client.ListConnectionStrings(resGroup, name) + if err != nil { + return fmt.Errorf("Error making Read request on AzureRM App Service ConnectionStrings %s: %+v", name, err) + } + d.Set("name", name) d.Set("resource_group_name", resGroup) d.Set("location", azureRMNormalizeLocation(*resp.Location)) - if siteProps := resp.SiteProperties; siteProps != nil { - d.Set("site_config", flattenAzureRmAppServiceSiteProps(siteProps)) + if props := resp.SiteProperties; props != nil { + d.Set("app_service_plan_id", props.ServerFarmID) + d.Set("client_affinity_enabled", props.ClientAffinityEnabled) + d.Set("enabled", props.Enabled) + d.Set("reserved", props.Reserved) + } + + d.Set("app_settings", appSettingsResp.Properties) + d.Set("connection_string", flattenAppServiceConnectionStrings(connectionStringsResp.Properties)) + + siteConfig := flattenAppServiceSiteConfig(configResp.SiteConfig) + if err := d.Set("site_config", siteConfig); err != nil { + return err } flattenAndSetTags(d, resp.Tags) @@ -162,7 +435,7 @@ func resourceArmAppServiceRead(d *schema.ResourceData, meta interface{}) error { } func resourceArmAppServiceDelete(d *schema.ResourceData, meta interface{}) error { - appClient := meta.(*ArmClient).appsClient + client := meta.(*ArmClient).appServicesClient id, err := parseAzureResourceID(d.Id()) if err != nil { @@ -171,53 +444,194 @@ func resourceArmAppServiceDelete(d *schema.ResourceData, meta interface{}) error resGroup := id.ResourceGroup name := id.Path["sites"] - log.Printf("[DEBUG] Deleting App Service %s: %s", resGroup, name) - - deleteMetrics := d.Get("delete_metrics").(bool) - deleteEmptyServerFarm := true - skipDNSRegistration := d.Get("skip_dns_registration").(bool) + log.Printf("[DEBUG] Deleting App Service %q (resource group %q)", name, resGroup) - _, err = appClient.Delete(resGroup, name, &deleteMetrics, &deleteEmptyServerFarm, &skipDNSRegistration) + deleteMetrics := true + deleteEmptyServerFarm := false + skipDNSRegistration := true + resp, err := client.Delete(resGroup, name, &deleteMetrics, &deleteEmptyServerFarm, &skipDNSRegistration) + if err != nil { + if !utils.ResponseWasNotFound(resp) { + return err + } + } - return err + return nil } -func expandAzureRmAppServiceSiteProps(d *schema.ResourceData) *web.SiteProperties { +func expandAppServiceSiteConfig(d *schema.ResourceData) web.SiteConfig { configs := d.Get("site_config").([]interface{}) - siteProps := web.SiteProperties{} + siteConfig := web.SiteConfig{} + if len(configs) == 0 { - return &siteProps + return siteConfig } + config := configs[0].(map[string]interface{}) - siteConfig := web.SiteConfig{} - alwaysOn := config["always_on"].(bool) - siteConfig.AlwaysOn = utils.Bool(alwaysOn) + if v, ok := config["always_on"]; ok { + siteConfig.AlwaysOn = utils.Bool(v.(bool)) + } - siteProps.SiteConfig = &siteConfig + if v, ok := config["default_documents"]; ok { + input := v.([]interface{}) - serverFarmID := config["app_service_plan_id"].(string) - siteProps.ServerFarmID = &serverFarmID + documents := make([]string, 0) + for _, document := range input { + documents = append(documents, document.(string)) + } - return &siteProps + siteConfig.DefaultDocuments = &documents + } + + if v, ok := config["dotnet_framework_version"]; ok { + siteConfig.NetFrameworkVersion = utils.String(v.(string)) + } + + if v, ok := config["java_version"]; ok { + siteConfig.JavaVersion = utils.String(v.(string)) + } + + if v, ok := config["java_container"]; ok { + siteConfig.JavaContainer = utils.String(v.(string)) + } + + if v, ok := config["java_container_version"]; ok { + siteConfig.JavaContainerVersion = utils.String(v.(string)) + } + + if v, ok := config["linux_app_framework_version"]; ok { + siteConfig.LinuxFxVersion = utils.String(v.(string)) + } + + if v, ok := config["local_mysql_enabled"]; ok { + siteConfig.LocalMySQLEnabled = utils.Bool(v.(bool)) + } + + if v, ok := config["managed_pipeline_mode"]; ok { + siteConfig.ManagedPipelineMode = web.ManagedPipelineMode(v.(string)) + } + + if v, ok := config["php_version"]; ok { + siteConfig.PhpVersion = utils.String(v.(string)) + } + + if v, ok := config["python_version"]; ok { + siteConfig.PythonVersion = utils.String(v.(string)) + } + + if v, ok := config["use_32_bit_worker_process"]; ok { + siteConfig.Use32BitWorkerProcess = utils.Bool(v.(bool)) + } + + if v, ok := config["websockets_enabled"]; ok { + siteConfig.WebSocketsEnabled = utils.Bool(v.(bool)) + } + + return siteConfig } -func flattenAzureRmAppServiceSiteProps(siteProps *web.SiteProperties) []interface{} { - result := make([]interface{}, 0, 1) - site_config := make(map[string]interface{}, 0) +func flattenAppServiceSiteConfig(input *web.SiteConfig) []interface{} { + results := make([]interface{}, 0) + result := make(map[string]interface{}, 0) + + if input == nil { + log.Printf("[DEBUG] SiteConfig is nil") + return results + } - if siteProps.ServerFarmID != nil { - site_config["app_service_plan_id"] = *siteProps.ServerFarmID + if input.AlwaysOn != nil { + result["always_on"] = *input.AlwaysOn } - siteConfig := siteProps.SiteConfig - log.Printf("[DEBUG] SiteConfig is %s", siteConfig) - if siteConfig != nil { - if siteConfig.AlwaysOn != nil { - site_config["always_on"] = *siteConfig.AlwaysOn + if input.DefaultDocuments != nil { + documents := make([]string, 0) + for _, document := range *input.DefaultDocuments { + documents = append(documents, document) } + + result["default_documents"] = documents + } + + if input.NetFrameworkVersion != nil { + result["dotnet_framework_version"] = *input.NetFrameworkVersion + } + + if input.JavaVersion != nil { + result["java_version"] = *input.JavaVersion + } + + if input.LinuxFxVersion != nil { + result["linux_app_framework_version"] = *input.LinuxFxVersion + } + + if input.LocalMySQLEnabled != nil { + result["local_mysql_enabled"] = *input.LocalMySQLEnabled + } + + result["managed_pipeline_mode"] = string(input.ManagedPipelineMode) + + if input.PhpVersion != nil { + result["php_version"] = *input.PhpVersion + } + + if input.PythonVersion != nil { + result["python_version"] = *input.PythonVersion + } + + if input.Use32BitWorkerProcess != nil { + result["use_32_bit_worker_process"] = *input.Use32BitWorkerProcess + } + + if input.WebSocketsEnabled != nil { + result["websockets_enabled"] = *input.WebSocketsEnabled + } + + results = append(results, result) + return results +} + +func expandAppServiceAppSettings(d *schema.ResourceData) *map[string]*string { + input := d.Get("app_settings").(map[string]interface{}) + output := make(map[string]*string, len(input)) + + for k, v := range input { + output[k] = utils.String(v.(string)) + } + + return &output +} + +func expandAppServiceConnectionStrings(d *schema.ResourceData) *map[string]*web.ConnStringValueTypePair { + input := d.Get("connection_string").([]interface{}) + output := make(map[string]*web.ConnStringValueTypePair, len(input)) + + for _, v := range input { + vals := v.(map[string]interface{}) + + csName := vals["name"].(string) + csType := vals["type"].(string) + csValue := vals["value"].(string) + + output[csName] = &web.ConnStringValueTypePair{ + Value: utils.String(csValue), + Type: web.ConnectionStringType(csType), + } + } + + return &output +} + +func flattenAppServiceConnectionStrings(input *map[string]*web.ConnStringValueTypePair) interface{} { + results := make([]interface{}, 0) + + for k, v := range *input { + result := make(map[string]interface{}, 0) + result["name"] = k + result["type"] = string(v.Type) + result["value"] = v.Value + results = append(results, result) } - result = append(result, site_config) - return result + return results } diff --git a/azurerm/resource_arm_app_service_test.go b/azurerm/resource_arm_app_service_test.go index 360ff470f469..3f8432a5b226 100644 --- a/azurerm/resource_arm_app_service_test.go +++ b/azurerm/resource_arm_app_service_test.go @@ -11,6 +11,7 @@ import ( ) func TestAccAzureRMAppService_basic(t *testing.T) { + resourceName := "azurerm_app_service.test" ri := acctest.RandInt() config := testAccAzureRMAppService_basic(ri, testLocation()) @@ -22,16 +23,17 @@ func TestAccAzureRMAppService_basic(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAppServiceExists("azurerm_app_service.test"), + testCheckAzureRMAppServiceExists(resourceName), ), }, }, }) } -func TestAccAzureRMAppService_complete(t *testing.T) { +func TestAccAzureRMAppService_32Bit(t *testing.T) { + resourceName := "azurerm_app_service.test" ri := acctest.RandInt() - config := testAccAzureRMAppService_complete(ri, testLocation()) + config := testAccAzureRMAppService_32Bit(ri, testLocation()) resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, @@ -41,16 +43,18 @@ func TestAccAzureRMAppService_complete(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAppServiceExists("azurerm_app_service.test"), + testCheckAzureRMAppServiceExists(resourceName), + resource.TestCheckResourceAttr(resourceName, "use_32_bit_worker_process", "true"), ), }, }, }) } -func TestAccAzureRMAppService_completeAlwaysOn(t *testing.T) { +func TestAccAzureRMAppService_alwaysOn(t *testing.T) { + resourceName := "azurerm_app_service.test" ri := acctest.RandInt() - config := testAccAzureRMAppService_completeAlwaysOn(ri, testLocation()) + config := testAccAzureRMAppService_alwaysOn(ri, testLocation()) resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, @@ -60,7 +64,550 @@ func TestAccAzureRMAppService_completeAlwaysOn(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAppServiceExists("azurerm_app_service.test"), + testCheckAzureRMAppServiceExists(resourceName), + resource.TestCheckResourceAttr(resourceName, "always_on", "true"), + ), + }, + }, + }) +} + +func TestAccAzureRMAppService_appSettings(t *testing.T) { + resourceName := "azurerm_app_service.test" + ri := acctest.RandInt() + config := testAccAzureRMAppService_appSettings(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, "app_settings.foo", "bar"), + ), + }, + }, + }) +} + +func TestAccAzureRMAppService_clientAffinityEnabled(t *testing.T) { + resourceName := "azurerm_app_service.test" + ri := acctest.RandInt() + config := testAccAzureRMAppService_clientAffinityEnabled(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, "client_affinity_enabled", "true"), + ), + }, + }, + }) +} + +func TestAccAzureRMAppService_connectionStrings(t *testing.T) { + resourceName := "azurerm_app_service.test" + ri := acctest.RandInt() + config := testAccAzureRMAppService_connectionStrings(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, "connection_string.0.name", "Example"), + resource.TestCheckResourceAttr(resourceName, "connection_string.0.value", "some-postgresql-connection-string"), + resource.TestCheckResourceAttr(resourceName, "connection_string.0.type", "PostgreSQL"), + ), + }, + }, + }) +} + +func TestAccAzureRMAppService_defaultDocuments(t *testing.T) { + resourceName := "azurerm_app_service.test" + ri := acctest.RandInt() + config := testAccAzureRMAppService_defaultDocuments(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, "site_config.0.default_documents.0", "first.html"), + resource.TestCheckResourceAttr(resourceName, "site_config.0.default_documents.1", "second.jsp"), + resource.TestCheckResourceAttr(resourceName, "site_config.0.default_documents.2", "third.aspx"), + ), + }, + }, + }) +} + +func TestAccAzureRMAppService_enabled(t *testing.T) { + resourceName := "azurerm_app_service.test" + ri := acctest.RandInt() + config := testAccAzureRMAppService_linuxEnabled(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, "enabled", "false"), + ), + }, + }, + }) +} + +func TestAccAzureRMAppService_linuxDotNetCore(t *testing.T) { + resourceName := "azurerm_app_service.test" + ri := acctest.RandInt() + config := testAccAzureRMAppService_linuxDotNetCore(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, "site_config.0.linux_app_framework_version", "dotnetcore|1.1"), + ), + }, + }, + }) +} + +func TestAccAzureRMAppService_linuxNode(t *testing.T) { + resourceName := "azurerm_app_service.test" + ri := acctest.RandInt() + config := testAccAzureRMAppService_linuxNode(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, "site_config.0.linux_app_framework_version", "node|8.1"), + ), + }, + }, + }) +} + +func TestAccAzureRMAppService_linuxPHP(t *testing.T) { + resourceName := "azurerm_app_service.test" + ri := acctest.RandInt() + config := testAccAzureRMAppService_linuxPHP(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, "site_config.0.linux_app_framework_version", "php|7.0"), + ), + }, + }, + }) +} + +func TestAccAzureRMAppService_linuxRuby(t *testing.T) { + resourceName := "azurerm_app_service.test" + ri := acctest.RandInt() + config := testAccAzureRMAppService_linuxRuby(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, "site_config.0.linux_app_framework_version", "ruby|2.3"), + ), + }, + }, + }) +} + +func TestAccAzureRMAppService_localMySql(t *testing.T) { + resourceName := "azurerm_app_service.test" + ri := acctest.RandInt() + config := testAccAzureRMAppService_localMySql(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, "site_config.0.local_mysql_enabled", "true"), + ), + }, + }, + }) +} + +func TestAccAzureRMAppService_managedPipelineMode(t *testing.T) { + resourceName := "azurerm_app_service.test" + ri := acctest.RandInt() + config := testAccAzureRMAppService_managedPipelineMode(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, "site_config.0.managed_pipeline_mode", "Classic"), + ), + }, + }, + }) +} + +func TestAccAzureRMAppService_reserved(t *testing.T) { + resourceName := "azurerm_app_service.test" + ri := acctest.RandInt() + config := testAccAzureRMAppService_reserved(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, "reserved", "true"), + ), + }, + }, + }) +} + +func TestAccAzureRMAppService_tagsUpdate(t *testing.T) { + resourceName := "azurerm_app_service.test" + ri := acctest.RandInt() + config := testAccAzureRMAppService_tags(ri, testLocation()) + updatedConfig := testAccAzureRMAppService_tagsUpdated(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, "tags.%", "1"), + resource.TestCheckResourceAttr(resourceName, "tags.Hello", "World"), + ), + }, + { + Config: updatedConfig, + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMAppServiceExists(resourceName), + resource.TestCheckResourceAttr(resourceName, "tags.%", "2"), + resource.TestCheckResourceAttr(resourceName, "tags.Hello", "World"), + resource.TestCheckResourceAttr(resourceName, "tags.Terraform", "AcceptanceTests"), + ), + }, + }, + }) +} + +func TestAccAzureRMAppService_linuxUpdate(t *testing.T) { + resourceName := "azurerm_app_service.test" + ri := acctest.RandInt() + config := testAccAzureRMAppService_linuxDotNetCore(ri, testLocation()) + updatedConfig := testAccAzureRMAppService_linuxRuby(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, "site_config.0.linux_app_framework_version", "dotnetcore|1.1"), + ), + }, + { + Config: updatedConfig, + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMAppServiceExists(resourceName), + resource.TestCheckResourceAttr(resourceName, "site_config.0.linux_app_framework_version", "ruby|2.3"), + ), + }, + }, + }) +} + +func TestAccAzureRMAppService_windowsDotNet2(t *testing.T) { + resourceName := "azurerm_app_service.test" + ri := acctest.RandInt() + config := testAccAzureRMAppService_windowsDotNet(ri, testLocation(), "v2.0") + + 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, "site_config.0.dotnet_framework_version", "v2.0"), + ), + }, + }, + }) +} + +func TestAccAzureRMAppService_windowsDotNet4(t *testing.T) { + resourceName := "azurerm_app_service.test" + ri := acctest.RandInt() + config := testAccAzureRMAppService_windowsDotNet(ri, testLocation(), "v4.0") + + 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, "site_config.0.dotnet_framework_version", "v4.0"), + ), + }, + }, + }) +} + +func TestAccAzureRMAppService_windowsDotNetUpdate(t *testing.T) { + resourceName := "azurerm_app_service.test" + ri := acctest.RandInt() + config := testAccAzureRMAppService_windowsDotNet(ri, testLocation(), "v2.0") + updatedConfig := testAccAzureRMAppService_windowsDotNet(ri, testLocation(), "v4.0") + + 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, "site_config.0.dotnet_framework_version", "v2.0"), + ), + }, + { + Config: updatedConfig, + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMAppServiceExists(resourceName), + resource.TestCheckResourceAttr(resourceName, "site_config.0.dotnet_framework_version", "v4.0"), + ), + }, + }, + }) +} + +func TestAccAzureRMAppService_windowsJava7Jetty(t *testing.T) { + resourceName := "azurerm_app_service.test" + ri := acctest.RandInt() + config := testAccAzureRMAppService_windowsJava(ri, testLocation(), "1.7", "Jetty", "9.3") + + 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, "site_config.0.java_version", "1.7"), + resource.TestCheckResourceAttr(resourceName, "site_config.0.java_container", "Jetty"), + resource.TestCheckResourceAttr(resourceName, "site_config.0.java_container_version", "9.3"), + ), + }, + }, + }) +} + +func TestAccAzureRMAppService_windowsJava8Jetty(t *testing.T) { + resourceName := "azurerm_app_service.test" + ri := acctest.RandInt() + config := testAccAzureRMAppService_windowsJava(ri, testLocation(), "1.8", "Jetty", "9.3") + + 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, "site_config.0.java_version", "1.8"), + resource.TestCheckResourceAttr(resourceName, "site_config.0.java_container", "Jetty"), + resource.TestCheckResourceAttr(resourceName, "site_config.0.java_container_version", "9.3"), + ), + }, + }, + }) +} +func TestAccAzureRMAppService_windowsJava7Tomcat(t *testing.T) { + resourceName := "azurerm_app_service.test" + ri := acctest.RandInt() + config := testAccAzureRMAppService_windowsJava(ri, testLocation(), "1.7", "TomCat", "9.0") + + 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, "site_config.0.java_version", "1.7"), + resource.TestCheckResourceAttr(resourceName, "site_config.0.java_container", "TomCat"), + resource.TestCheckResourceAttr(resourceName, "site_config.0.java_container_version", "9.0"), + ), + }, + }, + }) +} + +func TestAccAzureRMAppService_windowsJava8Tomcat(t *testing.T) { + resourceName := "azurerm_app_service.test" + ri := acctest.RandInt() + config := testAccAzureRMAppService_windowsJava(ri, testLocation(), "1.8", "TomCat", "9.0") + + 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, "site_config.0.java_version", "1.8"), + resource.TestCheckResourceAttr(resourceName, "site_config.0.java_container", "TomCat"), + resource.TestCheckResourceAttr(resourceName, "site_config.0.java_container_version", "9.0"), + ), + }, + }, + }) +} + +func TestAccAzureRMAppService_windowsPHP7(t *testing.T) { + resourceName := "azurerm_app_service.test" + ri := acctest.RandInt() + config := testAccAzureRMAppService_windowsPHP(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, "site_config.0.php_version", "7.1"), + ), + }, + }, + }) +} + +func TestAccAzureRMAppService_windowsPython(t *testing.T) { + resourceName := "azurerm_app_service.test" + ri := acctest.RandInt() + config := testAccAzureRMAppService_windowsPython(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, "site_config.0.python_version", "3.4"), + ), + }, + }, + }) +} + +func TestAccAzureRMAppService_webSockets(t *testing.T) { + resourceName := "azurerm_app_service.test" + ri := acctest.RandInt() + config := testAccAzureRMAppService_webSockets(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, "site_config.0.websockets_enabled", "true"), ), }, }, @@ -68,80 +615,555 @@ func TestAccAzureRMAppService_completeAlwaysOn(t *testing.T) { } func testCheckAzureRMAppServiceDestroy(s *terraform.State) error { - conn := testAccProvider.Meta().(*ArmClient).appsClient + client := testAccProvider.Meta().(*ArmClient).appServicesClient + + for _, rs := range s.RootModule().Resources { + if rs.Type != "azurerm_app_service" { + continue + } + + name := rs.Primary.Attributes["name"] + resourceGroup := rs.Primary.Attributes["resource_group_name"] + + resp, err := client.Get(resourceGroup, name) + + if err != nil { + if utils.ResponseWasNotFound(resp.Response) { + return nil + } + return err + } + + return fmt.Errorf("App Service still exists:\n%#v", resp) + } + + return nil +} + +func testCheckAzureRMAppServiceExists(name string) resource.TestCheckFunc { + return func(s *terraform.State) error { + // Ensure we have enough information in state to look up in API + rs, ok := s.RootModule().Resources[name] + if !ok { + return fmt.Errorf("Not found: %s", name) + } + + appServiceName := rs.Primary.Attributes["name"] + resourceGroup, hasResourceGroup := rs.Primary.Attributes["resource_group_name"] + if !hasResourceGroup { + return fmt.Errorf("Bad: no resource group found in state for App Service: %s", appServiceName) + } + + client := testAccProvider.Meta().(*ArmClient).appServicesClient + + resp, err := client.Get(resourceGroup, appServiceName) + if err != nil { + if utils.ResponseWasNotFound(resp.Response) { + return fmt.Errorf("Bad: App Service %q (resource group: %q) does not exist", appServiceName, resourceGroup) + } + + return fmt.Errorf("Bad: Get on appServicesClient: %+v", err) + } + + return nil + } +} + +func testAccAzureRMAppService_basic(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_alwaysOn(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}" + + site_config { + always_on = true + } +} +`, rInt, location, rInt, rInt) +} + +func testAccAzureRMAppService_32Bit(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}" + + site_config { + use_32_bit_worker_process = true + } +} +`, rInt, location, rInt, rInt) +} + +func testAccAzureRMAppService_appSettings(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}" + + app_settings { + "foo" = "bar" + } +} +`, rInt, location, rInt, rInt) +} + +func testAccAzureRMAppService_clientAffinityEnabled(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_affinity_enabled = true +} +`, rInt, location, rInt, rInt) +} + +func testAccAzureRMAppService_connectionStrings(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}" + + connection_string { + name = "Example" + value = "some-postgresql-connection-string" + type = "PostgreSQL" + } +} +`, rInt, location, rInt, rInt) +} + +func testAccAzureRMAppService_defaultDocuments(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}" + + site_config { + default_documents = [ + "first.html", + "second.jsp", + "third.aspx", + ] + } +} +`, rInt, location, rInt, rInt) +} + +func testAccAzureRMAppService_linuxDotNetCore(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 = "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}" + + site_config { + linux_app_framework_version = "dotnetcore|1.1" + } +} +`, rInt, location, rInt, rInt) +} + +func testAccAzureRMAppService_linuxNode(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 = "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}" + + site_config { + linux_app_framework_version = "node|8.1" + } +} +`, rInt, location, rInt, rInt) +} + +func testAccAzureRMAppService_linuxPHP(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 = "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}" + + site_config { + linux_app_framework_version = "php|7.0" + } +} +`, rInt, location, rInt, rInt) +} + +func testAccAzureRMAppService_linuxRuby(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 = "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}" - for _, rs := range s.RootModule().Resources { - if rs.Type != "azurerm_app_service" { - continue - } + site_config { + linux_app_framework_version = "ruby|2.3" + } +} +`, rInt, location, rInt, rInt) +} - name := rs.Primary.Attributes["name"] - resourceGroup := rs.Primary.Attributes["resource_group_name"] +func testAccAzureRMAppService_linuxEnabled(rInt int, location string) string { + return fmt.Sprintf(` +resource "azurerm_resource_group" "test" { + name = "acctestRG-%d" + location = "%s" +} - resp, err := conn.Get(resourceGroup, name) +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" - if err != nil { - if utils.ResponseWasNotFound(resp.Response) { - return nil - } - return err - } + sku { + tier = "Standard" + size = "S1" + } +} - return fmt.Errorf("App Service still exists:\n%#v", resp) - } +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}" + enabled = false +} +`, rInt, location, rInt, rInt) +} - return nil +func testAccAzureRMAppService_localMySql(rInt int, location string) string { + return fmt.Sprintf(` +resource "azurerm_resource_group" "test" { + name = "acctestRG-%d" + location = "%s" } -func testCheckAzureRMAppServiceExists(name string) resource.TestCheckFunc { - return func(s *terraform.State) error { - // Ensure we have enough information in state to look up in API - rs, ok := s.RootModule().Resources[name] - if !ok { - return fmt.Errorf("Not found: %s", name) - } +resource "azurerm_app_service_plan" "test" { + name = "acctestASP-%d" + location = "${azurerm_resource_group.test.location}" + resource_group_name = "${azurerm_resource_group.test.name}" - appServiceName := rs.Primary.Attributes["name"] - resourceGroup, hasResourceGroup := rs.Primary.Attributes["resource_group_name"] - if !hasResourceGroup { - return fmt.Errorf("Bad: no resource group found in state for App Service: %s", appServiceName) - } + sku { + tier = "Standard" + size = "S1" + } +} - conn := testAccProvider.Meta().(*ArmClient).appsClient +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}" - resp, err := conn.Get(resourceGroup, appServiceName) - if err != nil { - if utils.ResponseWasNotFound(resp.Response) { - return fmt.Errorf("Bad: App Service %q (resource group: %q) does not exist", appServiceName, resourceGroup) - } + site_config { + local_mysql_enabled = true + } +} +`, rInt, location, rInt, rInt) +} - return fmt.Errorf("Bad: Get on appsClient: %+v", err) - } +func testAccAzureRMAppService_managedPipelineMode(rInt int, location string) string { + return fmt.Sprintf(` +resource "azurerm_resource_group" "test" { + name = "acctestRG-%d" + location = "%s" +} - return nil - } +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" + } } -func testAccAzureRMAppService_basic(rInt int, location string) string { +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}" + + site_config { + managed_pipeline_mode = "Classic" + } +} +`, rInt, location, rInt, rInt) +} + +func testAccAzureRMAppService_reserved(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}" + reserved = true +} +`, rInt, location, rInt, rInt) +} - tags { - environment = "Production" - } +func testAccAzureRMAppService_tags(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}" + + tags { + "Hello" = "World" + } } -`, rInt, location, rInt) +`, rInt, location, rInt, rInt) } -func testAccAzureRMAppService_complete(rInt int, location string) string { +func testAccAzureRMAppService_tagsUpdated(rInt int, location string) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -163,16 +1185,17 @@ 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}" - site_config { - app_service_plan_id = "${azurerm_app_service_plan.test.id}" - always_on = false - } + tags { + "Hello" = "World" + "Terraform" = "AcceptanceTests" + } } `, rInt, location, rInt, rInt) } -func testAccAzureRMAppService_completeAlwaysOn(rInt int, location string) string { +func testAccAzureRMAppService_windowsDotNet(rInt int, location, version string) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -194,11 +1217,137 @@ 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}" - site_config { - app_service_plan_id = "${azurerm_app_service_plan.test.id}" - always_on = true - } + site_config { + dotnet_framework_version = "%s" + } +} +`, rInt, location, rInt, rInt, version) +} + +func testAccAzureRMAppService_windowsJava(rInt int, location, javaVersion, container, containerVersion 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}" + + site_config { + java_version = "%s" + java_container = "%s" + java_container_version = "%s" + } +} +`, rInt, location, rInt, rInt, javaVersion, container, containerVersion) +} + +func testAccAzureRMAppService_windowsPHP(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}" + + site_config { + php_version = "7.1" + } +} +`, rInt, location, rInt, rInt) +} + +func testAccAzureRMAppService_windowsPython(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}" + + site_config { + python_version = "3.4" + } +} +`, rInt, location, rInt, rInt) +} + +func testAccAzureRMAppService_webSockets(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}" + + site_config { + websockets_enabled = true + } } `, rInt, location, rInt, rInt) } From 5b0cf5c31cd58ea46db87adca4994912ccfcf859 Mon Sep 17 00:00:00 2001 From: tombuildsstuff Date: Fri, 15 Sep 2017 17:41:04 +0100 Subject: [PATCH 19/31] Reserved requires an App Service Environment --- azurerm/resource_arm_app_service.go | 13 ------ azurerm/resource_arm_app_service_test.go | 53 +----------------------- 2 files changed, 2 insertions(+), 64 deletions(-) diff --git a/azurerm/resource_arm_app_service.go b/azurerm/resource_arm_app_service.go index fbe326035e06..535b3f186185 100644 --- a/azurerm/resource_arm_app_service.go +++ b/azurerm/resource_arm_app_service.go @@ -191,13 +191,6 @@ func resourceArmAppService() *schema.Resource { ForceNew: true, // due to a bug in the Azure API :( }, - "reserved": { - Type: schema.TypeBool, - Optional: true, - Computed: true, - ForceNew: true, // due to a bug in the Azure API :( - }, - "app_settings": { Type: schema.TypeMap, Optional: true, @@ -275,11 +268,6 @@ func resourceArmAppServiceCreate(d *schema.ResourceData, meta interface{}) error siteEnvelope.SiteProperties.ClientAffinityEnabled = utils.Bool(enabled) } - if v, ok := d.GetOk("reserved"); ok { - reserved := v.(bool) - siteEnvelope.SiteProperties.Reserved = utils.Bool(reserved) - } - // NOTE: these seem like sensible defaults, in lieu of any better documentation. skipDNSRegistration := false forceDNSRegistration := false @@ -418,7 +406,6 @@ 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("reserved", props.Reserved) } d.Set("app_settings", appSettingsResp.Properties) diff --git a/azurerm/resource_arm_app_service_test.go b/azurerm/resource_arm_app_service_test.go index 3f8432a5b226..56ce81c70479 100644 --- a/azurerm/resource_arm_app_service_test.go +++ b/azurerm/resource_arm_app_service_test.go @@ -44,7 +44,7 @@ func TestAccAzureRMAppService_32Bit(t *testing.T) { Config: config, Check: resource.ComposeTestCheckFunc( testCheckAzureRMAppServiceExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "use_32_bit_worker_process", "true"), + resource.TestCheckResourceAttr(resourceName, "site_config.0.use_32_bit_worker_process", "true"), ), }, }, @@ -65,7 +65,7 @@ func TestAccAzureRMAppService_alwaysOn(t *testing.T) { Config: config, Check: resource.ComposeTestCheckFunc( testCheckAzureRMAppServiceExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "always_on", "true"), + resource.TestCheckResourceAttr(resourceName, "site_config.0.always_on", "true"), ), }, }, @@ -307,27 +307,6 @@ func TestAccAzureRMAppService_managedPipelineMode(t *testing.T) { }) } -func TestAccAzureRMAppService_reserved(t *testing.T) { - resourceName := "azurerm_app_service.test" - ri := acctest.RandInt() - config := testAccAzureRMAppService_reserved(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, "reserved", "true"), - ), - }, - }, - }) -} - func TestAccAzureRMAppService_tagsUpdate(t *testing.T) { resourceName := "azurerm_app_service.test" ri := acctest.RandInt() @@ -1104,34 +1083,6 @@ resource "azurerm_app_service" "test" { `, rInt, location, rInt, rInt) } -func testAccAzureRMAppService_reserved(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}" - reserved = true -} -`, rInt, location, rInt, rInt) -} - func testAccAzureRMAppService_tags(rInt int, location string) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { From 0fc5a966dbcee43656b72f97f3aec6d7ee5464ed Mon Sep 17 00:00:00 2001 From: tombuildsstuff Date: Mon, 18 Sep 2017 11:16:23 +0100 Subject: [PATCH 20/31] Fixing the Java apps --- azurerm/resource_arm_app_service.go | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/azurerm/resource_arm_app_service.go b/azurerm/resource_arm_app_service.go index 535b3f186185..8ca213fe253a 100644 --- a/azurerm/resource_arm_app_service.go +++ b/azurerm/resource_arm_app_service.go @@ -51,7 +51,7 @@ func resourceArmAppService() *schema.Resource { "always_on": { Type: schema.TypeBool, Optional: true, - Computed: true, + Default: false, }, "default_documents": { @@ -75,7 +75,6 @@ func resourceArmAppService() *schema.Resource { "java_version": { Type: schema.TypeString, Optional: true, - Computed: true, ValidateFunc: validation.StringInSlice([]string{ "1.7", "1.8", @@ -85,7 +84,6 @@ func resourceArmAppService() *schema.Resource { "java_container": { Type: schema.TypeString, Optional: true, - Computed: true, ValidateFunc: validation.StringInSlice([]string{ "JETTY", "TOMCAT", @@ -96,7 +94,6 @@ func resourceArmAppService() *schema.Resource { "java_container_version": { Type: schema.TypeString, Optional: true, - Computed: true, }, "linux_app_framework_version": { @@ -143,7 +140,6 @@ func resourceArmAppService() *schema.Resource { "php_version": { Type: schema.TypeString, Optional: true, - Computed: true, ValidateFunc: validation.StringInSlice([]string{ "5.5", "5.6", @@ -155,7 +151,6 @@ func resourceArmAppService() *schema.Resource { "python_version": { Type: schema.TypeString, Optional: true, - Computed: true, ValidateFunc: validation.StringInSlice([]string{ "2.7", "3.4", @@ -548,6 +543,14 @@ func flattenAppServiceSiteConfig(input *web.SiteConfig) []interface{} { result["java_version"] = *input.JavaVersion } + if input.JavaContainer != nil { + result["java_container"] = *input.JavaContainer + } + + if input.JavaContainerVersion != nil { + result["java_container_version"] = *input.JavaContainerVersion + } + if input.LinuxFxVersion != nil { result["linux_app_framework_version"] = *input.LinuxFxVersion } From bd30db18be8fe4fd6704c3fcc467eed4a2f2aac8 Mon Sep 17 00:00:00 2001 From: tombuildsstuff Date: Mon, 18 Sep 2017 12:03:28 +0100 Subject: [PATCH 21/31] Adding tests for remote debugging --- azurerm/resource_arm_app_service.go | 45 +++++++++++++++--- azurerm/resource_arm_app_service_test.go | 58 ++++++++++++++++++++++++ 2 files changed, 97 insertions(+), 6 deletions(-) diff --git a/azurerm/resource_arm_app_service.go b/azurerm/resource_arm_app_service.go index 8ca213fe253a..5be39a7d55e4 100644 --- a/azurerm/resource_arm_app_service.go +++ b/azurerm/resource_arm_app_service.go @@ -57,7 +57,6 @@ func resourceArmAppService() *schema.Resource { "default_documents": { Type: schema.TypeList, Optional: true, - Computed: true, Elem: &schema.Schema{Type: schema.TypeString}, }, @@ -157,6 +156,24 @@ func resourceArmAppService() *schema.Resource { }, false), }, + "remote_debugging_enabled": { + Type: schema.TypeBool, + Optional: true, + Default: false, + }, + + "remote_debugging_version": { + Type: schema.TypeString, + Optional: true, + ValidateFunc: validation.StringInSlice([]string{ + "VS2012", + "VS2013", + "VS2015", + "VS2017", + }, true), + DiffSuppressFunc: ignoreCaseDiffSuppressFunc, + }, + "use_32_bit_worker_process": { Type: schema.TypeBool, Optional: true, @@ -302,7 +319,7 @@ func resourceArmAppServiceCreate(d *schema.ResourceData, meta interface{}) error d.SetId(*read.ID) - return resourceArmAppServiceRead(d, meta) + return resourceArmAppServiceUpdate(d, meta) } func resourceArmAppServiceUpdate(d *schema.ResourceData, meta interface{}) error { @@ -375,22 +392,22 @@ func resourceArmAppServiceRead(d *schema.ResourceData, meta interface{}) error { d.SetId("") return nil } - return fmt.Errorf("Error making Read request on AzureRM App Service %s: %+v", name, err) + return fmt.Errorf("Error making Read request on AzureRM App Service %q: %+v", name, err) } configResp, err := client.GetConfiguration(resGroup, name) if err != nil { - return fmt.Errorf("Error making Read request on AzureRM App Service Configuration %s: %+v", name, err) + return fmt.Errorf("Error making Read request on AzureRM App Service Configuration %q: %+v", name, err) } appSettingsResp, err := client.ListApplicationSettings(resGroup, name) if err != nil { - return fmt.Errorf("Error making Read request on AzureRM App Service AppSettings %s: %+v", name, err) + return fmt.Errorf("Error making Read request on AzureRM App Service AppSettings %q: %+v", name, err) } connectionStringsResp, err := client.ListConnectionStrings(resGroup, name) if err != nil { - return fmt.Errorf("Error making Read request on AzureRM App Service ConnectionStrings %s: %+v", name, err) + return fmt.Errorf("Error making Read request on AzureRM App Service ConnectionStrings %q: %+v", name, err) } d.Set("name", name) @@ -502,6 +519,14 @@ func expandAppServiceSiteConfig(d *schema.ResourceData) web.SiteConfig { siteConfig.PythonVersion = utils.String(v.(string)) } + if v, ok := config["remote_debugging_enabled"]; ok { + siteConfig.RemoteDebuggingEnabled = utils.Bool(v.(bool)) + } + + if v, ok := config["remote_debugging_version"]; ok { + siteConfig.RemoteDebuggingVersion = utils.String(v.(string)) + } + if v, ok := config["use_32_bit_worker_process"]; ok { siteConfig.Use32BitWorkerProcess = utils.Bool(v.(bool)) } @@ -569,6 +594,14 @@ func flattenAppServiceSiteConfig(input *web.SiteConfig) []interface{} { result["python_version"] = *input.PythonVersion } + if input.RemoteDebuggingEnabled != nil { + result["remote_debugging_enabled"] = *input.RemoteDebuggingEnabled + } + + if input.RemoteDebuggingVersion != nil { + result["remote_debugging_version"] = *input.RemoteDebuggingVersion + } + if input.Use32BitWorkerProcess != nil { result["use_32_bit_worker_process"] = *input.Use32BitWorkerProcess } diff --git a/azurerm/resource_arm_app_service_test.go b/azurerm/resource_arm_app_service_test.go index 56ce81c70479..05f67e3c5085 100644 --- a/azurerm/resource_arm_app_service_test.go +++ b/azurerm/resource_arm_app_service_test.go @@ -368,6 +368,28 @@ func TestAccAzureRMAppService_linuxUpdate(t *testing.T) { }) } +func TestAccAzureRMAppService_remoteDebugging(t *testing.T) { + resourceName := "azurerm_app_service.test" + ri := acctest.RandInt() + config := testAccAzureRMAppService_remoteDebugging(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, "site_config.0.remote_debugging_enabled", "true"), + resource.TestCheckResourceAttr(resourceName, "site_config.0.remote_debugging_version", "VS2015"), + ), + }, + }, + }) +} + func TestAccAzureRMAppService_windowsDotNet2(t *testing.T) { resourceName := "azurerm_app_service.test" ri := acctest.RandInt() @@ -1083,6 +1105,42 @@ resource "azurerm_app_service" "test" { `, rInt, location, rInt, rInt) } +func testAccAzureRMAppService_remoteDebugging(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}" + + site_config { + remote_debugging_enabled = true + remote_debugging_version = "VS2015" + } + + tags { + "Hello" = "World" + } +} +`, rInt, location, rInt, rInt) +} + func testAccAzureRMAppService_tags(rInt int, location string) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { From e43b775acb1680c10d8c7abb6547369fd82b034d Mon Sep 17 00:00:00 2001 From: tombuildsstuff Date: Mon, 18 Sep 2017 12:08:35 +0100 Subject: [PATCH 22/31] remote debugging version needs to be computed --- azurerm/resource_arm_app_service.go | 1 + 1 file changed, 1 insertion(+) diff --git a/azurerm/resource_arm_app_service.go b/azurerm/resource_arm_app_service.go index 5be39a7d55e4..ecbac98492f2 100644 --- a/azurerm/resource_arm_app_service.go +++ b/azurerm/resource_arm_app_service.go @@ -165,6 +165,7 @@ func resourceArmAppService() *schema.Resource { "remote_debugging_version": { Type: schema.TypeString, Optional: true, + Computed: true, ValidateFunc: validation.StringInSlice([]string{ "VS2012", "VS2013", From f60e2280568094ffc36398d88c92dd8377554ace Mon Sep 17 00:00:00 2001 From: tombuildsstuff Date: Mon, 18 Sep 2017 12:17:16 +0100 Subject: [PATCH 23/31] Fixing the tests --- azurerm/resource_arm_app_service_test.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/azurerm/resource_arm_app_service_test.go b/azurerm/resource_arm_app_service_test.go index 05f67e3c5085..5da059484ac0 100644 --- a/azurerm/resource_arm_app_service_test.go +++ b/azurerm/resource_arm_app_service_test.go @@ -509,7 +509,7 @@ func TestAccAzureRMAppService_windowsJava8Jetty(t *testing.T) { func TestAccAzureRMAppService_windowsJava7Tomcat(t *testing.T) { resourceName := "azurerm_app_service.test" ri := acctest.RandInt() - config := testAccAzureRMAppService_windowsJava(ri, testLocation(), "1.7", "TomCat", "9.0") + config := testAccAzureRMAppService_windowsJava(ri, testLocation(), "1.7", "TOMCAT", "9.0") resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, @@ -521,7 +521,7 @@ func TestAccAzureRMAppService_windowsJava7Tomcat(t *testing.T) { Check: resource.ComposeTestCheckFunc( testCheckAzureRMAppServiceExists(resourceName), resource.TestCheckResourceAttr(resourceName, "site_config.0.java_version", "1.7"), - resource.TestCheckResourceAttr(resourceName, "site_config.0.java_container", "TomCat"), + resource.TestCheckResourceAttr(resourceName, "site_config.0.java_container", "TOMCAT"), resource.TestCheckResourceAttr(resourceName, "site_config.0.java_container_version", "9.0"), ), }, @@ -532,7 +532,7 @@ func TestAccAzureRMAppService_windowsJava7Tomcat(t *testing.T) { func TestAccAzureRMAppService_windowsJava8Tomcat(t *testing.T) { resourceName := "azurerm_app_service.test" ri := acctest.RandInt() - config := testAccAzureRMAppService_windowsJava(ri, testLocation(), "1.8", "TomCat", "9.0") + config := testAccAzureRMAppService_windowsJava(ri, testLocation(), "1.8", "TOMCAT", "9.0") resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, @@ -544,7 +544,7 @@ func TestAccAzureRMAppService_windowsJava8Tomcat(t *testing.T) { Check: resource.ComposeTestCheckFunc( testCheckAzureRMAppServiceExists(resourceName), resource.TestCheckResourceAttr(resourceName, "site_config.0.java_version", "1.8"), - resource.TestCheckResourceAttr(resourceName, "site_config.0.java_container", "TomCat"), + resource.TestCheckResourceAttr(resourceName, "site_config.0.java_container", "TOMCAT"), resource.TestCheckResourceAttr(resourceName, "site_config.0.java_container_version", "9.0"), ), }, From 83b8a619c0dd0ac111110eaf7a0c04e718c9d867 Mon Sep 17 00:00:00 2001 From: tombuildsstuff Date: Mon, 18 Sep 2017 12:21:37 +0100 Subject: [PATCH 24/31] Fixing the jetty tests --- azurerm/resource_arm_app_service_test.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/azurerm/resource_arm_app_service_test.go b/azurerm/resource_arm_app_service_test.go index 5da059484ac0..8d07faa211a6 100644 --- a/azurerm/resource_arm_app_service_test.go +++ b/azurerm/resource_arm_app_service_test.go @@ -464,7 +464,7 @@ func TestAccAzureRMAppService_windowsDotNetUpdate(t *testing.T) { func TestAccAzureRMAppService_windowsJava7Jetty(t *testing.T) { resourceName := "azurerm_app_service.test" ri := acctest.RandInt() - config := testAccAzureRMAppService_windowsJava(ri, testLocation(), "1.7", "Jetty", "9.3") + config := testAccAzureRMAppService_windowsJava(ri, testLocation(), "1.7", "JETTY", "9.3") resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, @@ -476,7 +476,7 @@ func TestAccAzureRMAppService_windowsJava7Jetty(t *testing.T) { Check: resource.ComposeTestCheckFunc( testCheckAzureRMAppServiceExists(resourceName), resource.TestCheckResourceAttr(resourceName, "site_config.0.java_version", "1.7"), - resource.TestCheckResourceAttr(resourceName, "site_config.0.java_container", "Jetty"), + resource.TestCheckResourceAttr(resourceName, "site_config.0.java_container", "JETTY"), resource.TestCheckResourceAttr(resourceName, "site_config.0.java_container_version", "9.3"), ), }, @@ -487,7 +487,7 @@ func TestAccAzureRMAppService_windowsJava7Jetty(t *testing.T) { func TestAccAzureRMAppService_windowsJava8Jetty(t *testing.T) { resourceName := "azurerm_app_service.test" ri := acctest.RandInt() - config := testAccAzureRMAppService_windowsJava(ri, testLocation(), "1.8", "Jetty", "9.3") + config := testAccAzureRMAppService_windowsJava(ri, testLocation(), "1.8", "JETTY", "9.3") resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, @@ -499,7 +499,7 @@ func TestAccAzureRMAppService_windowsJava8Jetty(t *testing.T) { Check: resource.ComposeTestCheckFunc( testCheckAzureRMAppServiceExists(resourceName), resource.TestCheckResourceAttr(resourceName, "site_config.0.java_version", "1.8"), - resource.TestCheckResourceAttr(resourceName, "site_config.0.java_container", "Jetty"), + resource.TestCheckResourceAttr(resourceName, "site_config.0.java_container", "JETTY"), resource.TestCheckResourceAttr(resourceName, "site_config.0.java_container_version", "9.3"), ), }, From 7dd051d0fe345f7c3ce8b0d07b42444dc813d042 Mon Sep 17 00:00:00 2001 From: tombuildsstuff Date: Mon, 18 Sep 2017 12:51:49 +0100 Subject: [PATCH 25/31] Removing linux support for the moment --- azurerm/resource_arm_app_service.go | 32 --- azurerm/resource_arm_app_service_test.go | 248 +---------------------- 2 files changed, 3 insertions(+), 277 deletions(-) diff --git a/azurerm/resource_arm_app_service.go b/azurerm/resource_arm_app_service.go index ecbac98492f2..af0ce32dbc98 100644 --- a/azurerm/resource_arm_app_service.go +++ b/azurerm/resource_arm_app_service.go @@ -95,30 +95,6 @@ func resourceArmAppService() *schema.Resource { Optional: true, }, - "linux_app_framework_version": { - Type: schema.TypeString, - Optional: true, - Computed: true, - // TODO: should this be ForceNew? - ValidateFunc: validation.StringInSlice([]string{ - "dotnetcore|1.0", - "dotnetcore|1.1", - "node|4.4", - "node|4.5", - "node|6.2", - "node|6.6", - "node|6.9", - "node|6.10", - "node|6.11", - "node|8.0", - "node|8.1", - "php|5.6", - "php|7.0", - "ruby|2.3", - }, true), - DiffSuppressFunc: ignoreCaseDiffSuppressFunc, - }, - "local_mysql_enabled": { Type: schema.TypeBool, Optional: true, @@ -500,10 +476,6 @@ func expandAppServiceSiteConfig(d *schema.ResourceData) web.SiteConfig { siteConfig.JavaContainerVersion = utils.String(v.(string)) } - if v, ok := config["linux_app_framework_version"]; ok { - siteConfig.LinuxFxVersion = utils.String(v.(string)) - } - if v, ok := config["local_mysql_enabled"]; ok { siteConfig.LocalMySQLEnabled = utils.Bool(v.(bool)) } @@ -577,10 +549,6 @@ func flattenAppServiceSiteConfig(input *web.SiteConfig) []interface{} { result["java_container_version"] = *input.JavaContainerVersion } - if input.LinuxFxVersion != nil { - result["linux_app_framework_version"] = *input.LinuxFxVersion - } - if input.LocalMySQLEnabled != nil { result["local_mysql_enabled"] = *input.LocalMySQLEnabled } diff --git a/azurerm/resource_arm_app_service_test.go b/azurerm/resource_arm_app_service_test.go index 8d07faa211a6..0a15e47f23f9 100644 --- a/azurerm/resource_arm_app_service_test.go +++ b/azurerm/resource_arm_app_service_test.go @@ -163,7 +163,7 @@ func TestAccAzureRMAppService_defaultDocuments(t *testing.T) { func TestAccAzureRMAppService_enabled(t *testing.T) { resourceName := "azurerm_app_service.test" ri := acctest.RandInt() - config := testAccAzureRMAppService_linuxEnabled(ri, testLocation()) + config := testAccAzureRMAppService_enabled(ri, testLocation()) resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, @@ -181,90 +181,6 @@ func TestAccAzureRMAppService_enabled(t *testing.T) { }) } -func TestAccAzureRMAppService_linuxDotNetCore(t *testing.T) { - resourceName := "azurerm_app_service.test" - ri := acctest.RandInt() - config := testAccAzureRMAppService_linuxDotNetCore(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, "site_config.0.linux_app_framework_version", "dotnetcore|1.1"), - ), - }, - }, - }) -} - -func TestAccAzureRMAppService_linuxNode(t *testing.T) { - resourceName := "azurerm_app_service.test" - ri := acctest.RandInt() - config := testAccAzureRMAppService_linuxNode(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, "site_config.0.linux_app_framework_version", "node|8.1"), - ), - }, - }, - }) -} - -func TestAccAzureRMAppService_linuxPHP(t *testing.T) { - resourceName := "azurerm_app_service.test" - ri := acctest.RandInt() - config := testAccAzureRMAppService_linuxPHP(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, "site_config.0.linux_app_framework_version", "php|7.0"), - ), - }, - }, - }) -} - -func TestAccAzureRMAppService_linuxRuby(t *testing.T) { - resourceName := "azurerm_app_service.test" - ri := acctest.RandInt() - config := testAccAzureRMAppService_linuxRuby(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, "site_config.0.linux_app_framework_version", "ruby|2.3"), - ), - }, - }, - }) -} - func TestAccAzureRMAppService_localMySql(t *testing.T) { resourceName := "azurerm_app_service.test" ri := acctest.RandInt() @@ -339,35 +255,6 @@ func TestAccAzureRMAppService_tagsUpdate(t *testing.T) { }) } -func TestAccAzureRMAppService_linuxUpdate(t *testing.T) { - resourceName := "azurerm_app_service.test" - ri := acctest.RandInt() - config := testAccAzureRMAppService_linuxDotNetCore(ri, testLocation()) - updatedConfig := testAccAzureRMAppService_linuxRuby(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, "site_config.0.linux_app_framework_version", "dotnetcore|1.1"), - ), - }, - { - Config: updatedConfig, - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAppServiceExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "site_config.0.linux_app_framework_version", "ruby|2.3"), - ), - }, - }, - }) -} - func TestAccAzureRMAppService_remoteDebugging(t *testing.T) { resourceName := "azurerm_app_service.test" ri := acctest.RandInt() @@ -886,135 +773,7 @@ resource "azurerm_app_service" "test" { `, rInt, location, rInt, rInt) } -func testAccAzureRMAppService_linuxDotNetCore(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 = "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}" - - site_config { - linux_app_framework_version = "dotnetcore|1.1" - } -} -`, rInt, location, rInt, rInt) -} - -func testAccAzureRMAppService_linuxNode(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 = "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}" - - site_config { - linux_app_framework_version = "node|8.1" - } -} -`, rInt, location, rInt, rInt) -} - -func testAccAzureRMAppService_linuxPHP(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 = "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}" - - site_config { - linux_app_framework_version = "php|7.0" - } -} -`, rInt, location, rInt, rInt) -} - -func testAccAzureRMAppService_linuxRuby(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 = "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}" - - site_config { - linux_app_framework_version = "ruby|2.3" - } -} -`, rInt, location, rInt, rInt) -} - -func testAccAzureRMAppService_linuxEnabled(rInt int, location string) string { +func testAccAzureRMAppService_enabled(rInt int, location string) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -1025,7 +784,6 @@ 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 = "Standard" @@ -1038,7 +796,7 @@ resource "azurerm_app_service" "test" { location = "${azurerm_resource_group.test.location}" resource_group_name = "${azurerm_resource_group.test.name}" app_service_plan_id = "${azurerm_app_service_plan.test.id}" - enabled = false + enabled = false } `, rInt, location, rInt, rInt) } From 8e3ac2eddc66769050a80f342efb63bd8355b780 Mon Sep 17 00:00:00 2001 From: tombuildsstuff Date: Mon, 18 Sep 2017 13:05:26 +0100 Subject: [PATCH 26/31] Adding import tests --- azurerm/import_arm_app_service_test.go | 449 ++++++++++++++++++++++++- 1 file changed, 441 insertions(+), 8 deletions(-) diff --git a/azurerm/import_arm_app_service_test.go b/azurerm/import_arm_app_service_test.go index 5c12dddc092f..e2bacbcbae5e 100644 --- a/azurerm/import_arm_app_service_test.go +++ b/azurerm/import_arm_app_service_test.go @@ -1,6 +1,5 @@ package azurerm -/* import ( "testing" @@ -19,17 +18,451 @@ func TestAccAzureRMAppService_importBasic(t *testing.T) { Providers: testAccProviders, CheckDestroy: testCheckAzureRMAppServiceDestroy, Steps: []resource.TestStep{ - resource.TestStep{ + { Config: config, }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +func TestAccAzureRMAppService_import32Bit(t *testing.T) { + resourceName := "azurerm_app_service.test" + + ri := acctest.RandInt() + config := testAccAzureRMAppService_32Bit(ri, testLocation()) + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testCheckAzureRMAppServiceDestroy, + Steps: []resource.TestStep{ + { + Config: config, + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +func TestAccAzureRMAppService_importAlwaysOn(t *testing.T) { + resourceName := "azurerm_app_service.test" + + ri := acctest.RandInt() + config := testAccAzureRMAppService_alwaysOn(ri, testLocation()) + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testCheckAzureRMAppServiceDestroy, + Steps: []resource.TestStep{ + { + Config: config, + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +func TestAccAzureRMAppService_importAppSettings(t *testing.T) { + resourceName := "azurerm_app_service.test" + + ri := acctest.RandInt() + config := testAccAzureRMAppService_appSettings(ri, testLocation()) + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testCheckAzureRMAppServiceDestroy, + Steps: []resource.TestStep{ + { + Config: config, + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +func TestAccAzureRMAppService_importClientAffinityEnabled(t *testing.T) { + resourceName := "azurerm_app_service.test" + + ri := acctest.RandInt() + config := testAccAzureRMAppService_clientAffinityEnabled(ri, testLocation()) + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testCheckAzureRMAppServiceDestroy, + Steps: []resource.TestStep{ + { + Config: config, + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +func TestAccAzureRMAppService_importConnectionStrings(t *testing.T) { + resourceName := "azurerm_app_service.test" + + ri := acctest.RandInt() + config := testAccAzureRMAppService_connectionStrings(ri, testLocation()) + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testCheckAzureRMAppServiceDestroy, + Steps: []resource.TestStep{ + { + Config: config, + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +func TestAccAzureRMAppService_importDefaultDocuments(t *testing.T) { + resourceName := "azurerm_app_service.test" + + ri := acctest.RandInt() + config := testAccAzureRMAppService_defaultDocuments(ri, testLocation()) + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testCheckAzureRMAppServiceDestroy, + Steps: []resource.TestStep{ + { + Config: config, + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +func TestAccAzureRMAppService_importEnabled(t *testing.T) { + resourceName := "azurerm_app_service.test" + + ri := acctest.RandInt() + config := testAccAzureRMAppService_enabled(ri, testLocation()) + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testCheckAzureRMAppServiceDestroy, + Steps: []resource.TestStep{ + { + Config: config, + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +func TestAccAzureRMAppService_importLocalMySql(t *testing.T) { + resourceName := "azurerm_app_service.test" + + ri := acctest.RandInt() + config := testAccAzureRMAppService_localMySql(ri, testLocation()) + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testCheckAzureRMAppServiceDestroy, + Steps: []resource.TestStep{ + { + Config: config, + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +func TestAccAzureRMAppService_importManagedPipelineMode(t *testing.T) { + resourceName := "azurerm_app_service.test" + + ri := acctest.RandInt() + config := testAccAzureRMAppService_managedPipelineMode(ri, testLocation()) + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testCheckAzureRMAppServiceDestroy, + Steps: []resource.TestStep{ + { + Config: config, + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +func TestAccAzureRMAppService_importRemoteDebugging(t *testing.T) { + resourceName := "azurerm_app_service.test" + + ri := acctest.RandInt() + config := testAccAzureRMAppService_remoteDebugging(ri, testLocation()) - resource.TestStep{ - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"force_dns_registration", "skip_custom_domain_verification", "skip_dns_registration", "delete_metrics"}, + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testCheckAzureRMAppServiceDestroy, + Steps: []resource.TestStep{ + { + Config: config, + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +func TestAccAzureRMAppService_importWindowsDotNet2(t *testing.T) { + resourceName := "azurerm_app_service.test" + + ri := acctest.RandInt() + config := testAccAzureRMAppService_windowsDotNet(ri, testLocation(), "v2.0") + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testCheckAzureRMAppServiceDestroy, + Steps: []resource.TestStep{ + { + Config: config, + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +func TestAccAzureRMAppService_importWindowsDotNet4(t *testing.T) { + resourceName := "azurerm_app_service.test" + + ri := acctest.RandInt() + config := testAccAzureRMAppService_windowsDotNet(ri, testLocation(), "v4.0") + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testCheckAzureRMAppServiceDestroy, + Steps: []resource.TestStep{ + { + Config: config, + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +func TestAccAzureRMAppService_importWindowsJava7Jetty(t *testing.T) { + resourceName := "azurerm_app_service.test" + + ri := acctest.RandInt() + config := testAccAzureRMAppService_windowsJava(ri, testLocation(), "1.7", "JETTY", "9.3") + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testCheckAzureRMAppServiceDestroy, + Steps: []resource.TestStep{ + { + Config: config, + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +func TestAccAzureRMAppService_importWindowsJava8Jetty(t *testing.T) { + resourceName := "azurerm_app_service.test" + + ri := acctest.RandInt() + config := testAccAzureRMAppService_windowsJava(ri, testLocation(), "1.8", "JETTY", "9.3") + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testCheckAzureRMAppServiceDestroy, + Steps: []resource.TestStep{ + { + Config: config, + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +func TestAccAzureRMAppService_importWindowsJava7Tomcat(t *testing.T) { + resourceName := "azurerm_app_service.test" + + ri := acctest.RandInt() + config := testAccAzureRMAppService_windowsJava(ri, testLocation(), "1.7", "TOMCAT", "9.0") + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testCheckAzureRMAppServiceDestroy, + Steps: []resource.TestStep{ + { + Config: config, + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +func TestAccAzureRMAppService_importWindowsJava8Tomcat(t *testing.T) { + resourceName := "azurerm_app_service.test" + + ri := acctest.RandInt() + config := testAccAzureRMAppService_windowsJava(ri, testLocation(), "1.8", "TOMCAT", "9.0") + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testCheckAzureRMAppServiceDestroy, + Steps: []resource.TestStep{ + { + Config: config, + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +func TestAccAzureRMAppService_importWindowsPHP7(t *testing.T) { + resourceName := "azurerm_app_service.test" + + ri := acctest.RandInt() + config := testAccAzureRMAppService_windowsPHP(ri, testLocation()) + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testCheckAzureRMAppServiceDestroy, + Steps: []resource.TestStep{ + { + Config: config, + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +func TestAccAzureRMAppService_importWindowsPython(t *testing.T) { + resourceName := "azurerm_app_service.test" + + ri := acctest.RandInt() + config := testAccAzureRMAppService_windowsPython(ri, testLocation()) + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testCheckAzureRMAppServiceDestroy, + Steps: []resource.TestStep{ + { + Config: config, + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +func TestAccAzureRMAppService_importWebSockets(t *testing.T) { + resourceName := "azurerm_app_service.test" + + ri := acctest.RandInt() + config := testAccAzureRMAppService_webSockets(ri, testLocation()) + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testCheckAzureRMAppServiceDestroy, + Steps: []resource.TestStep{ + { + Config: config, + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, }, }, }) } -*/ From 61d61674bcaa3748a38e2583cb63a76d2e1fbc81 Mon Sep 17 00:00:00 2001 From: tombuildsstuff Date: Mon, 18 Sep 2017 13:34:33 +0100 Subject: [PATCH 27/31] Handling setting the appSettings/connectionStrings correctly --- azurerm/resource_arm_app_service.go | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/azurerm/resource_arm_app_service.go b/azurerm/resource_arm_app_service.go index af0ce32dbc98..0f24e4677d51 100644 --- a/azurerm/resource_arm_app_service.go +++ b/azurerm/resource_arm_app_service.go @@ -397,8 +397,12 @@ func resourceArmAppServiceRead(d *schema.ResourceData, meta interface{}) error { d.Set("enabled", props.Enabled) } - d.Set("app_settings", appSettingsResp.Properties) - d.Set("connection_string", flattenAppServiceConnectionStrings(connectionStringsResp.Properties)) + 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 + } siteConfig := flattenAppServiceSiteConfig(configResp.SiteConfig) if err := d.Set("site_config", siteConfig); err != nil { @@ -621,9 +625,18 @@ func flattenAppServiceConnectionStrings(input *map[string]*web.ConnStringValueTy result := make(map[string]interface{}, 0) result["name"] = k result["type"] = string(v.Type) - result["value"] = v.Value + result["value"] = *v.Value results = append(results, result) } return results } + +func flattenAppServiceAppSettings(input *map[string]*string) map[string]string { + output := make(map[string]string, 0) + for k, v := range *input { + output[k] = *v + } + + return output +} From 976e2b474cde42ff568d254ec03f4035911b75d4 Mon Sep 17 00:00:00 2001 From: tombuildsstuff Date: Mon, 18 Sep 2017 14:15:59 +0100 Subject: [PATCH 28/31] Updating the documentation --- website/azurerm.erb | 8 +-- website/docs/r/app_service.html.markdown | 84 +++++++++++++++++++----- 2 files changed, 71 insertions(+), 21 deletions(-) diff --git a/website/azurerm.erb b/website/azurerm.erb index fd7cefb08013..5d4f9a78e45a 100644 --- a/website/azurerm.erb +++ b/website/azurerm.erb @@ -59,12 +59,12 @@ App Service (Web Apps) Resources diff --git a/website/docs/r/app_service.html.markdown b/website/docs/r/app_service.html.markdown index e2c53cc1dad4..275a347ff7b4 100644 --- a/website/docs/r/app_service.html.markdown +++ b/website/docs/r/app_service.html.markdown @@ -1,27 +1,48 @@ --- layout: "azurerm" page_title: "Azure Resource Manager: azurerm_app_service" -sidebar_current: "docs-azurerm-resource-app-service" +sidebar_current: "docs-azurerm-resource-app-service-x" description: |- - Manage an App Service (within an App Service Plan). + Manages an App Service (within an App Service Plan). + --- # azurerm\_app\_service -Manage an App Service (within an App Service Plan). +Manages an App Service (within an App Service Plan). ## Example Usage ```hcl resource "azurerm_resource_group" "test" { - name = "api-rg-pro" + name = "some-resource-group" location = "West Europe" } +resource "azurerm_app_service_plan" "test" { + name = "some-app-service-plan" + 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 = "api-appservice-pro" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + name = "my-app-service" + location = "${azurerm_resource_group.test.location}" + resource_group_name = "${azurerm_resource_group.test.name}" + app_service_plan_id = "${azurerm_app_service_plan.test.id}" + + site_config { + dotnet_framework_version = "v4.0" + } + + app_settings { + "SOME_KEY" = "some-value" + } } ``` @@ -35,31 +56,60 @@ The following arguments are supported: * `location` - (Required) Specifies the supported Azure location where the resource exists. Changing this forces a new resource to be created. -`site_config` supports the following: +* `app_service_plan_id` - (Required) The ID of the App Service Plan within which to create this App Service. Changing this forces a new resource to be created. + +* `app_settings` - (Optional) A key-value pair of App Settings. + +* `connection_string` - (Optional) An `connection_string` block as defined below. + +* `client_affinity_enabled` - (Optional) TODO: COMPLETE ME. Changing this forces a new resource to be created. -* `app_service_plan_id` - (Optional) The resource ID of the app service plan. +* `enabled` - (Optional) TODO: COMPLETE ME. Changing this forces a new resource to be created. -* `always_on` - (Optional) Alows the app to be loaded all the time. +* `site_config` - (Optional) A `site_config` object as defined below. -* `skip_dns_registration` - (Optional) If true, DNS registration is skipped. +* `tags` - (Optional) A mapping of tags to assign to the resource. Changing this forces a new resource to be created. + +--- + +`connection_string` supports the following: + +* `name` - (Required) The name of the Connection String. +* `type` - (Required) The type of the Connection String. Possible values are `APIHub`, `Custom`, `DocDb`, `EventHub`, `MySQL`, `NotificationHub`, `PostgreSQL`, `RedisCache`, `ServiceBus`, `SQLAzure` and `SQLServer`. +* `value` - (Required) The value for the Connection String. + +--- + +`site_config` supports the following: -* `skip_custom_domain_verification` - (Optional) If true, custom (non .azurewebsites.net) domains associated with web app are not verified. +* `always_on` - (Optional) Should the app be loaded at all times? Defaults to `false`. +* `default_documents` - (Optional) The ordering of default documents to load, if an address isn't specified. +* `dotnet_framework_version` - (Optional) The version of the .net framework used in this App Service. Possible values are `v2.0` (which corresponds to `v3.5`) and `v4.0` (which is `v4.7` at the time of writing). Defaults to `v4.0`. -* `force_dns_registration` - (Optional) If true, web app hostname is force registered with DNS. +* `java_version` - (Optional) The version of Java to use. If specified `java_container` and `java_container_version` must also be specified. Possible values are `1.7` and `1.8`. +* `java_container` - (Optional) The Java Container to use. If specified `java_version` and `java_container_version` must also be specified. Possible values are `JETTY` and `TOMCAT`. +* `java_container_version` - (Optional) The version of the Java Container to use. If specified `java_version` and `java_container` must also be specified. Possible values are `JETTY` and `TOMCAT`. -* `ttl_in_seconds` - (Optional) Time to live in seconds for app service's default domain name. +* `local_mysql_enabled` - (Optional) Is "MySQL In App" Enabled? This runs a local MySQL instance with your app and shares resources from the App Service plan. +~> **NOTE:** MySQL In App is not intended for production environments and will not scale beyond a single instance. Instead you may wish to use Azure Database for MySQL. -* `tags` - (Optional) A mapping of tags to assign to the resource. +* `managed_pipeline_mode` - (Optional) The Managed Pipeline Mode. Possible values are `Integrated` and `Classic`. Defaults to `Integrated`. +* `php_version` - (Optional) The version of PHP to use in this App Service. Possible values are `5.5`, `5.6`, `7.0` and `7.1`. +* `python_version` - (Optional) The version of Python to use in this App Service. Possible values are `2.7` and `3.4`. +* `remote_debugging_enabled` - (Optional) Is Remote Debugging Enabled? Defaults to `false`. +* `remote_debugging_version` - (Optional) Which version of Visual Studio should the Remote Debugger be compatible with? Possible values are `VS2012`, `VS2013`, `VS2015` and `VS2017`. +* `use_32_bit_worker_process` - (Optional) Should the App Service run in 32 bit mode, rather than 64 bit mode? +* `websockets_enabled` - (Optional) Should WebSockets be enabled? ## Attributes Reference The following attributes are exported: -* `id` - The ID of the App Service component. +* `id` - The ID of the App Service. ## Import -App Service instances can be imported using the `resource id`, e.g. +App Services can be imported using the `resource id`, e.g. ``` terraform import azurerm_app_service.instance1 /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/mygroup1/providers/Microsoft.Web/sites/instance1 From 978c976622bb45abdfc8c9af11827b2e22ec8c82 Mon Sep 17 00:00:00 2001 From: tombuildsstuff Date: Tue, 19 Sep 2017 14:52:12 +0100 Subject: [PATCH 29/31] Removing the updates from the create --- azurerm/resource_arm_app_service.go | 21 +-------------------- 1 file changed, 1 insertion(+), 20 deletions(-) diff --git a/azurerm/resource_arm_app_service.go b/azurerm/resource_arm_app_service.go index 0f24e4677d51..ae2c1b617bdf 100644 --- a/azurerm/resource_arm_app_service.go +++ b/azurerm/resource_arm_app_service.go @@ -240,7 +240,6 @@ func resourceArmAppServiceCreate(d *schema.ResourceData, meta interface{}) error tags := d.Get("tags").(map[string]interface{}) siteConfig := expandAppServiceSiteConfig(d) - appSettings := expandAppServiceAppSettings(d) siteEnvelope := web.Site{ Location: &location, @@ -268,24 +267,6 @@ func resourceArmAppServiceCreate(d *schema.ResourceData, meta interface{}) error return err } - settings := web.StringDictionary{ - Properties: appSettings, - } - _, err = client.UpdateApplicationSettings(resGroup, name, settings) - if err != nil { - return fmt.Errorf("Error updating Application Settings for App Service %q: %+v", name, err) - } - - connectionStrings := expandAppServiceConnectionStrings(d) - properties := web.ConnectionStringDictionary{ - Properties: connectionStrings, - } - - _, err = client.UpdateConnectionStrings(resGroup, name, properties) - if err != nil { - return fmt.Errorf("Error updating Connection Strings for App Service %q: %+v", name, err) - } - read, err := client.Get(resGroup, name) if err != nil { return err @@ -365,7 +346,7 @@ func resourceArmAppServiceRead(d *schema.ResourceData, meta interface{}) error { resp, err := client.Get(resGroup, name) if err != nil { if utils.ResponseWasNotFound(resp.Response) { - // TODO: debug logging + log.Printf("[DEBUG] App Service %q (resource group %q) was not found - removing from state", name, resGroup) d.SetId("") return nil } From 50f1a067962d4294a17ce04e9208e4e135f2648b Mon Sep 17 00:00:00 2001 From: tombuildsstuff Date: Tue, 19 Sep 2017 18:15:36 +0100 Subject: [PATCH 30/31] Updating the documentation --- website/docs/r/app_service.html.markdown | 49 +++++++++++++++++++++--- 1 file changed, 44 insertions(+), 5 deletions(-) diff --git a/website/docs/r/app_service.html.markdown b/website/docs/r/app_service.html.markdown index 275a347ff7b4..8c272e1ec67e 100644 --- a/website/docs/r/app_service.html.markdown +++ b/website/docs/r/app_service.html.markdown @@ -7,11 +7,11 @@ description: |- --- -# azurerm\_app\_service +# azurerm_app_service Manages an App Service (within an App Service Plan). -## Example Usage +## Example Usage (.net 4.x) ```hcl resource "azurerm_resource_group" "test" { @@ -43,6 +43,45 @@ resource "azurerm_app_service" "test" { app_settings { "SOME_KEY" = "some-value" } + + connection_string { + name = "Database" + type = "SQLServer" + value = "Server=some-server.mydomain.com;Integrated Security=SSPI" + } +} +``` + +## Example Usage (Java 1.8) + +```hcl +resource "azurerm_resource_group" "test" { + name = "some-resource-group" + location = "West Europe" +} + +resource "azurerm_app_service_plan" "test" { + name = "some-app-service-plan" + 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 = "my-app-service" + location = "${azurerm_resource_group.test.location}" + resource_group_name = "${azurerm_resource_group.test.name}" + app_service_plan_id = "${azurerm_app_service_plan.test.id}" + + site_config { + java_version = "1.8" + java_container = "JETTY" + java_container_version = "9.3" + } } ``` @@ -62,9 +101,9 @@ The following arguments are supported: * `connection_string` - (Optional) An `connection_string` block as defined below. -* `client_affinity_enabled` - (Optional) TODO: COMPLETE ME. Changing this forces a new resource to be created. +* `client_affinity_enabled` - (Optional) Should the App Service 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) TODO: COMPLETE ME. Changing this forces a new resource to be created. +* `enabled` - (Optional) Is the App Service Enabled? Changing this forces a new resource to be created. * `site_config` - (Optional) A `site_config` object as defined below. @@ -88,7 +127,7 @@ The following arguments are supported: * `java_version` - (Optional) The version of Java to use. If specified `java_container` and `java_container_version` must also be specified. Possible values are `1.7` and `1.8`. * `java_container` - (Optional) The Java Container to use. If specified `java_version` and `java_container_version` must also be specified. Possible values are `JETTY` and `TOMCAT`. -* `java_container_version` - (Optional) The version of the Java Container to use. If specified `java_version` and `java_container` must also be specified. Possible values are `JETTY` and `TOMCAT`. +* `java_container_version` - (Optional) The version of the Java Container to use. If specified `java_version` and `java_container` must also be specified. * `local_mysql_enabled` - (Optional) Is "MySQL In App" Enabled? This runs a local MySQL instance with your app and shares resources from the App Service plan. ~> **NOTE:** MySQL In App is not intended for production environments and will not scale beyond a single instance. Instead you may wish to use Azure Database for MySQL. From 91f71fd6d4666bdd63d37cba73429f51967bc355 Mon Sep 17 00:00:00 2001 From: tombuildsstuff Date: Tue, 19 Sep 2017 18:48:59 +0100 Subject: [PATCH 31/31] Updating the TODO's --- azurerm/resource_arm_app_service.go | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/azurerm/resource_arm_app_service.go b/azurerm/resource_arm_app_service.go index ae2c1b617bdf..adcbc368f22d 100644 --- a/azurerm/resource_arm_app_service.go +++ b/azurerm/resource_arm_app_service.go @@ -170,14 +170,20 @@ func resourceArmAppService() *schema.Resource { Type: schema.TypeBool, Optional: true, Computed: true, - ForceNew: true, // due to a bug in the Azure API :( + + // 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, Default: true, - ForceNew: true, // due to a bug in the Azure API :( + + // TODO: (tombuildsstuff) support Update once the API is fixed: + // https://github.com/Azure/azure-rest-api-specs/issues/1697 + ForceNew: true, }, "app_settings": { @@ -222,7 +228,9 @@ func resourceArmAppService() *schema.Resource { }, }, - "tags": tagsForceNewSchema(), // due to a bug in the Azure API :( + // TODO: (tombuildsstuff) support Update once the API is fixed: + // https://github.com/Azure/azure-rest-api-specs/issues/1697 + "tags": tagsForceNewSchema(), }, } }