-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2954 from terraform-providers/f/api-management-users
New Resource/Data Source: `azurerm_api_management_user`
- Loading branch information
Showing
11 changed files
with
986 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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, | ||
}, | ||
|
||
"email": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
|
||
"last_name": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
|
||
"note": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
|
||
"state": { | ||
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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%[email protected]", rInt)), | ||
resource.TestCheckResourceAttr(dataSourceName, "state", "active"), | ||
resource.TestCheckResourceAttr(dataSourceName, "note", "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 = "[email protected]" | ||
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%[email protected]" | ||
state = "active" | ||
note = "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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.