Skip to content

Commit

Permalink
azurerm_api_management_identity_provider_aadb2c: Use ID parser when c…
Browse files Browse the repository at this point in the history
…reating/updating, use API URL exported from parent resource, fix up documentation
  • Loading branch information
manicminer committed Feb 2, 2021
1 parent ba0d52c commit 6ba4c83
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -120,16 +120,16 @@ 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 {
if !utils.ResponseWasNotFound(existing.Response) {
return fmt.Errorf("checking for presence of existing Identity Provider %q (API Management Service %q / Resource Group %q): %s", apimanagement.AadB2C, serviceName, resourceGroup, err)
return fmt.Errorf("checking for presence of existing %s: %s", id.String(), err)
}
}

if existing.ID != nil && *existing.ID != "" {
return tf.ImportAsExistsError("azurerm_api_management_identity_provider_aadb2c", *existing.ID)
} else {
return tf.ImportAsExistsError("azurerm_api_management_identity_provider_aadb2c", id.ID())
}
}

Expand All @@ -152,15 +152,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.ID())
return resourceArmApiManagementIdentityProviderAADB2CRead(d, meta)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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),
),
Expand All @@ -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),
},
})
Expand Down Expand Up @@ -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 {}
Expand Down Expand Up @@ -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" {
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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.

---

Expand All @@ -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
Expand Down

0 comments on commit 6ba4c83

Please sign in to comment.