Skip to content

Commit

Permalink
Merge pull request #97 from circonus-labs/CIRC-8532
Browse files Browse the repository at this point in the history
CIRC-8532: Remove unsupported external contact methods from the contact group resource
  • Loading branch information
dhaifley committed Jun 8, 2022
2 parents 2e3886f + a1002ba commit 19d4446
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 113 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
## 0.12.10 (June 8, 2022)

CHANGES:

* upd: Removes support from the circonus_contact_group resource for external
contact methods that are no longer supported: irc and xmpp. Updates the
documentation to remove these methods as well.

## 0.12.9 (June 6, 2022)

CHANGES:
Expand Down
84 changes: 0 additions & 84 deletions circonus/resource_circonus_contact.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ const (
contactSlackAttr = "slack"
contactTagsAttr = "tags"
contactVictorOpsAttr = "victorops"
contactXMPPAttr = "xmpp"

// circonus_contact.alert_option attributes.
contactEscalateAfterAttr = "escalate_after"
Expand Down Expand Up @@ -75,10 +74,6 @@ const (
contactVictorOpsTeamAttr = "team"
contactVictorOpsWarningAttr = "warning"

// circonus_contact.victorops attributes
// contactUserCIDAttr.
contactXMPPAddressAttr = "address"

// circonus_contact read-only attributes.
contactLastModifiedAttr = "last_modified"
contactLastModifiedByAttr = "last_modified_by"
Expand All @@ -96,7 +91,6 @@ const (
circonusMethodSlack = "slack"
circonusMethodSMS = "sms"
circonusMethodVictorOps = "victorops"
circonusMethodXMPP = "xmpp"
)

type contactHTTPInfo struct {
Expand Down Expand Up @@ -150,7 +144,6 @@ var contactGroupDescriptions = attrDescrs{
contactSlackAttr: "",
contactTagsAttr: "",
contactVictorOpsAttr: "",
contactXMPPAttr: "",
}

var contactAlertDescriptions = attrDescrs{
Expand Down Expand Up @@ -200,11 +193,6 @@ var contactVictorOpsDescriptions = attrDescrs{
contactVictorOpsWarningAttr: "",
}

var contactXMPPDescriptions = attrDescrs{
contactUserCIDAttr: "",
contactXMPPAddressAttr: "",
}

func resourceContactGroup() *schema.Resource {
return &schema.Resource{
Create: contactGroupCreate,
Expand Down Expand Up @@ -481,26 +469,6 @@ func resourceContactGroup() *schema.Resource {
}),
},
},
contactXMPPAttr: {
Type: schema.TypeList,
MaxItems: 1,
Optional: true,
Elem: &schema.Resource{
Schema: convertToHelperSchema(contactXMPPDescriptions, map[schemaAttr]*schema.Schema{
contactXMPPAddressAttr: {
Type: schema.TypeString,
Optional: true,
ConflictsWith: []string{contactXMPPAttr + "." + contactUserCIDAttr},
},
contactUserCIDAttr: {
Type: schema.TypeString,
Optional: true,
ValidateFunc: validateUserCID(contactUserCIDAttr),
ConflictsWith: []string{contactXMPPAttr + "." + contactXMPPAddressAttr},
},
}),
},
},

// OUT parameters
contactLastModifiedAttr: {
Expand Down Expand Up @@ -594,11 +562,6 @@ func contactGroupRead(d *schema.ResourceData, meta interface{}) error {
return err
}

xmppState, err := contactGroupXMPPToState(cg)
if err != nil {
return err
}

_ = d.Set(contactAggregationWindowAttr, fmt.Sprintf("%ds", cg.AggregationWindow))
_ = d.Set(contactAlwaysSendClearAttr, cg.AlwaysSendClear)
_ = d.Set(contactGroupTypeAttr, cg.GroupType)
Expand Down Expand Up @@ -643,10 +606,6 @@ func contactGroupRead(d *schema.ResourceData, meta interface{}) error {
return fmt.Errorf("Unable to store contact %q attribute: %w", contactVictorOpsAttr, err)
}

if err := d.Set(contactXMPPAttr, xmppState); err != nil {
return fmt.Errorf("Unable to store contact %q attribute: %w", contactXMPPAttr, err)
}

// Out parameters
_ = d.Set(contactLastModifiedAttr, cg.LastModified)
_ = d.Set(contactLastModifiedByAttr, cg.LastModifiedBy)
Expand Down Expand Up @@ -1066,27 +1025,6 @@ func getContactGroupInput(d *schema.ResourceData) (*api.ContactGroup, error) {
}
}

if v, ok := d.GetOk(contactXMPPAttr); ok {
xmppListRaw := v.(*schema.Set).List()
for _, xmppMapRaw := range xmppListRaw {
xmppMap := xmppMapRaw.(map[string]interface{})

if v, ok := xmppMap[contactXMPPAddressAttr]; ok && v.(string) != "" {
cg.Contacts.External = append(cg.Contacts.External, api.ContactGroupContactsExternal{
Info: v.(string),
Method: circonusMethodXMPP,
})
}

if v, ok := xmppMap[contactUserCIDAttr]; ok && v.(string) != "" {
cg.Contacts.Users = append(cg.Contacts.Users, api.ContactGroupContactsUser{
Method: circonusMethodXMPP,
UserCID: v.(string),
})
}
}
}

if v, ok := d.GetOk(contactLongMessageAttr); ok {
msg := v.(string)
cg.AlertFormats.LongMessage = &msg
Expand Down Expand Up @@ -1234,28 +1172,6 @@ func contactGroupVictorOpsToState(cg *api.ContactGroup) ([]interface{}, error) {
return victorOpsContacts, nil
}

func contactGroupXMPPToState(cg *api.ContactGroup) ([]interface{}, error) { //nolint:unparam
xmppContacts := make([]interface{}, 0, len(cg.Contacts.Users)+len(cg.Contacts.External))

for _, ext := range cg.Contacts.External {
if ext.Method == circonusMethodXMPP {
xmppContacts = append(xmppContacts, map[string]interface{}{
contactXMPPAddressAttr: ext.Info,
})
}
}

for _, user := range cg.Contacts.Users {
if user.Method == circonusMethodXMPP {
xmppContacts = append(xmppContacts, map[string]interface{}{
contactUserCIDAttr: user.UserCID,
})
}
}

return xmppContacts, nil
}

// contactGroupAlertOptionsChecksum creates a stable hash of the normalized values.
func contactGroupAlertOptionsChecksum(v interface{}) int {
m := v.(map[string]interface{})
Expand Down
10 changes: 0 additions & 10 deletions circonus/resource_circonus_contact_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,6 @@ func TestAccCirconusContactGroup_basic(t *testing.T) {
// resource.TestCheckResourceAttr("circonus_contact_group.staging-sev3", "sms.#", "1"),
// resource.TestCheckResourceAttr("circonus_contact_group.staging-sev3", "sms.1119127802.user", "/user/5469"),

// xmpp.# will be 0 for user faux user accounts that don't have an
// XMPP address setup.
resource.TestCheckResourceAttr("circonus_contact_group.staging-sev3", "xmpp.#", "0"),
// resource.TestCheckResourceAttr("circonus_contact_group.staging-sev3", "xmpp.1119127802.user", "/user/5469"),
resource.TestCheckResourceAttr("circonus_contact_group.staging-sev3", "victorops.#", "0"),
// resource.TestCheckResourceAttr("circonus_contact_group.staging-sev3", "victorops.#", "1"),
// resource.TestCheckResourceAttr("circonus_contact_group.staging-sev3", "victorops.2029434450.api_key", "123"),
Expand Down Expand Up @@ -198,12 +194,6 @@ resource "circonus_contact_group" "staging-sev3" {
warning = 3
}
*/
// Faux user accounts that don't have an XMPP address setup will not return a
// valid response in the future.
//
// xmpp {
// user = "/user/5469"
// }
aggregation_window = "1m"
Expand Down
20 changes: 1 addition & 19 deletions website/docs/r/contact_group.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,6 @@ resource "circonus_contact_group" "myteam-alerts" {
warning = 3
}
xmpp {
user = "/user/9876"
}
aggregation_window = "5m"
alert_option {
Expand Down Expand Up @@ -175,7 +171,7 @@ mechanisms).

## Supported Contact Group `http` Attributes

* `address` - (Required) URL to send a webhook request to.
* `url` - (Required) URL to send a webhook request to.

* `format` - (Optional) The payload of the request is a JSON-encoded payload
when the `format` is set to `json` (the default). The alternate payload
Expand All @@ -184,11 +180,6 @@ mechanisms).
* `method` - (Optional) The HTTP verb to use when making a request. Either
`GET` or `POST` may be specified. The default verb is `POST`.

## Supported Contact Group `irc` Attributes

* `user` - (Required) When a user has configured IRC on their user account, they
will receive an IRC notification.

## Supported Contact Group `pager_duty` Attributes

* `contact_group_fallback` - (Optional) If there is a problem contacting
Expand Down Expand Up @@ -249,15 +240,6 @@ mechanisms).
* `team` - (Required)
* `warning` - (Required)

## Supported Contact Group `xmpp` Attributes

Either an `address` or `user` attribute is required.

* `address` - (Optional) XMPP address to send a short notification to.

* `user` - (Optional) An XMPP notification will be sent to the XMPP address of
record for the corresponding user ID (e.g. `/user/1234`).

## Import Example

`circonus_contact_group` supports importing resources. Supposing the following
Expand Down

0 comments on commit 19d4446

Please sign in to comment.