Skip to content
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

r/lighthouse: Expose principal_id_display_name field #10613

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,12 @@ func resourceLighthouseDefinition() *schema.Resource {
Required: true,
ValidateFunc: validation.IsUUID,
},

"principal_display_name": {
Type: schema.TypeString,
Optional: true,
ValidateFunc: validation.StringIsNotEmpty,
},
},
},
},
Expand Down Expand Up @@ -225,9 +231,15 @@ func flattenLighthouseDefinitionAuthorization(input *[]managedservices.Authoriza
roleDefinitionID = *item.RoleDefinitionID
}

principalIDDisplayName := ""
if item.PrincipalIDDisplayName != nil {
principalIDDisplayName = *item.PrincipalIDDisplayName
}

results = append(results, map[string]interface{}{
"role_definition_id": roleDefinitionID,
"principal_id": principalID,
"role_definition_id": roleDefinitionID,
"principal_id": principalID,
"principal_display_name": principalIDDisplayName,
})
}

Expand All @@ -239,8 +251,9 @@ func expandLighthouseDefinitionAuthorization(input []interface{}) *[]managedserv
for _, item := range input {
v := item.(map[string]interface{})
result := managedservices.Authorization{
RoleDefinitionID: utils.String(v["role_definition_id"].(string)),
PrincipalID: utils.String(v["principal_id"].(string)),
RoleDefinitionID: utils.String(v["role_definition_id"].(string)),
PrincipalID: utils.String(v["principal_id"].(string)),
PrincipalIDDisplayName: utils.String(v["principal_display_name"].(string)),
}
results = append(results, result)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ func TestAccLighthouseDefinition_basic(t *testing.T) {
check.That(data.ResourceName).ExistsInAzure(r),
check.That(data.ResourceName).Key("scope").Exists(),
resource.TestMatchResourceAttr(data.ResourceName, "lighthouse_definition_id", validate.UUIDRegExp),
check.That(data.ResourceName).Key("authorization.0.principal_display_name").HasValue("Tier 1 Support"),
),
},
})
Expand Down Expand Up @@ -160,8 +161,9 @@ resource "azurerm_lighthouse_definition" "test" {
managing_tenant_id = "%s"

authorization {
principal_id = "%s"
role_definition_id = data.azurerm_role_definition.contributor.role_definition_id
principal_id = "%s"
role_definition_id = data.azurerm_role_definition.contributor.role_definition_id
principal_display_name = "Tier 1 Support"
}
}
`, id, data.RandomInteger, secondTenantID, principalID)
Expand Down
9 changes: 6 additions & 3 deletions website/docs/r/lighthouse_definition.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@ resource "azurerm_lighthouse_definition" "example" {
managing_tenant_id = "00000000-0000-0000-0000-000000000000"

authorization {
principal_id = "00000000-0000-0000-0000-000000000000"
role_definition_id = data.azurerm_role_definition.contributor.role_definition_id
principal_id = "00000000-0000-0000-0000-000000000000"
role_definition_id = data.azurerm_role_definition.contributor.role_definition_id
principal_display_name = "Tier 1 Support"
}
}
```
Expand All @@ -44,12 +45,14 @@ The following arguments are supported:

* `authorization` - (Required) An authorization block as defined below.

---
---

An `authorization` block supports the following:

* `principal_id` - (Required) Principal ID of the security group/service principal/user that would be assigned permissions to the projected subscription.

* `principal_display_name` - (Optional) The display name of the security group/service principal/user that would be assigned permissions to the projected subscription.

* `role_definition_id` - (Required) The role definition identifier. This role will define the permissions that are granted to the principal. This cannot be an `Owner` role.

## Attributes Reference
Expand Down