From 7245e623783ff156bf99018fc619ea782b9864e4 Mon Sep 17 00:00:00 2001 From: tombuildsstuff Date: Thu, 14 Feb 2019 16:10:04 +0100 Subject: [PATCH 1/7] New Resource: `azurerm_api_management_user` --- azurerm/config.go | 5 + azurerm/helpers/azure/api_management.go | 9 + azurerm/helpers/validate/api_management.go | 13 + azurerm/provider.go | 1 + azurerm/resource_arm_api_management_user.go | 218 +++++++++ .../resource_arm_api_management_user_test.go | 420 ++++++++++++++++++ .../docs/r/api_management_user.html.markdown | 86 ++++ 7 files changed, 752 insertions(+) create mode 100644 azurerm/resource_arm_api_management_user.go create mode 100644 azurerm/resource_arm_api_management_user_test.go create mode 100644 website/docs/r/api_management_user.html.markdown diff --git a/azurerm/config.go b/azurerm/config.go index f7aaaa24619d..d6513f8145c9 100644 --- a/azurerm/config.go +++ b/azurerm/config.go @@ -129,6 +129,7 @@ type ArmClient struct { apiManagementGroupClient apimanagement.GroupClient apiManagementProductsClient apimanagement.ProductClient apiManagementServiceClient apimanagement.ServiceClient + apiManagementUsersClient apimanagement.UserClient // Application Insights appInsightsClient appinsights.ComponentsClient @@ -500,6 +501,10 @@ func (c *ArmClient) registerApiManagementServiceClients(endpoint, subscriptionId productsClient := apimanagement.NewProductClientWithBaseURI(endpoint, subscriptionId) c.configureClient(&productsClient.Client, auth) c.apiManagementProductsClient = productsClient + + usersClient := apimanagement.NewUserClientWithBaseURI(endpoint, subscriptionId) + c.configureClient(&usersClient.Client, auth) + c.apiManagementUsersClient = usersClient } func (c *ArmClient) registerAppInsightsClients(endpoint, subscriptionId string, auth autorest.Authorizer) { diff --git a/azurerm/helpers/azure/api_management.go b/azurerm/helpers/azure/api_management.go index 84e4d8386f10..bda1e3327940 100644 --- a/azurerm/helpers/azure/api_management.go +++ b/azurerm/helpers/azure/api_management.go @@ -42,3 +42,12 @@ func SchemaApiManagementChildDataSourceName() *schema.Schema { ValidateFunc: validate.ApiManagementChildName, } } + +func SchemaApiManagementUserName() *schema.Schema { + return &schema.Schema{ + Type: schema.TypeString, + Required: true, + ForceNew: true, + ValidateFunc: validate.ApiManagementUserName, + } +} diff --git a/azurerm/helpers/validate/api_management.go b/azurerm/helpers/validate/api_management.go index e39f2761088f..d75d4208133a 100644 --- a/azurerm/helpers/validate/api_management.go +++ b/azurerm/helpers/validate/api_management.go @@ -26,6 +26,19 @@ func ApiManagementServiceName(v interface{}, k string) (warnings []string, error return warnings, errors } +func ApiManagementUserName(v interface{}, k string) (warnings []string, errors []error) { + value := v.(string) + + // TODO: confirm this + + // from the portal: `The field may contain only numbers, letters, and dash (-) sign when preceded and followed by number or a letter.` + if matched := regexp.MustCompile(`(^[a-zA-Z0-9])([a-zA-Z0-9-]{1,78})([a-zA-Z0-9]$)`).Match([]byte(value)); !matched { + errors = append(errors, fmt.Errorf("%q may only contain alphanumeric characters and dashes up to 80 characters in length", k)) + } + + return warnings, errors +} + func ApiManagementServicePublisherName(v interface{}, k string) (warnings []string, errors []error) { value := v.(string) diff --git a/azurerm/provider.go b/azurerm/provider.go index a2882038dfe5..4ac8a4aeb28a 100644 --- a/azurerm/provider.go +++ b/azurerm/provider.go @@ -168,6 +168,7 @@ func Provider() terraform.ResourceProvider { "azurerm_api_management": resourceArmApiManagementService(), "azurerm_api_management_group": resourceArmApiManagementGroup(), "azurerm_api_management_product": resourceArmApiManagementProduct(), + "azurerm_api_management_user": resourceArmApiManagementUser(), "azurerm_app_service_active_slot": resourceArmAppServiceActiveSlot(), "azurerm_app_service_custom_hostname_binding": resourceArmAppServiceCustomHostnameBinding(), "azurerm_app_service_plan": resourceArmAppServicePlan(), diff --git a/azurerm/resource_arm_api_management_user.go b/azurerm/resource_arm_api_management_user.go new file mode 100644 index 000000000000..f1067f407214 --- /dev/null +++ b/azurerm/resource_arm_api_management_user.go @@ -0,0 +1,218 @@ +package azurerm + +import ( + "fmt" + "log" + + "github.com/Azure/azure-sdk-for-go/services/preview/apimanagement/mgmt/2018-06-01-preview/apimanagement" + "github.com/hashicorp/terraform/helper/schema" + "github.com/hashicorp/terraform/helper/validation" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/validate" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" +) + +func resourceArmApiManagementUser() *schema.Resource { + return &schema.Resource{ + Create: resourceArmApiManagementUserCreateUpdate, + Read: resourceArmApiManagementUserRead, + Update: resourceArmApiManagementUserCreateUpdate, + Delete: resourceArmApiManagementUserDelete, + Importer: &schema.ResourceImporter{ + State: schema.ImportStatePassthrough, + }, + + Schema: map[string]*schema.Schema{ + "user_id": azure.SchemaApiManagementUserName(), + + "api_management_name": azure.SchemaApiManagementName(), + + "resource_group_name": resourceGroupNameSchema(), + + "first_name": { + Type: schema.TypeString, + Required: true, + ValidateFunc: validate.NoEmptyStrings, + }, + + "last_name": { + Type: schema.TypeString, + Required: true, + ValidateFunc: validate.NoEmptyStrings, + }, + + "email": { + Type: schema.TypeString, + Required: true, + ValidateFunc: validate.NoEmptyStrings, + }, + + "state": { + Type: schema.TypeString, + Optional: true, + Computed: true, + ValidateFunc: validation.StringInSlice([]string{ + string(apimanagement.UserStateActive), + string(apimanagement.UserStateBlocked), + string(apimanagement.UserStatePending), + }, false), + }, + + "confirmation": { + Type: schema.TypeString, + Optional: true, + ForceNew: true, + ValidateFunc: validation.StringInSlice([]string{ + string(apimanagement.Invite), + string(apimanagement.Signup), + }, false), + }, + + "note": { + Type: schema.TypeString, + Optional: true, + }, + + "password": { + Type: schema.TypeString, + Optional: true, + Sensitive: true, + }, + }, + } +} + +func resourceArmApiManagementUserCreateUpdate(d *schema.ResourceData, meta interface{}) error { + client := meta.(*ArmClient).apiManagementUsersClient + ctx := meta.(*ArmClient).StopContext + + log.Printf("[INFO] preparing arguments for API Management User creation.") + + resourceGroup := d.Get("resource_group_name").(string) + serviceName := d.Get("api_management_name").(string) + userId := d.Get("user_id").(string) + + firstName := d.Get("first_name").(string) + lastName := d.Get("last_name").(string) + email := d.Get("email").(string) + state := d.Get("state").(string) + note := d.Get("note").(string) + password := d.Get("password").(string) + + if requireResourcesToBeImported && d.IsNewResource() { + existing, err := client.Get(ctx, resourceGroup, serviceName, userId) + if err != nil { + if !utils.ResponseWasNotFound(existing.Response) { + return fmt.Errorf("Error checking for presence of existing User %q (API Management Service %q / Resource Group %q): %s", userId, serviceName, resourceGroup, err) + } + } + + if existing.ID != nil && *existing.ID != "" { + return tf.ImportAsExistsError("azurerm_api_management_user", *existing.ID) + } + } + + properties := apimanagement.UserCreateParameters{ + UserCreateParameterProperties: &apimanagement.UserCreateParameterProperties{ + FirstName: utils.String(firstName), + LastName: utils.String(lastName), + Email: utils.String(email), + }, + } + + confirmation := d.Get("confirmation").(string) + if confirmation != "" { + properties.UserCreateParameterProperties.Confirmation = apimanagement.Confirmation(confirmation) + } + if note != "" { + properties.UserCreateParameterProperties.Note = utils.String(note) + } + if password != "" { + properties.UserCreateParameterProperties.Password = utils.String(password) + } + if state != "" { + properties.UserCreateParameterProperties.State = apimanagement.UserState(state) + } + + if _, err := client.CreateOrUpdate(ctx, resourceGroup, serviceName, userId, properties, ""); err != nil { + return fmt.Errorf("Error creating/updating User %q (API Management Service %q / Resource Group %q): %+v", userId, serviceName, resourceGroup, err) + } + + read, err := client.Get(ctx, resourceGroup, serviceName, userId) + if err != nil { + return fmt.Errorf("Error retrieving User %q (API Management Service %q / Resource Group %q): %+v", userId, serviceName, resourceGroup, err) + } + + if read.ID == nil { + return fmt.Errorf("Cannot read ID for User %q (API Management Service %q / Resource Group %q)", userId, serviceName, resourceGroup) + } + + d.SetId(*read.ID) + + return resourceArmApiManagementUserRead(d, meta) +} + +func resourceArmApiManagementUserRead(d *schema.ResourceData, meta interface{}) error { + client := meta.(*ArmClient).apiManagementUsersClient + ctx := meta.(*ArmClient).StopContext + + id, err := parseAzureResourceID(d.Id()) + if err != nil { + return err + } + + resourceGroup := id.ResourceGroup + serviceName := id.Path["service"] + userId := id.Path["users"] + + resp, err := client.Get(ctx, resourceGroup, serviceName, userId) + if err != nil { + if utils.ResponseWasNotFound(resp.Response) { + log.Printf("User %q was not found in API Management Service %q / Resource Group %q - removing from state!", userId, serviceName, resourceGroup) + d.SetId("") + return nil + } + + return fmt.Errorf("Error making Read request on User %q (API Management Service %q / Resource Group %q): %+v", userId, serviceName, resourceGroup, err) + } + + d.Set("user_id", userId) + d.Set("api_management_name", serviceName) + d.Set("resource_group_name", resourceGroup) + + if props := resp.UserContractProperties; props != nil { + d.Set("first_name", props.FirstName) + d.Set("last_name", props.LastName) + d.Set("email", props.Email) + d.Set("note", props.Note) + d.Set("state", string(props.State)) + } + + return nil +} + +func resourceArmApiManagementUserDelete(d *schema.ResourceData, meta interface{}) error { + client := meta.(*ArmClient).apiManagementUsersClient + ctx := meta.(*ArmClient).StopContext + + id, err := parseAzureResourceID(d.Id()) + if err != nil { + return err + } + resourceGroup := id.ResourceGroup + serviceName := id.Path["service"] + userId := id.Path["users"] + + log.Printf("[DEBUG] Deleting User %q (API Management Service %q / Resource Grouo %q)", userId, serviceName, resourceGroup) + deleteSubscriptions := utils.Bool(true) + notify := utils.Bool(false) + resp, err := client.Delete(ctx, resourceGroup, serviceName, userId, "", deleteSubscriptions, notify) + if err != nil { + if !utils.ResponseWasNotFound(resp) { + return fmt.Errorf("Error deleting User %q (API Management Service %q / Resource Group %q): %+v", userId, serviceName, resourceGroup, err) + } + } + + return nil +} diff --git a/azurerm/resource_arm_api_management_user_test.go b/azurerm/resource_arm_api_management_user_test.go new file mode 100644 index 000000000000..cd49b46c2580 --- /dev/null +++ b/azurerm/resource_arm_api_management_user_test.go @@ -0,0 +1,420 @@ +package azurerm + +import ( + "fmt" + "testing" + + "github.com/hashicorp/terraform/helper/resource" + "github.com/hashicorp/terraform/terraform" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" +) + +func TestAccAzureRMApiManagementUser_basic(t *testing.T) { + resourceName := "azurerm_api_management_user.test" + ri := tf.AccRandTimeInt() + location := testLocation() + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testCheckAzureRMApiManagementUserDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAzureRMApiManagementUser_basic(ri, location), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMApiManagementUserExists(resourceName), + resource.TestCheckResourceAttr(resourceName, "first_name", "Acceptance"), + resource.TestCheckResourceAttr(resourceName, "last_name", "Test"), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +func TestAccAzureRMApiManagementUser_requiresImport(t *testing.T) { + resourceName := "azurerm_api_management_user.test" + ri := tf.AccRandTimeInt() + location := testLocation() + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testCheckAzureRMApiManagementUserDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAzureRMApiManagementUser_basic(ri, location), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMApiManagementUserExists(resourceName), + ), + }, + { + Config: testAccAzureRMApiManagementUser_requiresImport(ri, location), + ExpectError: testRequiresImportError("azurerm_api_management_user"), + }, + }, + }) +} + +func TestAccAzureRMApiManagementUser_update(t *testing.T) { + resourceName := "azurerm_api_management_user.test" + ri := tf.AccRandTimeInt() + location := testLocation() + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testCheckAzureRMApiManagementUserDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAzureRMApiManagementUser_basic(ri, location), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMApiManagementUserExists(resourceName), + resource.TestCheckResourceAttr(resourceName, "first_name", "Acceptance"), + resource.TestCheckResourceAttr(resourceName, "last_name", "Test"), + resource.TestCheckResourceAttr(resourceName, "state", "pending"), + ), + }, + { + Config: testAccAzureRMApiManagementUser_updated(ri, location), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMApiManagementUserExists(resourceName), + resource.TestCheckResourceAttr(resourceName, "first_name", "Acceptance Updated"), + resource.TestCheckResourceAttr(resourceName, "last_name", "Test Updated"), + resource.TestCheckResourceAttr(resourceName, "state", "active"), + ), + }, + { + Config: testAccAzureRMApiManagementUser_basic(ri, location), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMApiManagementUserExists(resourceName), + resource.TestCheckResourceAttr(resourceName, "first_name", "Acceptance"), + resource.TestCheckResourceAttr(resourceName, "last_name", "Test"), + resource.TestCheckResourceAttr(resourceName, "state", "pending"), + ), + }, + }, + }) +} + +func TestAccAzureRMApiManagementUser_password(t *testing.T) { + resourceName := "azurerm_api_management_user.test" + ri := tf.AccRandTimeInt() + location := testLocation() + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testCheckAzureRMApiManagementUserDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAzureRMApiManagementUser_password(ri, location), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMApiManagementUserExists(resourceName), + resource.TestCheckResourceAttr(resourceName, "first_name", "Acceptance"), + resource.TestCheckResourceAttr(resourceName, "last_name", "Test"), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"password"}, + }, + }, + }) +} + +func TestAccAzureRMApiManagementUser_invite(t *testing.T) { + resourceName := "azurerm_api_management_user.test" + ri := tf.AccRandTimeInt() + location := testLocation() + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testCheckAzureRMApiManagementUserDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAzureRMApiManagementUser_invited(ri, location), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMApiManagementUserExists(resourceName), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{ + // not returned + "confirmation", + }, + }, + }, + }) +} + +func TestAccAzureRMApiManagementUser_signup(t *testing.T) { + resourceName := "azurerm_api_management_user.test" + ri := tf.AccRandTimeInt() + location := testLocation() + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testCheckAzureRMApiManagementUserDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAzureRMApiManagementUser_signUp(ri, location), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMApiManagementUserExists(resourceName), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{ + // not returned + "confirmation", + }, + }, + }, + }) +} + +func TestAccAzureRMApiManagementUser_complete(t *testing.T) { + resourceName := "azurerm_api_management_user.test" + ri := tf.AccRandTimeInt() + location := testLocation() + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testCheckAzureRMApiManagementUserDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAzureRMApiManagementUser_complete(ri, location), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMApiManagementUserExists(resourceName), + resource.TestCheckResourceAttr(resourceName, "first_name", "Acceptance"), + resource.TestCheckResourceAttr(resourceName, "last_name", "Test"), + resource.TestCheckResourceAttr(resourceName, "note", "Used for testing in dimension C-137."), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{ + // not returned + "confirmation", + }, + }, + }, + }) +} + +func testCheckAzureRMApiManagementUserDestroy(s *terraform.State) error { + conn := testAccProvider.Meta().(*ArmClient).apiManagementUsersClient + + for _, rs := range s.RootModule().Resources { + if rs.Type != "azurerm_api_management_user" { + continue + } + + userId := rs.Primary.Attributes["user_id"] + serviceName := rs.Primary.Attributes["api_management_name"] + resourceGroup := rs.Primary.Attributes["resource_group_name"] + ctx := testAccProvider.Meta().(*ArmClient).StopContext + resp, err := conn.Get(ctx, resourceGroup, serviceName, userId) + if err != nil { + if utils.ResponseWasNotFound(resp.Response) { + return nil + } + + return err + } + + return nil + } + + return nil +} + +func testCheckAzureRMApiManagementUserExists(resourceName 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[resourceName] + if !ok { + return fmt.Errorf("Not found: %s", resourceName) + } + + userId := rs.Primary.Attributes["user_id"] + serviceName := rs.Primary.Attributes["api_management_name"] + resourceGroup := rs.Primary.Attributes["resource_group_name"] + + conn := testAccProvider.Meta().(*ArmClient).apiManagementUsersClient + ctx := testAccProvider.Meta().(*ArmClient).StopContext + resp, err := conn.Get(ctx, resourceGroup, serviceName, userId) + if err != nil { + if utils.ResponseWasNotFound(resp.Response) { + return fmt.Errorf("Bad: User %q (API Management Service %q / Resource Group %q) does not exist", userId, serviceName, resourceGroup) + } + + return fmt.Errorf("Bad: Get on apiManagementUsersClient: %+v", err) + } + + return nil + } +} + +func testAccAzureRMApiManagementUser_basic(rInt int, location string) string { + template := testAccAzureRMApiManagementUser_template(rInt, location) + return fmt.Sprintf(` +%s + +resource "azurerm_api_management_user" "test" { + user_id = "acctestuser%d" + api_management_name = "${azurerm_api_management.test.name}" + resource_group_name = "${azurerm_resource_group.test.name}" + first_name = "Acceptance" + last_name = "Test" + email = "azure-acctest%d@hashicorptest.com" +} +`, template, rInt, rInt) +} + +func testAccAzureRMApiManagementUser_requiresImport(rInt int, location string) string { + template := testAccAzureRMApiManagementUser_basic(rInt, location) + return fmt.Sprintf(` +%s + +resource "azurerm_api_management_user" "import" { + user_id = "${azurerm_api_management_user.test.user_id}" + api_management_name = "${azurerm_api_management_user.test.api_management_name}" + resource_group_name = "${azurerm_api_management_user.test.resource_group_name}" + first_name = "${azurerm_api_management_user.test.first_name}" + last_name = "${azurerm_api_management_user.test.last_name}" + email = "${azurerm_api_management_user.test.email}" + state = "${azurerm_api_management_user.test.state}" +} +`, template) +} + +func testAccAzureRMApiManagementUser_password(rInt int, location string) string { + template := testAccAzureRMApiManagementUser_template(rInt, location) + return fmt.Sprintf(` +%s + +resource "azurerm_api_management_user" "test" { + user_id = "acctestuser%d" + api_management_name = "${azurerm_api_management.test.name}" + resource_group_name = "${azurerm_resource_group.test.name}" + first_name = "Acceptance" + last_name = "Test" + email = "azure-acctest%d@hashicorptest.com" + state = "active" + password = "3991bb15-282d-4b9b-9de3-3d5fc89eb530" +} +`, template, rInt, rInt) +} + +func testAccAzureRMApiManagementUser_updated(rInt int, location string) string { + template := testAccAzureRMApiManagementUser_template(rInt, location) + return fmt.Sprintf(` +%s + +resource "azurerm_api_management_user" "test" { + user_id = "acctestuser%d" + api_management_name = "${azurerm_api_management.test.name}" + resource_group_name = "${azurerm_resource_group.test.name}" + first_name = "Acceptance Updated" + last_name = "Test Updated" + email = "azure-acctest%d@hashicorptest.com" + state = "blocked" +} +`, template, rInt, rInt) +} + +func testAccAzureRMApiManagementUser_invited(rInt int, location string) string { + template := testAccAzureRMApiManagementUser_template(rInt, location) + return fmt.Sprintf(` +%s + +resource "azurerm_api_management_user" "test" { + user_id = "acctestuser%d" + api_management_name = "${azurerm_api_management.test.name}" + resource_group_name = "${azurerm_resource_group.test.name}" + first_name = "Acceptance" + last_name = "Test User" + email = "azure-acctest%d@hashicorptest.com" + state = "blocked" + confirmation = "invite" +} +`, template, rInt, rInt) +} + +func testAccAzureRMApiManagementUser_signUp(rInt int, location string) string { + template := testAccAzureRMApiManagementUser_template(rInt, location) + return fmt.Sprintf(` +%s + +resource "azurerm_api_management_user" "test" { + user_id = "acctestuser%d" + api_management_name = "${azurerm_api_management.test.name}" + resource_group_name = "${azurerm_resource_group.test.name}" + first_name = "Acceptance" + last_name = "Test User" + email = "azure-acctest%d@hashicorptest.com" + state = "blocked" + confirmation = "signup" +} +`, template, rInt, rInt) +} + +func testAccAzureRMApiManagementUser_complete(rInt int, location string) string { + template := testAccAzureRMApiManagementUser_template(rInt, location) + return fmt.Sprintf(` +%s + +resource "azurerm_api_management_user" "test" { + user_id = "acctestuser%d" + api_management_name = "${azurerm_api_management.test.name}" + resource_group_name = "${azurerm_resource_group.test.name}" + first_name = "Acceptance" + last_name = "Test" + email = "azure-acctest%d@hashicorptest.com" + state = "active" + confirmation = "signup" + notes = "Used for testing in dimension C-137." +} +`, template, rInt, rInt) +} + +func testAccAzureRMApiManagementUser_template(rInt int, location string) string { + return fmt.Sprintf(` +resource "azurerm_resource_group" "test" { + name = "acctestRG-%d" + location = "%s" +} + +resource "azurerm_api_management" "test" { + name = "acctestAM-%d" + location = "${azurerm_resource_group.test.location}" + resource_group_name = "${azurerm_resource_group.test.name}" + publisher_name = "pub1" + publisher_email = "pub1@email.com" + + sku { + name = "Developer" + capacity = 1 + } +} +`, rInt, location, rInt) +} diff --git a/website/docs/r/api_management_user.html.markdown b/website/docs/r/api_management_user.html.markdown new file mode 100644 index 000000000000..09c5a638e499 --- /dev/null +++ b/website/docs/r/api_management_user.html.markdown @@ -0,0 +1,86 @@ +--- +layout: "azurerm" +page_title: "Azure Resource Manager: azurerm_api_management_user" +sidebar_current: "docs-azurerm-resource-api-management-user" +description: |- + Manages an API Management User. +--- + +# azurerm_api_management_user + +Manages an API Management User. + +## Example Usage + +```hcl +resource "azurerm_resource_group" "test" { + name = "example-resources" + location = "West Europe" +} + +resource "azurerm_api_management" "test" { + name = "example-apim" + location = "${azurerm_resource_group.test.location}" + resource_group_name = "${azurerm_resource_group.test.name}" + publisher_name = "My Company" + publisher_email = "company@terraform.io" + + sku { + name = "Developer" + capacity = 1 + } +} + +resource "azurerm_api_management_user" "test" { + user_id = "5931a75ae4bbd512288c680b" + api_management_name = "${azurerm_api_management.test.name}" + resource_group_name = "${azurerm_resource_group.test.name}" + first_name = "Example" + last_name = "User" + email = "tom+tfdev@hashicorp.com" + state = "active" +} +``` + +## Argument Reference + +The following arguments are supported: + + +* `api_management_name` - (Required) The name of the API Management Service in which the User should be created. Changing this forces a new resource to be created. + +* `resource_group_name` - (Required) The name of the Resource Group in which the API Management Service exists. Changing this forces a new resource to be created. + +* `email` - (Required) The email address associated with this user. + +* `first_name` - (Required) The first name for this user. + +* `last_name` - (Required) The last name for this user. + +* `user_id` - (Required) The Identifier for this User, which must be unique within the API Management Service. Changing this forces a new resource to be created. + +--- + +* `confirmation` - (Optional) The kind of confirmation email which will be sent to this user. Possible values are `invite` and `signup`. Changing this forces a new resource to be created. + +* `note` - (Optional) A note about this user. + +* `password` - (Optional) The password associated with this user. + +* `state` - (Optional) The state of this user. Possible values are `active`, `blocked` and `pending`. + +-> **NOTE:** the State can be changed from Pending -> Active/Blocked but not from Active/Blocked -> Pending. + +## Attributes Reference + +In addition to all arguments above, the following attributes are exported: + +* `id` - The ID of the API Management User. + +## Import + +API Management Users can be imported using the `resource id`, e.g. + +```shell +terraform import azurerm_api_management_user.test /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/mygroup1/providers/Microsoft.ApiManagement/service/instance1/users/abc123 +``` From d2e30cc8ad43e91d8629423bc0fa4dbd76bef82e Mon Sep 17 00:00:00 2001 From: tombuildsstuff Date: Thu, 14 Feb 2019 16:10:22 +0100 Subject: [PATCH 2/7] New Data Source: `azurerm_api_management_user` --- azurerm/data_source_api_management_user.go | 78 +++++++++++++++++++ .../data_source_api_management_user_test.go | 74 ++++++++++++++++++ azurerm/helpers/azure/api_management.go | 8 ++ azurerm/provider.go | 1 + website/azurerm.erb | 4 + .../docs/d/api_management_user.html.markdown | 47 +++++++++++ 6 files changed, 212 insertions(+) create mode 100644 azurerm/data_source_api_management_user.go create mode 100644 azurerm/data_source_api_management_user_test.go create mode 100644 website/docs/d/api_management_user.html.markdown diff --git a/azurerm/data_source_api_management_user.go b/azurerm/data_source_api_management_user.go new file mode 100644 index 000000000000..71c7333b1ad0 --- /dev/null +++ b/azurerm/data_source_api_management_user.go @@ -0,0 +1,78 @@ +package azurerm + +import ( + "fmt" + + "github.com/hashicorp/terraform/helper/schema" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" +) + +func dataSourceArmApiManagementUser() *schema.Resource { + return &schema.Resource{ + Read: dataSourceArmApiManagementUserRead, + + Schema: map[string]*schema.Schema{ + "user_id": azure.SchemaApiManagementUserDataSourceName(), + + "api_management_name": azure.SchemaApiManagementDataSourceName(), + + "resource_group_name": resourceGroupNameForDataSourceSchema(), + + "first_name": { + Type: schema.TypeString, + Computed: true, + }, + + "last_name": { + Type: schema.TypeString, + Computed: true, + }, + + "email": { + Type: schema.TypeString, + Computed: true, + }, + + "state": { + Type: schema.TypeString, + Computed: true, + }, + + "note": { + Type: schema.TypeString, + Computed: true, + }, + }, + } +} + +func dataSourceArmApiManagementUserRead(d *schema.ResourceData, meta interface{}) error { + client := meta.(*ArmClient).apiManagementUsersClient + ctx := meta.(*ArmClient).StopContext + + resourceGroup := d.Get("resource_group_name").(string) + serviceName := d.Get("api_management_name").(string) + userId := d.Get("user_id").(string) + + resp, err := client.Get(ctx, resourceGroup, serviceName, userId) + if err != nil { + if utils.ResponseWasNotFound(resp.Response) { + return fmt.Errorf("User %q was not found in API Management Service %q / Resource Group %q", userId, serviceName, resourceGroup) + } + + return fmt.Errorf("Error making Read request on User %q (API Management Service %q / Resource Group %q): %+v", userId, serviceName, resourceGroup, err) + } + + d.SetId(*resp.ID) + + if props := resp.UserContractProperties; props != nil { + d.Set("first_name", props.FirstName) + d.Set("last_name", props.LastName) + d.Set("email", props.Email) + d.Set("note", props.Note) + d.Set("state", string(props.State)) + } + + return nil +} diff --git a/azurerm/data_source_api_management_user_test.go b/azurerm/data_source_api_management_user_test.go new file mode 100644 index 000000000000..d9e2757a9e46 --- /dev/null +++ b/azurerm/data_source_api_management_user_test.go @@ -0,0 +1,74 @@ +package azurerm + +import ( + "fmt" + "testing" + + "github.com/hashicorp/terraform/helper/resource" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" +) + +func TestAccDataSourceAzureRMApiManagementUser_basic(t *testing.T) { + dataSourceName := "data.azurerm_api_management_user.test" + rInt := tf.AccRandTimeInt() + location := testLocation() + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + Steps: []resource.TestStep{ + { + Config: testAccDataSourceApiManagementUser_basic(rInt, location), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr(dataSourceName, "user_id", "test-user"), + resource.TestCheckResourceAttr(dataSourceName, "first_name", "Acceptance"), + resource.TestCheckResourceAttr(dataSourceName, "last_name", "Test"), + resource.TestCheckResourceAttr(dataSourceName, "email", fmt.Sprintf("azure-acctest%d@hashicorptest.com", rInt)), + resource.TestCheckResourceAttr(dataSourceName, "state", "active"), + resource.TestCheckResourceAttr(dataSourceName, "notes", "Used for testing in dimension C-137."), + ), + }, + }, + }) +} + +func testAccDataSourceApiManagementUser_basic(rInt int, location string) string { + return fmt.Sprintf(` +resource "azurerm_resource_group" "test" { + name = "amtestRG-%d" + location = "%s" +} + +resource "azurerm_api_management" "test" { + name = "acctestAM-%d" + publisher_name = "pub1" + publisher_email = "pub1@email.com" + + sku { + name = "Developer" + capacity = 1 + } + + location = "${azurerm_resource_group.test.location}" + resource_group_name = "${azurerm_resource_group.test.name}" +} + + +resource "azurerm_api_management_user" "test" { + user_id = "test-user" + api_management_name = "${azurerm_api_management.test.name}" + resource_group_name = "${azurerm_resource_group.test.name}" + first_name = "Acceptance" + last_name = "Test" + email = "azure-acctest%d@hashicorptest.com" + state = "active" + notes = "Used for testing in dimension C-137." +} + +data "azurerm_api_management_user" "test" { + user_id = "${azurerm_api_management_user.test.user_id}" + api_management_name = "${azurerm_api_management_user.test.api_management_name}" + resource_group_name = "${azurerm_api_management_user.test.resource_group_name}" +} +`, rInt, location, rInt, rInt) +} diff --git a/azurerm/helpers/azure/api_management.go b/azurerm/helpers/azure/api_management.go index bda1e3327940..8eced21d8b8f 100644 --- a/azurerm/helpers/azure/api_management.go +++ b/azurerm/helpers/azure/api_management.go @@ -51,3 +51,11 @@ func SchemaApiManagementUserName() *schema.Schema { ValidateFunc: validate.ApiManagementUserName, } } + +func SchemaApiManagementUserDataSourceName() *schema.Schema { + return &schema.Schema{ + Type: schema.TypeString, + Required: true, + ValidateFunc: validate.ApiManagementUserName, + } +} diff --git a/azurerm/provider.go b/azurerm/provider.go index 4ac8a4aeb28a..9429b84147b4 100644 --- a/azurerm/provider.go +++ b/azurerm/provider.go @@ -101,6 +101,7 @@ func Provider() terraform.ResourceProvider { "azurerm_api_management": dataSourceApiManagementService(), "azurerm_api_management_group": dataSourceApiManagementGroup(), "azurerm_api_management_product": dataSourceApiManagementProduct(), + "azurerm_api_management_user": dataSourceArmApiManagementUser(), "azurerm_app_service_plan": dataSourceAppServicePlan(), "azurerm_app_service": dataSourceArmAppService(), "azurerm_application_insights": dataSourceArmApplicationInsights(), diff --git a/website/azurerm.erb b/website/azurerm.erb index c96e5009e98f..396b72a4004f 100644 --- a/website/azurerm.erb +++ b/website/azurerm.erb @@ -71,6 +71,10 @@ azurerm_api_management_product + > + azurerm_api_management_user + + > azurerm_application_security_group diff --git a/website/docs/d/api_management_user.html.markdown b/website/docs/d/api_management_user.html.markdown new file mode 100644 index 000000000000..643d9f8184b0 --- /dev/null +++ b/website/docs/d/api_management_user.html.markdown @@ -0,0 +1,47 @@ +--- +layout: "azurerm" +page_title: "Azure Resource Manager: azurerm_api_management_user" +sidebar_current: "docs-azurerm-datasource-api-management-user" +description: |- + Gets information about an existing API Management User. +--- + +# Data Source: azurerm_api_management_user + +Use this data source to access information about an existing API Management User. + +## Example Usage + +```hcl +data "azurerm_api_management_user" "test" { + user_id = "my-user" + api_management_name = "example-apim + resource_group_name = "search-service" +} + +output "notes" { + value = "${data.azurerm_api_management_user.test.notes}" +} +``` + +## Argument Reference + +* `api_management_name` - (Required) The Name of the API Management Service in which this User exists. + +* `resource_group_name` - (Required) The Name of the Resource Group in which the API Management Service exists. + +* `user_id` - (Required) The Identifier for the User. + +## Attributes Reference + +* `id` - The ID of the API Management User. + +* `first_name` - The First Name for the User. + +* `last_name` - The Last Name for the User. + +* `email` - The Email Address used for this User. + +* `note` - Any notes about this User. + +* `state` - The current state of this User, for example `active`, `blocked` or `pending`. \ No newline at end of file From 2ad44df5737249a78484e103c6c048ac8b63ef7d Mon Sep 17 00:00:00 2001 From: tombuildsstuff Date: Wed, 27 Feb 2019 13:58:08 +0100 Subject: [PATCH 3/7] Switching to the older API --- azurerm/resource_arm_api_management_user.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/azurerm/resource_arm_api_management_user.go b/azurerm/resource_arm_api_management_user.go index f1067f407214..ef242af6cfdd 100644 --- a/azurerm/resource_arm_api_management_user.go +++ b/azurerm/resource_arm_api_management_user.go @@ -4,7 +4,7 @@ import ( "fmt" "log" - "github.com/Azure/azure-sdk-for-go/services/preview/apimanagement/mgmt/2018-06-01-preview/apimanagement" + "github.com/Azure/azure-sdk-for-go/services/apimanagement/mgmt/2018-01-01/apimanagement" "github.com/hashicorp/terraform/helper/schema" "github.com/hashicorp/terraform/helper/validation" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure" From ea90cd7f19f2aa17443c5a81a3c4e2aa08221eb7 Mon Sep 17 00:00:00 2001 From: tombuildsstuff Date: Wed, 27 Feb 2019 14:45:44 +0100 Subject: [PATCH 4/7] fixing issues from code review --- azurerm/data_source_api_management_user.go | 8 +++---- azurerm/resource_arm_api_management_user.go | 26 ++++++++++----------- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/azurerm/data_source_api_management_user.go b/azurerm/data_source_api_management_user.go index 71c7333b1ad0..350844ff2d65 100644 --- a/azurerm/data_source_api_management_user.go +++ b/azurerm/data_source_api_management_user.go @@ -24,22 +24,22 @@ func dataSourceArmApiManagementUser() *schema.Resource { Computed: true, }, - "last_name": { + "email": { Type: schema.TypeString, Computed: true, }, - "email": { + "last_name": { Type: schema.TypeString, Computed: true, }, - "state": { + "note": { Type: schema.TypeString, Computed: true, }, - "note": { + "state": { Type: schema.TypeString, Computed: true, }, diff --git a/azurerm/resource_arm_api_management_user.go b/azurerm/resource_arm_api_management_user.go index ef242af6cfdd..5fef2c29a93e 100644 --- a/azurerm/resource_arm_api_management_user.go +++ b/azurerm/resource_arm_api_management_user.go @@ -36,29 +36,18 @@ func resourceArmApiManagementUser() *schema.Resource { ValidateFunc: validate.NoEmptyStrings, }, - "last_name": { + "email": { Type: schema.TypeString, Required: true, ValidateFunc: validate.NoEmptyStrings, }, - "email": { + "last_name": { Type: schema.TypeString, Required: true, ValidateFunc: validate.NoEmptyStrings, }, - "state": { - Type: schema.TypeString, - Optional: true, - Computed: true, - ValidateFunc: validation.StringInSlice([]string{ - string(apimanagement.UserStateActive), - string(apimanagement.UserStateBlocked), - string(apimanagement.UserStatePending), - }, false), - }, - "confirmation": { Type: schema.TypeString, Optional: true, @@ -79,6 +68,17 @@ func resourceArmApiManagementUser() *schema.Resource { Optional: true, Sensitive: true, }, + + "state": { + Type: schema.TypeString, + Optional: true, + Computed: true, + ValidateFunc: validation.StringInSlice([]string{ + string(apimanagement.UserStateActive), + string(apimanagement.UserStateBlocked), + string(apimanagement.UserStatePending), + }, false), + }, }, } } From 8ee0985b5a9bd6dd526bd0389e1af7c9986d0a12 Mon Sep 17 00:00:00 2001 From: tombuildsstuff Date: Wed, 27 Feb 2019 15:28:12 +0100 Subject: [PATCH 5/7] test failure: `notes` -> `note` --- azurerm/data_source_api_management_user_test.go | 4 ++-- azurerm/resource_arm_api_management_user_test.go | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/azurerm/data_source_api_management_user_test.go b/azurerm/data_source_api_management_user_test.go index d9e2757a9e46..45aaad65bacb 100644 --- a/azurerm/data_source_api_management_user_test.go +++ b/azurerm/data_source_api_management_user_test.go @@ -25,7 +25,7 @@ func TestAccDataSourceAzureRMApiManagementUser_basic(t *testing.T) { resource.TestCheckResourceAttr(dataSourceName, "last_name", "Test"), resource.TestCheckResourceAttr(dataSourceName, "email", fmt.Sprintf("azure-acctest%d@hashicorptest.com", rInt)), resource.TestCheckResourceAttr(dataSourceName, "state", "active"), - resource.TestCheckResourceAttr(dataSourceName, "notes", "Used for testing in dimension C-137."), + resource.TestCheckResourceAttr(dataSourceName, "note", "Used for testing in dimension C-137."), ), }, }, @@ -62,7 +62,7 @@ resource "azurerm_api_management_user" "test" { last_name = "Test" email = "azure-acctest%d@hashicorptest.com" state = "active" - notes = "Used for testing in dimension C-137." + note = "Used for testing in dimension C-137." } data "azurerm_api_management_user" "test" { diff --git a/azurerm/resource_arm_api_management_user_test.go b/azurerm/resource_arm_api_management_user_test.go index cd49b46c2580..59cdd742110a 100644 --- a/azurerm/resource_arm_api_management_user_test.go +++ b/azurerm/resource_arm_api_management_user_test.go @@ -392,7 +392,7 @@ resource "azurerm_api_management_user" "test" { email = "azure-acctest%d@hashicorptest.com" state = "active" confirmation = "signup" - notes = "Used for testing in dimension C-137." + note = "Used for testing in dimension C-137." } `, template, rInt, rInt) } From 7b541e73aea8d28aa40396efadeb8258a2fec0d9 Mon Sep 17 00:00:00 2001 From: tombuildsstuff Date: Wed, 27 Feb 2019 16:20:05 +0100 Subject: [PATCH 6/7] switching to use a fake email domain --- azurerm/data_source_api_management_user_test.go | 2 +- azurerm/resource_arm_api_management_user_test.go | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/azurerm/data_source_api_management_user_test.go b/azurerm/data_source_api_management_user_test.go index 45aaad65bacb..c9c808566d82 100644 --- a/azurerm/data_source_api_management_user_test.go +++ b/azurerm/data_source_api_management_user_test.go @@ -60,7 +60,7 @@ resource "azurerm_api_management_user" "test" { resource_group_name = "${azurerm_resource_group.test.name}" first_name = "Acceptance" last_name = "Test" - email = "azure-acctest%d@hashicorptest.com" + email = "azure-acctest%d@example.com" state = "active" note = "Used for testing in dimension C-137." } diff --git a/azurerm/resource_arm_api_management_user_test.go b/azurerm/resource_arm_api_management_user_test.go index 59cdd742110a..794c006cb97a 100644 --- a/azurerm/resource_arm_api_management_user_test.go +++ b/azurerm/resource_arm_api_management_user_test.go @@ -285,7 +285,7 @@ resource "azurerm_api_management_user" "test" { resource_group_name = "${azurerm_resource_group.test.name}" first_name = "Acceptance" last_name = "Test" - email = "azure-acctest%d@hashicorptest.com" + email = "azure-acctest%d@example.com" } `, template, rInt, rInt) } @@ -318,7 +318,7 @@ resource "azurerm_api_management_user" "test" { resource_group_name = "${azurerm_resource_group.test.name}" first_name = "Acceptance" last_name = "Test" - email = "azure-acctest%d@hashicorptest.com" + email = "azure-acctest%d@example.com" state = "active" password = "3991bb15-282d-4b9b-9de3-3d5fc89eb530" } @@ -336,7 +336,7 @@ resource "azurerm_api_management_user" "test" { resource_group_name = "${azurerm_resource_group.test.name}" first_name = "Acceptance Updated" last_name = "Test Updated" - email = "azure-acctest%d@hashicorptest.com" + email = "azure-acctest%d@example.com" state = "blocked" } `, template, rInt, rInt) @@ -353,7 +353,7 @@ resource "azurerm_api_management_user" "test" { resource_group_name = "${azurerm_resource_group.test.name}" first_name = "Acceptance" last_name = "Test User" - email = "azure-acctest%d@hashicorptest.com" + email = "azure-acctest%d@example.com" state = "blocked" confirmation = "invite" } @@ -371,7 +371,7 @@ resource "azurerm_api_management_user" "test" { resource_group_name = "${azurerm_resource_group.test.name}" first_name = "Acceptance" last_name = "Test User" - email = "azure-acctest%d@hashicorptest.com" + email = "azure-acctest%d@example.com" state = "blocked" confirmation = "signup" } @@ -389,7 +389,7 @@ resource "azurerm_api_management_user" "test" { resource_group_name = "${azurerm_resource_group.test.name}" first_name = "Acceptance" last_name = "Test" - email = "azure-acctest%d@hashicorptest.com" + email = "azure-acctest%d@example.com" state = "active" confirmation = "signup" note = "Used for testing in dimension C-137." From 9994fd26e419b9a855e79e365dc826b9f583a18f Mon Sep 17 00:00:00 2001 From: tombuildsstuff Date: Wed, 27 Feb 2019 16:52:26 +0100 Subject: [PATCH 7/7] fixing the tests --- .../resource_arm_api_management_user_test.go | 34 +++++++++++++++---- 1 file changed, 28 insertions(+), 6 deletions(-) diff --git a/azurerm/resource_arm_api_management_user_test.go b/azurerm/resource_arm_api_management_user_test.go index 794c006cb97a..6fa655c423f5 100644 --- a/azurerm/resource_arm_api_management_user_test.go +++ b/azurerm/resource_arm_api_management_user_test.go @@ -38,6 +38,11 @@ func TestAccAzureRMApiManagementUser_basic(t *testing.T) { } func TestAccAzureRMApiManagementUser_requiresImport(t *testing.T) { + if !requireResourcesToBeImported { + t.Skip("Skipping since resources aren't required to be imported") + return + } + resourceName := "azurerm_api_management_user.test" ri := tf.AccRandTimeInt() location := testLocation() @@ -77,25 +82,25 @@ func TestAccAzureRMApiManagementUser_update(t *testing.T) { testCheckAzureRMApiManagementUserExists(resourceName), resource.TestCheckResourceAttr(resourceName, "first_name", "Acceptance"), resource.TestCheckResourceAttr(resourceName, "last_name", "Test"), - resource.TestCheckResourceAttr(resourceName, "state", "pending"), + resource.TestCheckResourceAttr(resourceName, "state", "active"), ), }, { - Config: testAccAzureRMApiManagementUser_updated(ri, location), + Config: testAccAzureRMApiManagementUser_updatedBlocked(ri, location), Check: resource.ComposeTestCheckFunc( testCheckAzureRMApiManagementUserExists(resourceName), resource.TestCheckResourceAttr(resourceName, "first_name", "Acceptance Updated"), resource.TestCheckResourceAttr(resourceName, "last_name", "Test Updated"), - resource.TestCheckResourceAttr(resourceName, "state", "active"), + resource.TestCheckResourceAttr(resourceName, "state", "blocked"), ), }, { - Config: testAccAzureRMApiManagementUser_basic(ri, location), + Config: testAccAzureRMApiManagementUser_updatedActive(ri, location), Check: resource.ComposeTestCheckFunc( testCheckAzureRMApiManagementUserExists(resourceName), resource.TestCheckResourceAttr(resourceName, "first_name", "Acceptance"), resource.TestCheckResourceAttr(resourceName, "last_name", "Test"), - resource.TestCheckResourceAttr(resourceName, "state", "pending"), + resource.TestCheckResourceAttr(resourceName, "state", "active"), ), }, }, @@ -325,7 +330,24 @@ resource "azurerm_api_management_user" "test" { `, template, rInt, rInt) } -func testAccAzureRMApiManagementUser_updated(rInt int, location string) string { +func testAccAzureRMApiManagementUser_updatedActive(rInt int, location string) string { + template := testAccAzureRMApiManagementUser_template(rInt, location) + return fmt.Sprintf(` +%s + +resource "azurerm_api_management_user" "test" { + user_id = "acctestuser%d" + api_management_name = "${azurerm_api_management.test.name}" + resource_group_name = "${azurerm_resource_group.test.name}" + first_name = "Acceptance" + last_name = "Test" + email = "azure-acctest%d@example.com" + state = "active" +} +`, template, rInt, rInt) +} + +func testAccAzureRMApiManagementUser_updatedBlocked(rInt int, location string) string { template := testAccAzureRMApiManagementUser_template(rInt, location) return fmt.Sprintf(` %s