forked from hashicorp/terraform-provider-azurerm
-
Notifications
You must be signed in to change notification settings - Fork 0
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 #1 from terraform-providers/master
Merge base
- Loading branch information
Showing
665 changed files
with
317,369 additions
and
3,086 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
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,102 @@ | ||
package azurerm | ||
|
||
import ( | ||
"fmt" | ||
|
||
"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), | ||
}, | ||
|
||
// Computed | ||
"description": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"type": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"permissions": { | ||
Type: schema.TypeList, | ||
Computed: true, | ||
Elem: &schema.Resource{ | ||
Schema: map[string]*schema.Schema{ | ||
"actions": { | ||
Type: schema.TypeList, | ||
Computed: true, | ||
Elem: &schema.Schema{ | ||
Type: schema.TypeString, | ||
}, | ||
}, | ||
"not_actions": { | ||
Type: schema.TypeList, | ||
Computed: true, | ||
Elem: &schema.Schema{ | ||
Type: schema.TypeString, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
"assignable_scopes": { | ||
Type: schema.TypeList, | ||
Computed: true, | ||
Elem: &schema.Schema{ | ||
Type: schema.TypeString, | ||
}, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func dataSourceArmBuiltInRoleDefinitionRead(d *schema.ResourceData, meta interface{}) error { | ||
client := meta.(*ArmClient).roleDefinitionsClient | ||
name := d.Get("name").(string) | ||
roleDefinitionIds := map[string]string{ | ||
"Contributor": "/providers/Microsoft.Authorization/roleDefinitions/b24988ac-6180-42a0-ab88-20f7382dd24c", | ||
"Owner": "/providers/Microsoft.Authorization/roleDefinitions/8e3af657-a8ff-443c-a75c-2fe8c4bcb635", | ||
"Reader": "/providers/Microsoft.Authorization/roleDefinitions/acdd72a7-3385-48ef-bd42-f606fba81ae7", | ||
"VirtualMachineContributor": "/providers/Microsoft.Authorization/roleDefinitions/d73bb868-a0df-4d4d-bd69-98a00b01fccb", | ||
} | ||
roleDefinitionId := roleDefinitionIds[name] | ||
|
||
d.SetId(roleDefinitionId) | ||
|
||
role, err := client.GetByID(roleDefinitionId) | ||
if err != nil { | ||
return fmt.Errorf("Error loadng Role Definition: %+v", err) | ||
} | ||
|
||
if props := role.Properties; props != nil { | ||
d.Set("name", props.RoleName) | ||
d.Set("description", props.Description) | ||
d.Set("type", props.Type) | ||
|
||
permissions := flattenRoleDefinitionPermissions(props.Permissions) | ||
if err := d.Set("permissions", permissions); err != nil { | ||
return err | ||
} | ||
|
||
assignableScopes := flattenRoleDefinitionAssignableScopes(props.AssignableScopes) | ||
if err := d.Set("assignable_scopes", assignableScopes); err != nil { | ||
return err | ||
} | ||
} | ||
|
||
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,108 @@ | ||
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", "/providers/Microsoft.Authorization/roleDefinitions/b24988ac-6180-42a0-ab88-20f7382dd24c"), | ||
resource.TestCheckResourceAttrSet(dataSourceName, "description"), | ||
resource.TestCheckResourceAttrSet(dataSourceName, "type"), | ||
resource.TestCheckResourceAttr(dataSourceName, "permissions.#", "1"), | ||
resource.TestCheckResourceAttr(dataSourceName, "permissions.0.actions.#", "1"), | ||
resource.TestCheckResourceAttr(dataSourceName, "permissions.0.actions.0", "*"), | ||
resource.TestCheckResourceAttr(dataSourceName, "permissions.0.not_actions.#", "3"), | ||
resource.TestCheckResourceAttr(dataSourceName, "permissions.0.not_actions.0", "Microsoft.Authorization/*/Delete"), | ||
resource.TestCheckResourceAttr(dataSourceName, "permissions.0.not_actions.1", "Microsoft.Authorization/*/Write"), | ||
resource.TestCheckResourceAttr(dataSourceName, "permissions.0.not_actions.2", "Microsoft.Authorization/elevateAccess/Action"), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
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", "/providers/Microsoft.Authorization/roleDefinitions/8e3af657-a8ff-443c-a75c-2fe8c4bcb635"), | ||
resource.TestCheckResourceAttrSet(dataSourceName, "description"), | ||
resource.TestCheckResourceAttrSet(dataSourceName, "type"), | ||
resource.TestCheckResourceAttr(dataSourceName, "permissions.#", "1"), | ||
resource.TestCheckResourceAttr(dataSourceName, "permissions.0.actions.#", "1"), | ||
resource.TestCheckResourceAttr(dataSourceName, "permissions.0.actions.0", "*"), | ||
resource.TestCheckResourceAttr(dataSourceName, "permissions.0.not_actions.#", "0"), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
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", "/providers/Microsoft.Authorization/roleDefinitions/acdd72a7-3385-48ef-bd42-f606fba81ae7"), | ||
resource.TestCheckResourceAttrSet(dataSourceName, "description"), | ||
resource.TestCheckResourceAttrSet(dataSourceName, "type"), | ||
resource.TestCheckResourceAttr(dataSourceName, "permissions.#", "1"), | ||
resource.TestCheckResourceAttr(dataSourceName, "permissions.0.actions.#", "1"), | ||
resource.TestCheckResourceAttr(dataSourceName, "permissions.0.actions.0", "*/read"), | ||
resource.TestCheckResourceAttr(dataSourceName, "permissions.0.not_actions.#", "0"), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
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", "/providers/Microsoft.Authorization/roleDefinitions/d73bb868-a0df-4d4d-bd69-98a00b01fccb"), | ||
resource.TestCheckResourceAttrSet(dataSourceName, "description"), | ||
resource.TestCheckResourceAttrSet(dataSourceName, "type"), | ||
resource.TestCheckResourceAttr(dataSourceName, "permissions.#", "1"), | ||
resource.TestCheckResourceAttr(dataSourceName, "permissions.0.actions.#", "17"), | ||
resource.TestCheckResourceAttr(dataSourceName, "permissions.0.actions.0", "Microsoft.Authorization/*/read"), | ||
resource.TestCheckResourceAttr(dataSourceName, "permissions.0.actions.15", "Microsoft.Resources/subscriptions/resourceGroups/read"), | ||
resource.TestCheckResourceAttr(dataSourceName, "permissions.0.not_actions.#", "0"), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testAccDataSourceBuiltInRoleDefinition(name string) string { | ||
return fmt.Sprintf(` | ||
data "azurerm_builtin_role_definition" "test" { | ||
name = "%s" | ||
} | ||
`, name) | ||
} |
Oops, something went wrong.