-
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.
New Data Source:
azurerm_builtin_role_definition
``` $ acctests azurerm TestAccDataSourceAzureRMBuiltInRoleDefinition_ === RUN TestAccDataSourceAzureRMBuiltInRoleDefinition_contributor --- PASS: TestAccDataSourceAzureRMBuiltInRoleDefinition_contributor (8.28s) === RUN TestAccDataSourceAzureRMBuiltInRoleDefinition_owner --- PASS: TestAccDataSourceAzureRMBuiltInRoleDefinition_owner (7.63s) === RUN TestAccDataSourceAzureRMBuiltInRoleDefinition_reader --- PASS: TestAccDataSourceAzureRMBuiltInRoleDefinition_reader (7.06s) === RUN TestAccDataSourceAzureRMBuiltInRoleDefinition_virtualMachineContributor --- PASS: TestAccDataSourceAzureRMBuiltInRoleDefinition_virtualMachineContributor (7.68s) PASS ok github.com/terraform-providers/terraform-provider-azurerm/azurerm 30.676s ```
- Loading branch information
1 parent
7bba42a
commit 2f3fa9e
Showing
6 changed files
with
191 additions
and
15 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,41 @@ | ||
package azurerm | ||
|
||
import ( | ||
"github.com/hashicorp/terraform/helper/schema" | ||
"github.com/hashicorp/terraform/helper/validation" | ||
) | ||
|
||
func dataSourceArmBuiltInRoleDefinition() *schema.Resource { | ||
return &schema.Resource{ | ||
Read: dataSourceArmBuiltInRoleDefinitionRead, | ||
Schema: map[string]*schema.Schema{ | ||
"name": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
ValidateFunc: validation.StringInSlice([]string{ | ||
"Contributor", | ||
"Reader", | ||
"Owner", | ||
"VirtualMachineContributor", | ||
}, false), | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func dataSourceArmBuiltInRoleDefinitionRead(d *schema.ResourceData, meta interface{}) error { | ||
name := d.Get("name").(string) | ||
roleDefinitionIds := map[string]string{ | ||
"Contributor": "b24988ac-6180-42a0-ab88-20f7382dd24c", | ||
"Owner": "8e3af657-a8ff-443c-a75c-2fe8c4bcb635", | ||
"Reader": "acdd72a7-3385-48ef-bd42-f606fba81ae7", | ||
"VirtualMachineContributor": "d73bb868-a0df-4d4d-bd69-98a00b01fccb", | ||
} | ||
roleDefinitionId := roleDefinitionIds[name] | ||
|
||
// TODO: when the API's fixed - pull out additional information from the API | ||
|
||
d.SetId(roleDefinitionId) | ||
|
||
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,80 @@ | ||
package azurerm | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform/helper/resource" | ||
) | ||
|
||
func TestAccDataSourceAzureRMBuiltInRoleDefinition_contributor(t *testing.T) { | ||
dataSourceName := "data.azurerm_builtin_role_definition.test" | ||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
Providers: testAccProviders, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccDataSourceBuiltInRoleDefinition("Contributor"), | ||
Check: resource.ComposeTestCheckFunc( | ||
testAzureRMClientConfigAttr(dataSourceName, "id", "b24988ac-6180-42a0-ab88-20f7382dd24c"), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func TestAccDataSourceAzureRMBuiltInRoleDefinition_owner(t *testing.T) { | ||
dataSourceName := "data.azurerm_builtin_role_definition.test" | ||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
Providers: testAccProviders, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccDataSourceBuiltInRoleDefinition("Owner"), | ||
Check: resource.ComposeTestCheckFunc( | ||
testAzureRMClientConfigAttr(dataSourceName, "id", "8e3af657-a8ff-443c-a75c-2fe8c4bcb635"), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func TestAccDataSourceAzureRMBuiltInRoleDefinition_reader(t *testing.T) { | ||
dataSourceName := "data.azurerm_builtin_role_definition.test" | ||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
Providers: testAccProviders, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccDataSourceBuiltInRoleDefinition("Reader"), | ||
Check: resource.ComposeTestCheckFunc( | ||
testAzureRMClientConfigAttr(dataSourceName, "id", "acdd72a7-3385-48ef-bd42-f606fba81ae7"), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func TestAccDataSourceAzureRMBuiltInRoleDefinition_virtualMachineContributor(t *testing.T) { | ||
dataSourceName := "data.azurerm_builtin_role_definition.test" | ||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
Providers: testAccProviders, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccDataSourceBuiltInRoleDefinition("VirtualMachineContributor"), | ||
Check: resource.ComposeTestCheckFunc( | ||
testAzureRMClientConfigAttr(dataSourceName, "id", "d73bb868-a0df-4d4d-bd69-98a00b01fccb"), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testAccDataSourceBuiltInRoleDefinition(name string) string { | ||
return fmt.Sprintf(` | ||
data "azurerm_builtin_role_definition" "test" { | ||
name = "%s" | ||
} | ||
`, name) | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
--- | ||
layout: "azurerm" | ||
page_title: "Azure Resource Manager: azurerm_builtin_role_definition" | ||
sidebar_current: "docs-azurerm-datasource-builtin-role-definition" | ||
description: |- | ||
Get information about a built-in Role Definition. | ||
--- | ||
|
||
# azurerm_built_in_role_definition | ||
|
||
Use this data source to access the properties of a built-in Role Definition. | ||
|
||
## Example Usage | ||
|
||
```hcl | ||
data "azurerm_builtin_role_definition" "contributor" { | ||
name = "Contributor" | ||
} | ||
output "contributor_role_definition_id" { | ||
value = "${data.azurerm_built_in_role.contributor.id}" | ||
} | ||
``` | ||
|
||
## Argument Reference | ||
|
||
* `name` - (Required) Specifies the name of the built-in Role Definition. Possible values are: `Contributor`, `Owner`, `Reader` and `VirtualMachineContributor`. | ||
|
||
|
||
## Attributes Reference | ||
|
||
* `id` - the ID of the built-in Role Definition. |