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

azuread_group - support for the description property #216

Merged
merged 5 commits into from
Mar 11, 2020
Merged
Show file tree
Hide file tree
Changes from 3 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
10 changes: 10 additions & 0 deletions azuread/data_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ func dataGroup() *schema.Resource {
ConflictsWith: []string{"name"},
},

"description": {
Type: schema.TypeString,
Optional: true,
Computed: true,
},

"name": {
Type: schema.TypeString,
Optional: true,
Expand Down Expand Up @@ -86,6 +92,10 @@ func dataSourceActiveDirectoryGroupRead(d *schema.ResourceData, meta interface{}
d.Set("object_id", group.ObjectID)
d.Set("name", group.DisplayName)

if v, ok := group.AdditionalProperties["Properties"]; ok {
d.Set("description", v.(string))
}

members, err := graph.GroupAllMembers(client, ctx, d.Id())
if err != nil {
return err
Expand Down
25 changes: 21 additions & 4 deletions azuread/resource_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ func resourceGroup() *schema.Resource {
Computed: true,
},

"description": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
},

"members": {
Type: schema.TypeSet,
Optional: true,
Expand Down Expand Up @@ -73,11 +79,18 @@ func resourceGroupCreate(d *schema.ResourceData, meta interface{}) error {

name := d.Get("name").(string)

additionalProperties := make(map[string]interface{})

if v, ok := d.GetOk("description"); ok {
additionalProperties["Description"] = v.(string)
}

properties := graphrbac.GroupCreateParameters{
DisplayName: &name,
MailEnabled: p.Bool(false), // we're defaulting to false, as the API currently only supports the creation of non-mail enabled security groups.
MailNickname: p.String(uuid.New().String()), // this matches the portal behaviour
SecurityEnabled: p.Bool(true), // we're defaulting to true, as the API currently only supports the creation of non-mail enabled security groups.
DisplayName: &name,
MailEnabled: p.Bool(false), // we're defaulting to false, as the API currently only supports the creation of non-mail enabled security groups.
MailNickname: p.String(uuid.New().String()), // this matches the portal behaviour
SecurityEnabled: p.Bool(true), // we're defaulting to true, as the API currently only supports the creation of non-mail enabled security groups.
AdditionalProperties: additionalProperties,
}

group, err := client.Create(ctx, properties)
Expand All @@ -87,6 +100,7 @@ func resourceGroupCreate(d *schema.ResourceData, meta interface{}) error {
if group.ObjectID == nil {
return fmt.Errorf("nil Group ID for %q: %+v", name, err)
}

d.SetId(*group.ObjectID)

// Add members if specified
Expand Down Expand Up @@ -132,6 +146,9 @@ func resourceGroupRead(d *schema.ResourceData, meta interface{}) error {
return fmt.Errorf("Error retrieving Azure AD Group with ID %q: %+v", d.Id(), err)
}

if v, ok := resp.AdditionalProperties["Properties"]; ok {
d.Set("description", v.(string))
}
d.Set("name", resp.DisplayName)
d.Set("object_id", resp.ObjectID)

Expand Down
1 change: 1 addition & 0 deletions website/docs/d/group.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ The following arguments are supported:
The following attributes are exported:

* `id` - The Object ID of the Azure AD Group.
* `description` - The description of the AD Group.
* `name` - The name of the Azure AD Group.
* `owners` - The Object IDs of the Azure AD Group owners.
* `members` - The Object IDs of the Azure AD Group members.
Expand Down
3 changes: 3 additions & 0 deletions website/docs/r/group.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ resource "azuread_group" "example" {
The following arguments are supported:

* `name` - (Required) The display name for the Group. Changing this forces a new resource to be created.
* `description` - (Optional) The description for the Group. Changing this forces a new resource to be created.
* `members` (Optional) A set of members who should be present in this Group. Supported Object types are Users, Groups or Service Principals.
* `owners` (Optional) A set of owners who own this Group. Supported Object types are Users or Service Principals.

Expand All @@ -60,6 +61,8 @@ The following attributes are exported:

* `name` - The Display Name of the Group.

* `description` - The Description of the Group.

* `members` - The Members of the Group.

* `owners` - The Members of the Group.
Expand Down