-
Notifications
You must be signed in to change notification settings - Fork 4.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
New Data Source: azurerm_builtin_role_definition
#384
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
7bba42a
Refactoring Resource Group
tombuildsstuff 2f3fa9e
New Data Source: `azurerm_builtin_role_definition`
tombuildsstuff b387d67
Adding the vendored authorization sdk
tombuildsstuff 2c24fce
Removing the Role Assignments/Definitions clients for the moment
tombuildsstuff 1eacca5
Adding in the issue
tombuildsstuff File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,42 @@ | ||
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'll open a bug shortly and link that here |
||
// https://github.com/Azure/azure-rest-api-specs/issues/1785 | ||
|
||
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
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. |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
these are Constants within Azure - I've confirmed this within the Azure Portal and in a third-party ARM Template.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this documented anywhere publicly - i.e. can we possibly link to any doc page from here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not that I've seen, I found these in an ARM Template and confirmed the values in the HTML source of the Azure Portal - so I can confirm they're right.
A search for the GUID doesn't bring up anything official from MS - but does confirm it's a global constant ¯_(ツ)_/¯