From 0468a721710ca28c4719794e5902093d726e917c Mon Sep 17 00:00:00 2001 From: Tom Bamford Date: Fri, 22 Jan 2021 13:15:26 +0000 Subject: [PATCH] azurerm_api_management_identity_provider_aadb2c: Use ID parser when creating/updating, use API URL exported from parent resource, fix up documentation --- ...ement_identity_provider_aadb2c_resource.go | 17 +++---------- ..._identity_provider_aadb2c_resource_test.go | 25 ++++++------------- ...ent_identity_provider_aadb2c.html.markdown | 20 +++++++-------- 3 files changed, 22 insertions(+), 40 deletions(-) diff --git a/azurerm/internal/services/apimanagement/api_management_identity_provider_aadb2c_resource.go b/azurerm/internal/services/apimanagement/api_management_identity_provider_aadb2c_resource.go index 42d65e17f2fd..6e73e91c6d53 100644 --- a/azurerm/internal/services/apimanagement/api_management_identity_provider_aadb2c_resource.go +++ b/azurerm/internal/services/apimanagement/api_management_identity_provider_aadb2c_resource.go @@ -120,6 +120,8 @@ func resourceArmApiManagementIdentityProviderAADB2CCreateUpdate(d *schema.Resour profileEditingPolicy := d.Get("profile_editing_policy").(string) passwordResetPolicy := d.Get("password_reset_policy").(string) + id := parse.NewIdentityProviderID(client.SubscriptionID, resourceGroup, serviceName, string(apimanagement.AadB2C)) + if d.IsNewResource() { existing, err := client.Get(ctx, resourceGroup, serviceName, apimanagement.AadB2C) if err != nil { @@ -127,10 +129,7 @@ func resourceArmApiManagementIdentityProviderAADB2CCreateUpdate(d *schema.Resour return fmt.Errorf("checking for presence of existing Identity Provider %q (API Management Service %q / Resource Group %q): %s", apimanagement.AadB2C, serviceName, resourceGroup, err) } } - - if existing.ID != nil && *existing.ID != "" { - return tf.ImportAsExistsError("azurerm_api_management_identity_provider_aadb2c", *existing.ID) - } + return tf.ImportAsExistsError("azurerm_api_management_identity_provider_aadb2c", id.String()) } parameters := apimanagement.IdentityProviderCreateContract{ @@ -152,15 +151,7 @@ func resourceArmApiManagementIdentityProviderAADB2CCreateUpdate(d *schema.Resour return fmt.Errorf("creating or updating Identity Provider %q (Resource Group %q / API Management Service %q): %+v", apimanagement.AadB2C, resourceGroup, serviceName, err) } - resp, err := client.Get(ctx, resourceGroup, serviceName, apimanagement.AadB2C) - if err != nil { - return fmt.Errorf("retrieving Identity Provider %q (Resource Group %q / API Management Service %q): %+v", apimanagement.AadB2C, resourceGroup, serviceName, err) - } - if resp.ID == nil { - return fmt.Errorf("Cannot read ID for Identity Provider %q (Resource Group %q / API Management Service %q)", apimanagement.AadB2C, resourceGroup, serviceName) - } - d.SetId(*resp.ID) - + d.SetId(id.String()) return resourceArmApiManagementIdentityProviderAADB2CRead(d, meta) } diff --git a/azurerm/internal/services/apimanagement/api_management_identity_provider_aadb2c_resource_test.go b/azurerm/internal/services/apimanagement/api_management_identity_provider_aadb2c_resource_test.go index ac4b0f4067f2..9dcba8cba430 100644 --- a/azurerm/internal/services/apimanagement/api_management_identity_provider_aadb2c_resource_test.go +++ b/azurerm/internal/services/apimanagement/api_management_identity_provider_aadb2c_resource_test.go @@ -34,18 +34,10 @@ func TestAccAzureRMApiManagementIdentityProviderAADB2C_basic(t *testing.T) { data := acceptance.BuildTestData(t, "azurerm_api_management_identity_provider_aadb2c", "test") r := ApiManagementIdentityProviderAADB2CResource{} b2cConfig := testAccAzureRMApiManagementIdentityProviderAADB2C_getB2CConfig(t) - env, err := acceptance.Environment() - if err != nil { - t.Fatalf("could not load Azure Environment: %+v", err) - } - apiDomain := env.APIManagementHostNameSuffix - if apiDomain == "" { - t.Fatalf("APIManagementHostNameSuffix was empty") - } data.ResourceTest(t, r, []resource.TestStep{ { - Config: r.basic(data, b2cConfig, apiDomain), + Config: r.basic(data, b2cConfig), Check: resource.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), ), @@ -58,17 +50,16 @@ func TestAccAzureRMApiManagementIdentityProviderAADB2C_requiresImport(t *testing data := acceptance.BuildTestData(t, "azurerm_api_management_identity_provider_aadb2c", "test") r := ApiManagementIdentityProviderAADB2CResource{} b2cConfig := testAccAzureRMApiManagementIdentityProviderAADB2C_getB2CConfig(t) - apiDomain := acceptance.AzureProvider.Meta().(*clients.Client).Account.Environment.APIManagementHostNameSuffix data.ResourceTest(t, r, []resource.TestStep{ { - Config: r.basic(data, b2cConfig, apiDomain), + Config: r.basic(data, b2cConfig), Check: resource.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), ), }, { - Config: r.requiresImport(data, b2cConfig, apiDomain), + Config: r.requiresImport(data, b2cConfig), ExpectError: acceptance.RequiresImportError(data.ResourceType), }, }) @@ -113,7 +104,7 @@ func (ApiManagementIdentityProviderAADB2CResource) Exists(ctx context.Context, c return utils.Bool(resp.ID != nil), nil } -func (ApiManagementIdentityProviderAADB2CResource) basic(data acceptance.TestData, b2cConfig map[string]string, apiDomain string) string { +func (ApiManagementIdentityProviderAADB2CResource) basic(data acceptance.TestData, b2cConfig map[string]string) string { return fmt.Sprintf(` provider "azurerm" { features {} @@ -142,7 +133,7 @@ resource "azurerm_api_management" "test" { resource "azuread_application" "test" { name = "acctestAM-%[5]d" oauth2_allow_implicit_flow = true - reply_urls = ["https://${azurerm_api_management.test.name}.developer.%[8]s/signin"] + reply_urls = [azurerm_api_management.test.developer_portal_url] } resource "azuread_application_password" "test" { @@ -166,11 +157,11 @@ resource "azurerm_api_management_identity_provider_aadb2c" "test" { depends_on = [azuread_application_password.test] } -`, b2cConfig["tenant_id"], b2cConfig["client_id"], b2cConfig["client_secret"], b2cConfig["tenant_slug"], data.RandomInteger, data.Locations.Primary, data.RandomString, apiDomain) +`, b2cConfig["tenant_id"], b2cConfig["client_id"], b2cConfig["client_secret"], b2cConfig["tenant_slug"], data.RandomInteger, data.Locations.Primary, data.RandomString) } -func (r ApiManagementIdentityProviderAADB2CResource) requiresImport(data acceptance.TestData, b2cConfig map[string]string, apiDomain string) string { - template := r.basic(data, b2cConfig, apiDomain) +func (r ApiManagementIdentityProviderAADB2CResource) requiresImport(data acceptance.TestData, b2cConfig map[string]string) string { + template := r.basic(data, b2cConfig) return fmt.Sprintf(` %s diff --git a/website/docs/r/api_management_identity_provider_aadb2c.html.markdown b/website/docs/r/api_management_identity_provider_aadb2c.html.markdown index 387e6f099a6b..120b920efe33 100644 --- a/website/docs/r/api_management_identity_provider_aadb2c.html.markdown +++ b/website/docs/r/api_management_identity_provider_aadb2c.html.markdown @@ -3,12 +3,12 @@ subcategory: "API Management" layout: "azurerm" page_title: "Azure Resource Manager: azurerm_api_management_identity_provider_aadb2c" description: |- - Manages an API Management AADB2C Identity Provider. + Manages an API Management Azure AD B2C Identity Provider. --- # azurerm_api_management_identity_provider_aadb2c -Manages an API Management AADB2C Identity Provider. +Manages an API Management Azure AD B2C Identity Provider. ## Example Usage @@ -71,9 +71,9 @@ The following arguments are supported: * `authority` - (Required) OpenID Connect discovery endpoint hostname, usually your b2clogin.com domain. -* `signin_policy` - (Required) Signup Policy Name. +* `signin_policy` - (Required) Signin Policy Name. -* `signup_policy` - (Required) Signin Policy Name. +* `signup_policy` - (Required) Signup Policy Name. --- @@ -85,20 +85,20 @@ The following arguments are supported: In addition to the Arguments listed above - the following Attributes are exported: -* `id` - The ID of the API Management Identity Provider Resource. +* `id` - The ID of the API Management Azure AD B2C Identity Provider Resource. ## Timeouts The `timeouts` block allows you to specify [timeouts](https://www.terraform.io/docs/configuration/resources.html#timeouts) for certain actions: -* `create` - (Defaults to 30 minutes) Used when creating the API Management Resources. -* `read` - (Defaults to 5 minutes) Used when retrieving the API Management Resources. -* `update` - (Defaults to 30 minutes) Used when updating the API Management Resources. -* `delete` - (Defaults to 30 minutes) Used when deleting the API Management Resources. +* `create` - (Defaults to 30 minutes) Used when creating the API Management Azure AD B2C Identity Provider. +* `read` - (Defaults to 5 minutes) Used when retrieving the API Management Azure AD B2C Identity Provider. +* `update` - (Defaults to 30 minutes) Used when updating the API Management Azure AD B2C Identity Provider. +* `delete` - (Defaults to 30 minutes) Used when deleting the API Management Azure AD B2C Identity Provider. ## Import -API Management Resourcess can be imported using the `resource id`, e.g. +API Management Azure AD B2C Identity Providers can be imported using the `resource id`, e.g. ```shell terraform import azurerm_api_management_identity_provider_aadb2c.example /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/mygroup1/providers/Microsoft.ApiManagement/service1/identityProviders/AadB2C