Skip to content

Commit

Permalink
provider/opsgenie: Descriptions for Teams (hashicorp#11391)
Browse files Browse the repository at this point in the history
* updating the opsgenie dependency

* Adding description to an OpsGenie team

* Description for Teams

* Added tests for an empty description
  • Loading branch information
tombuildsstuff authored and arcadiatea committed Feb 7, 2017
1 parent 12f042a commit f932bb6
Show file tree
Hide file tree
Showing 12 changed files with 344 additions and 150 deletions.
24 changes: 24 additions & 0 deletions builtin/providers/opsgenie/import_opsgenie_team_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,30 @@ func TestAccOpsGenieTeam_importBasic(t *testing.T) {
})
}

func TestAccOpsGenieTeam_importWithEmptyDescription(t *testing.T) {
resourceName := "opsgenie_team.test"

ri := acctest.RandInt()
config := fmt.Sprintf(testAccOpsGenieTeam_withEmptyDescription, ri)

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testCheckOpsGenieTeamDestroy,
Steps: []resource.TestStep{
{
Config: config,
},

{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
},
},
})
}

func TestAccOpsGenieTeam_importWithUser(t *testing.T) {
resourceName := "opsgenie_team.test"

Expand Down
22 changes: 16 additions & 6 deletions builtin/providers/opsgenie/resource_opsgenie_team.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ import (
"fmt"
"strings"

"regexp"

"github.com/hashicorp/terraform/helper/schema"
"github.com/opsgenie/opsgenie-go-sdk/team"
"regexp"
)

func resourceOpsGenieTeam() *schema.Resource {
Expand All @@ -26,6 +27,10 @@ func resourceOpsGenieTeam() *schema.Resource {
Required: true,
ValidateFunc: validateOpsGenieTeamName,
},
"description": {
Type: schema.TypeString,
Optional: true,
},
"member": {
Type: schema.TypeList,
Optional: true,
Expand Down Expand Up @@ -53,10 +58,12 @@ func resourceOpsGenieTeamCreate(d *schema.ResourceData, meta interface{}) error
client := meta.(*OpsGenieClient).teams

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

createRequest := team.CreateTeamRequest{
Name: name,
Members: expandOpsGenieTeamMembers(d),
Name: name,
Description: description,
Members: expandOpsGenieTeamMembers(d),
}

log.Printf("[INFO] Creating OpsGenie team '%s'", name)
Expand Down Expand Up @@ -118,6 +125,7 @@ func resourceOpsGenieTeamRead(d *schema.ResourceData, meta interface{}) error {
}

d.Set("name", getResponse.Name)
d.Set("description", getResponse.Description)
d.Set("member", flattenOpsGenieTeamMembers(getResponse.Members))

return nil
Expand All @@ -126,11 +134,13 @@ func resourceOpsGenieTeamRead(d *schema.ResourceData, meta interface{}) error {
func resourceOpsGenieTeamUpdate(d *schema.ResourceData, meta interface{}) error {
client := meta.(*OpsGenieClient).teams
name := d.Get("name").(string)
description := d.Get("description").(string)

updateRequest := team.UpdateTeamRequest{
Id: d.Id(),
Name: name,
Members: expandOpsGenieTeamMembers(d),
Id: d.Id(),
Name: name,
Description: description,
Members: expandOpsGenieTeamMembers(d),
}

log.Printf("[INFO] Updating OpsGenie team '%s'", name)
Expand Down
32 changes: 30 additions & 2 deletions builtin/providers/opsgenie/resource_opsgenie_team_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,25 @@ func TestAccOpsGenieTeam_basic(t *testing.T) {
})
}

func TestAccOpsGenieTeam_withEmptyDescription(t *testing.T) {
ri := acctest.RandInt()
config := fmt.Sprintf(testAccOpsGenieTeam_withEmptyDescription, ri)

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testCheckOpsGenieTeamDestroy,
Steps: []resource.TestStep{
{
Config: config,
Check: resource.ComposeTestCheckFunc(
testCheckOpsGenieTeamExists("opsgenie_team.test"),
),
},
},
})
}

func TestAccOpsGenieTeam_withUser(t *testing.T) {
ri := acctest.RandInt()
config := fmt.Sprintf(testAccOpsGenieTeam_withUser, ri, ri)
Expand Down Expand Up @@ -215,6 +234,13 @@ resource "opsgenie_team" "test" {
}
`

var testAccOpsGenieTeam_withEmptyDescription = `
resource "opsgenie_team" "test" {
name = "acctest%d"
description = ""
}
`

var testAccOpsGenieTeam_withUser = `
resource "opsgenie_user" "test" {
username = "acctest-%d@example.tld"
Expand All @@ -238,7 +264,8 @@ resource "opsgenie_user" "test" {
}
resource "opsgenie_team" "test" {
name = "acctest%d"
name = "acctest%d"
description = "Some exmaple description"
member {
username = "${opsgenie_user.test.username}"
role = "user"
Expand All @@ -259,7 +286,8 @@ resource "opsgenie_user" "second" {
}
resource "opsgenie_team" "test" {
name = "acctest%d"
name = "acctest%d"
description = "Some exmaple description"
member {
username = "${opsgenie_user.first.username}"
}
Expand Down
10 changes: 0 additions & 10 deletions vendor/github.com/opsgenie/opsgenie-go-sdk/CONTRIBUTING.md

This file was deleted.

97 changes: 0 additions & 97 deletions vendor/github.com/opsgenie/opsgenie-go-sdk/README.md

This file was deleted.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit f932bb6

Please sign in to comment.