From 21a1ed98906a77cfc3fb8441987fff984ea357c1 Mon Sep 17 00:00:00 2001 From: Adam Coulter Date: Mon, 7 Dec 2020 00:56:14 +1100 Subject: [PATCH 1/2] create cert in service plan rg --- .../web/app_service_managed_certificate_resource.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/azurerm/internal/services/web/app_service_managed_certificate_resource.go b/azurerm/internal/services/web/app_service_managed_certificate_resource.go index c088738a0dde..8ec2d6c1749d 100644 --- a/azurerm/internal/services/web/app_service_managed_certificate_resource.go +++ b/azurerm/internal/services/web/app_service_managed_certificate_resource.go @@ -117,6 +117,11 @@ func resourceArmAppServiceManagedCertificateCreateUpdate(d *schema.ResourceData, } appServicePlanID = *appService.SiteProperties.ServerFarmID + appServicePlanIDParts, err := parse.AppServicePlanID(appServicePlanID) + if err != nil { + return err + } + appServiceLocation := "" if appService.Location != nil { appServiceLocation = location.Normalize(*appService.Location) @@ -124,7 +129,7 @@ func resourceArmAppServiceManagedCertificateCreateUpdate(d *schema.ResourceData, t := d.Get("tags").(map[string]interface{}) - id := parse.NewManagedCertificateID(subscriptionId, customHostnameBindingId.ResourceGroup, name) + id := parse.NewManagedCertificateID(subscriptionId, appServicePlanIDParts.ResourceGroup, name) if d.IsNewResource() { existing, err := client.Get(ctx, id.ResourceGroup, id.CertificateName) From 53f0700ffb9b3a24abf525caefcdd193027f7fe7 Mon Sep 17 00:00:00 2001 From: Adam Coulter Date: Mon, 7 Dec 2020 23:12:54 +1100 Subject: [PATCH 2/2] Renamed variables to follow convention --- .../web/app_service_managed_certificate_resource.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/azurerm/internal/services/web/app_service_managed_certificate_resource.go b/azurerm/internal/services/web/app_service_managed_certificate_resource.go index 8ec2d6c1749d..243150fb3dca 100644 --- a/azurerm/internal/services/web/app_service_managed_certificate_resource.go +++ b/azurerm/internal/services/web/app_service_managed_certificate_resource.go @@ -111,13 +111,13 @@ func resourceArmAppServiceManagedCertificateCreateUpdate(d *schema.ResourceData, } name := customHostnameBindingId.Name - appServicePlanID := "" + appServicePlanIDRaw := "" if appService.SiteProperties == nil || appService.SiteProperties.ServerFarmID == nil { return fmt.Errorf("could not get App Service Plan ID for Custom Hostname Binding %q (resource group %q)", customHostnameBindingId.Name, customHostnameBindingId.ResourceGroup) } - appServicePlanID = *appService.SiteProperties.ServerFarmID + appServicePlanIDRaw = *appService.SiteProperties.ServerFarmID - appServicePlanIDParts, err := parse.AppServicePlanID(appServicePlanID) + appServicePlanID, err := parse.AppServicePlanID(appServicePlanIDRaw) if err != nil { return err } @@ -129,7 +129,7 @@ func resourceArmAppServiceManagedCertificateCreateUpdate(d *schema.ResourceData, t := d.Get("tags").(map[string]interface{}) - id := parse.NewManagedCertificateID(subscriptionId, appServicePlanIDParts.ResourceGroup, name) + id := parse.NewManagedCertificateID(subscriptionId, appServicePlanID.ResourceGroup, name) if d.IsNewResource() { existing, err := client.Get(ctx, id.ResourceGroup, id.CertificateName) @@ -147,7 +147,7 @@ func resourceArmAppServiceManagedCertificateCreateUpdate(d *schema.ResourceData, certificate := web.Certificate{ CertificateProperties: &web.CertificateProperties{ CanonicalName: utils.String(customHostnameBindingId.Name), - ServerFarmID: utils.String(appServicePlanID), + ServerFarmID: utils.String(appServicePlanIDRaw), Password: new(string), }, Location: utils.String(appServiceLocation),