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

Feat - add optional parameter for Opsgenie user tagging #172

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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
25 changes: 25 additions & 0 deletions opsgenie/resource_opsgenie_user.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,13 @@ func resourceOpsGenieUser() *schema.Resource {
Optional: true,
Default: "America/New_York",
},
"tags": {
Type: schema.TypeSet,
Optional: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
},
}
}
Expand All @@ -72,6 +79,7 @@ func resourceOpsGenieUserCreate(d *schema.ResourceData, meta interface{}) error
},
Locale: locale,
TimeZone: timeZone,
Tags: flattenOpsgenieUserTags(d),
}

log.Printf("[INFO] Creating OpsGenie user '%s'", username)
Expand Down Expand Up @@ -106,6 +114,7 @@ func resourceOpsGenieUserRead(d *schema.ResourceData, meta interface{}) error {
d.Set("role", usr.Role.RoleName)
d.Set("locale", usr.Locale)
d.Set("timezone", usr.TimeZone)
d.Set("tags", usr.Tags)

return nil
}
Expand All @@ -131,6 +140,7 @@ func resourceOpsGenieUserUpdate(d *schema.ResourceData, meta interface{}) error
},
Locale: locale,
TimeZone: timeZone,
Tags: flattenOpsgenieUserTags(d),
}

_, err = client.Update(context.Background(), updateRequest)
Expand Down Expand Up @@ -191,3 +201,18 @@ func validateOpsGenieUserRole(v interface{}, k string) (ws []string, errors []er
}
return
}

func flattenOpsgenieUserTags(d *schema.ResourceData) []string {
input := d.Get("tags").(*schema.Set)
tags := make([]string, len(input.List()))

if input == nil {
return tags
}

for k, v := range input.List() {
tags[k] = v.(string)
}

return tags
}
1 change: 1 addition & 0 deletions opsgenie/resource_opsgenie_user_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ resource "opsgenie_user" "test" {
role = "User"
locale = "en_GB"
timezone = "Europe/Rome"
tags = ["SME"]
}
`, rString)
}
Expand Down
3 changes: 3 additions & 0 deletions website/docs/r/user.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ resource "opsgenie_user" "test" {
role = "User"
locale = "en_US"
timezone = "America/New_York"
tags = ["user","sme"]
}
```

Expand All @@ -36,6 +37,8 @@ The following arguments are supported:

* `timezone` - (Optional) Timezone information of the user. Please look at [Supported Timezone Ids](https://docs.opsgenie.com/docs/supported-timezone-ids) for available timezones.

* `tags` - (Optional) List of tags to add to the user tags value as a list of strings

## Attributes Reference

The following attributes are exported:
Expand Down