Skip to content
This repository has been archived by the owner on Mar 20, 2023. It is now read-only.

Commit

Permalink
implement new resource resource_rollbar_team_project_association (#59)
Browse files Browse the repository at this point in the history
  • Loading branch information
davidji99 authored Jun 1, 2021
1 parent 671fc86 commit a113219
Show file tree
Hide file tree
Showing 21 changed files with 330 additions and 60 deletions.
8 changes: 3 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,19 @@ Terraform Provider Rollbar

This provider is used to configure certain resources supported by [Rollbar API](https://docs.rollbar.com/reference).

**NOTE**: This provider is unofficial and not created by the Rollbar team.
If you have questions about Rollbar functionality, please kindly refer to the [Rollbar API documentation](https://explorer.docs.rollbar.com/).

For provider bugs/questions, please open an issue on this repository.

Documentation
------------

Documentation about resources and data sources can be found [here](https://registry.terraform.io/providers/davidji99/rollbar/latest/docs).
Documentation about resources and data sources can be found
[here](https://registry.terraform.io/providers/davidji99/rollbar/latest/docs).

Requirements
------------

- [Terraform](https://www.terraform.io/downloads.html) `v0.12+`. (No support for terraform `v0.11`)
- [Go](https://golang.org/doc/install) `v1.14` (to build the provider plugin)
- [Go](https://golang.org/doc/install) `v1.16` (to build the provider plugin)

Usage
-----
Expand Down
4 changes: 2 additions & 2 deletions docs/data-sources/project.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ Use this data source to get information about a Rollbar Project.

## Example Usage

```hcl
```hcl-terraform
data "rollbar_project" "foobar" {
name = "<SOME_PROJECT_NAME>"
name = "my_project"
}
```

Expand Down
2 changes: 1 addition & 1 deletion docs/data-sources/project_access_tokens.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ it is recommended to use data source to reference them in your terraform configu

## Example Usage

```hcl
```hcl-terraform
resource "rollbar_project" "foobar" {
name = "some_project"
}
Expand Down
4 changes: 2 additions & 2 deletions docs/data-sources/team.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ Use this data source to get information about a Rollbar Team.

## Example Usage

```hcl
```hcl-terraform
data "rollbar_team" "foobar" {
id = "<SOME_TEAM_ID>"
id = "my_team"
}
```

Expand Down
4 changes: 2 additions & 2 deletions docs/data-sources/user.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ that is used to authenticate with the provider.

## Example Usage

```hcl
```hcl-terraform
data "rollbar_user" "foobar" {
email = "<SOME_USER_EMAIL>"
email = "user@email.com"
}
```

Expand Down
19 changes: 2 additions & 17 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,6 @@ description: |-
# Rollbar Provider

The Rollbar provider is used to interact with the resources provided by [Rollbar API](https://explorer.docs.rollbar.com/).
and needs to be configured with credentials before it can be used. This provider has been developed
using the [terraform sdk](https://github.com/hashicorp/terraform-plugin-sdk) and is recommended to be used with `terraform v0.12.X+`.

## Background

[Rollbar](https://rollbar.com) automates error monitoring and triaging, so developers can fix errors that matter within minutes,
and build software quickly and painlessly.

## Contributing

Development happens in the [GitHub repo](https://github.com/davidji99/terraform-provider-rollbar):

* [Releases](https://github.com/davidji99/terraform-provider-rollbar/releases)
* [Changelog](https://github.com/davidji99/terraform-provider-rollbar/blob/master/CHANGELOG.md)
* [Issues](https://github.com/davidji99/terraform-provider-rollbar/issues)

## Example Usage

Expand Down Expand Up @@ -84,11 +69,11 @@ Refreshing Terraform state in-memory prior to plan...
The following arguments are supported:

* `account_access_token` - (Required) Rollbar account access token. It can be provided, but it can also
be sourced from [other locations](#Authentication). This token **MUST** have read & write permissions enabled
be sourced from [other locations](#Authentication). This token **MUST** have read & write permissions enabled,
so the provider can completely manage supported resources.

* `project_access_token` - (Required) Rollbar project access token. It can be provided, but it can also
be sourced from [other locations](#Authentication). This token **MUST** have read & write permissions enabled
be sourced from [other locations](#Authentication). This token **MUST** have read & write permissions enabled,
so the provider can completely manage supported resources.

* `headers` - (Optional) Additional API headers.
Expand Down
2 changes: 1 addition & 1 deletion docs/resources/pagerduty_integration.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ resource cannot import existing rules due to API limitations.

## Example Usage

```hcl
```hcl-terraform
# Create a new Rollbar PagerDuty Integration
resource "rollbar_pagerduty_integration" "pd" {
service_key = "SOME_VALID_PD_KEY"
Expand Down
2 changes: 1 addition & 1 deletion docs/resources/pagerduty_notification_rule.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ will overwrite any remotely defined rules not in your configuration files. Furth

## Example Usage

```hcl
```hcl-terraform
# Create a new Rollbar PagerDuty notification rule
resource "rollbar_pagerduty_notification_rule" "foobar" {
rule {
Expand Down
2 changes: 1 addition & 1 deletion docs/resources/project.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ the project name. Otherwise, your `terraform plan` will detect if a difference b

## Example Usage

```hcl
```hcl-terraform
# Create a new Rollbar project
resource "rollbar_project" "follbar" {
name = "my_new_project"
Expand Down
2 changes: 1 addition & 1 deletion docs/resources/project_access_token.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ Please also note that a project, by default, comes with four project access toke

## Example Usage

```hcl
```hcl-terraform
# Create a new Rollbar project access token
resource "rollbar_project" "foobar" {
name = "new_project"
Expand Down
2 changes: 1 addition & 1 deletion docs/resources/team.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ the team name. Otherwise, your `terraform plan` will detect if a difference betw

## Example Usage

```hcl
```hcl-terraform
# Create a new Rollbar team
resource "rollbar_team" "follbar" {
name = "my_new_team"
Expand Down
52 changes: 52 additions & 0 deletions docs/resources/team_project_association.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
---
layout: "rollbar"
page_title: "Rollbar: rollbar_team_project_association"
sidebar_current: "docs-rollbar-resource-team-project-association"
description: |-
Provides a resource to create and manage the association between a team and project.
---

# rollbar_team_project_association

This resource is used to create and manage the association between a team and project.

## Example Usage

```hcl-terraform
resource "rollbar_team" "foobar" {
name = "my_team"
access_level = "standard"
}
resource "rollbar_project" "foobar" {
name = "my_project"
}
resource "rollbar_team_project_association" "foobar" {
team_id = rollbar_team.foobar.id
project_id = rollbar_project.foobar.id
}
```

## Argument Reference

The following arguments are supported:

* `team_id` - (Required) `<string>` ID of existing team.

* `project_id` - (Required) `<string>` ID of existing project.

## Attributes Reference

n/a

## Import

Existing team project association can be imported using a composite value of the team and project ID
separated by a colon.

For example:

```shell
$ terraform import rollbar_team_project_association.follbar 123:456
```
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/davidji99/terraform-provider-rollbar

go 1.14
go 1.16

require (
github.com/davidji99/rollrest-go v0.1.5
Expand Down
8 changes: 0 additions & 8 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,8 @@ github.com/agext/levenshtein v1.2.1/go.mod h1:JEDfjyjHDjOF/1e4FlBE/PkbqA9OfWu2ki
github.com/agext/levenshtein v1.2.2 h1:0S/Yg6LYmFJ5stwQeRp6EeOcCbj7xiqQSdNelsXvaqE=
github.com/agext/levenshtein v1.2.2/go.mod h1:JEDfjyjHDjOF/1e4FlBE/PkbqA9OfWu2ki2W0IB5558=
github.com/agl/ed25519 v0.0.0-20170116200512-5312a6153412/go.mod h1:WPjqKcmVOxf0XSf3YxCJs6N6AOSrOx3obionmG7T0y0=
github.com/alcortesm/tgz v0.0.0-20161220082320-9c5fe88206d7 h1:uSoVVbwJiQipAclBbw+8quDsfcvFjOpI5iCf4p/cqCs=
github.com/alcortesm/tgz v0.0.0-20161220082320-9c5fe88206d7/go.mod h1:6zEj6s6u/ghQa61ZWa/C2Aw3RkjiTBOix7dkqa1VLIs=
github.com/andybalholm/crlf v0.0.0-20171020200849-670099aa064f/go.mod h1:k8feO4+kXDxro6ErPXBRTJ/ro2mf0SsFG8s7doP9kJE=
github.com/anmitsu/go-shlex v0.0.0-20161002113705-648efa622239 h1:kFOfPq6dUM1hTo4JG6LR5AXSUEsOjtdm0kw0FtQtMJA=
github.com/anmitsu/go-shlex v0.0.0-20161002113705-648efa622239/go.mod h1:2FmKhYUyUczH0OGQWaF5ceTx0UBShxjsH6f8oGKYe2c=
github.com/apparentlymart/go-cidr v1.0.1 h1:NmIwLZ/KdsjIUlhf+/Np40atNXm/+lZ5txfTJ/SpF+U=
github.com/apparentlymart/go-cidr v1.0.1/go.mod h1:EBcsNrHc3zQeuaeCeCtQruQm+n9/YjEn/vI25Lg7Gwc=
Expand All @@ -60,7 +58,6 @@ github.com/apparentlymart/go-textseg/v12 v12.0.0/go.mod h1:S/4uRK2UtaQttw1GenVJE
github.com/apparentlymart/go-textseg/v13 v13.0.0 h1:Y+KvPE1NYz0xl601PVImeQfFyEy6iT90AvPUL1NNfNw=
github.com/apparentlymart/go-textseg/v13 v13.0.0/go.mod h1:ZK2fH7c4NqDTLtiYLvIkEghdlcqw7yxLeM89kiTRPUo=
github.com/armon/go-radix v0.0.0-20180808171621-7fddfc383310/go.mod h1:ufUuZ+zHj4x4TnLV4JWEpy2hxWSpsRywHrMgIH9cCH8=
github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5 h1:0CwZNZbxp69SHPdPJAN/hZIm0C4OItdklCFmMRWYpio=
github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5/go.mod h1:wHh0iHkYZB8zMSxRWpUBQtwG5a7fFgvEO+odwuTv2gs=
github.com/aws/aws-sdk-go v1.15.78/go.mod h1:E3/ieXAlvM0XWO57iftYVDLLvQ824smPP3ATZkfNZeM=
github.com/aws/aws-sdk-go v1.25.3 h1:uM16hIw9BotjZKMZlX05SN2EFtaWfi/NonPKIARiBLQ=
Expand Down Expand Up @@ -93,16 +90,13 @@ github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1m
github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
github.com/fatih/color v1.7.0 h1:DkWD4oS2D8LGGgTQ6IvwJJXSL5Vp2ffcQg58nFV38Ys=
github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
github.com/flynn/go-shlex v0.0.0-20150515145356-3f9db97f8568 h1:BHsljHzVlRcyQhjrss6TZTdY2VfCqZPbv5k3iBFa2ZQ=
github.com/flynn/go-shlex v0.0.0-20150515145356-3f9db97f8568/go.mod h1:xEzjJPgXI435gkrCt3MPfRiAkVrwSbHsst4LCFVfpJc=
github.com/gliderlabs/ssh v0.2.2 h1:6zsha5zo/TWhRhwqCD3+EarCAgZ2yN28ipRnGPnwkI0=
github.com/gliderlabs/ssh v0.2.2/go.mod h1:U7qILu1NlMHj9FlMhZLlkCdDnU1DBEAqr0aevW3Awn0=
github.com/go-git/gcfg v1.5.0 h1:Q5ViNfGF8zFgyJWPqYwA7qGFoMTEiBmdlkcfRmpIMa4=
github.com/go-git/gcfg v1.5.0/go.mod h1:5m20vg6GwYabIxaOonVkTdrILxQMpEShl1xiMF4ua+E=
github.com/go-git/go-billy/v5 v5.0.0/go.mod h1:pmpqyWchKfYfrkb/UVH4otLvyi/5gJlGI4Hb3ZqZ3W0=
github.com/go-git/go-billy/v5 v5.1.0 h1:4pl5BV4o7ZG/lterP4S6WzJ6xr49Ba5ET9ygheTYahk=
github.com/go-git/go-billy/v5 v5.1.0/go.mod h1:pmpqyWchKfYfrkb/UVH4otLvyi/5gJlGI4Hb3ZqZ3W0=
github.com/go-git/go-git-fixtures/v4 v4.0.2-0.20200613231340-f56387b50c12 h1:PbKy9zOy4aAKrJ5pibIRpVO2BXnK1Tlcg+caKI7Ox5M=
github.com/go-git/go-git-fixtures/v4 v4.0.2-0.20200613231340-f56387b50c12/go.mod h1:m+ICp2rF3jDhFgEZ/8yziagdT1C+ZpZcrJjappBCDSw=
github.com/go-git/go-git/v5 v5.3.0 h1:8WKMtJR2j8RntEXR/uvTKagfEt4GYlwQ7mntE4+0GWc=
github.com/go-git/go-git/v5 v5.3.0/go.mod h1:xdX4bWJ48aOrdhnl2XqHYstHbbp6+LFS4r4X+lNVprw=
Expand Down Expand Up @@ -279,7 +273,6 @@ github.com/oklog/run v1.0.0 h1:Ru7dDtJNOyC66gQ5dQmaCa0qIsAUFY3sFpK1Xk8igrw=
github.com/oklog/run v1.0.0/go.mod h1:dlhp/R75TPv97u0XWUtDeV/lRKWPKSdTuV0TZvrmrQA=
github.com/pierrec/lz4 v2.0.5+incompatible/go.mod h1:pdkljMzZIN41W+lC3N2tnIh5sFi+IEE17M5jbnwPHcY=
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
Expand Down Expand Up @@ -586,7 +579,6 @@ gopkg.in/warnings.v0 v0.1.2 h1:wFXVbFY8DY5/xOe1ECiWdKCzZlxgshcYVNkBHstARME=
gopkg.in/warnings.v0 v0.1.2/go.mod h1:jksf8JmL6Qr/oQM2OXTHunEvvTAsrWBLb6OOjuVWRNI=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.3.0 h1:clyUAQHOM3G0M3f5vQj7LuJrETvjVot3Z5el9nffUtU=
gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
Expand Down
40 changes: 38 additions & 2 deletions rollbar/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,38 @@ package rollbar

import (
"fmt"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"log"
"math/rand"
"strconv"
"strings"
"time"
)

// getTeamID extracts the team ID attribute generically from a Rollbar resource.
func getTeamID(d *schema.ResourceData) int {
var teamID int
if v, ok := d.GetOk("team_id"); ok {
vs := v.(int)
log.Printf("[DEBUG] team_id: %d", vs)
teamID = vs
}

return teamID
}

// getProjectID extracts the project ID attribute generically from a Rollbar resource.
func getProjectID(d *schema.ResourceData) int {
var projectID int
if v, ok := d.GetOk("project_id"); ok {
vs := v.(int)
log.Printf("[DEBUG] Project id: %d", vs)
projectID = vs
}

return projectID
}

// StringToInt converts a string parameter to an integer.
func StringToInt(s string) int {
intValue, _ := strconv.Atoi(s)
Expand All @@ -25,8 +51,8 @@ func GenerateRandomResourceID() string {
return strconv.Itoa(rand.Int())
}

// ParseCompositeID takes a composite id separated by a colon and returns two string values.
func ParseCompositeID(id string) (p1 string, p2 string, err error) {
// ParseCompositeImportID takes a composite id separated by a colon and returns two string values.
func ParseCompositeImportID(id string) (p1 string, p2 string, err error) {
parts := strings.Split(id, ":")
if len(parts) == 2 {
p1 = parts[0]
Expand All @@ -37,6 +63,16 @@ func ParseCompositeID(id string) (p1 string, p2 string, err error) {
return
}

// ParseCompositeID splits a given string based on a specified number of
func ParseCompositeID(id string, numOfSplits int) ([]string, error) {
parts := strings.SplitN(id, ":", numOfSplits)

if len(parts) != numOfSplits {
return nil, fmt.Errorf("error: composite ID requires %d parts separated by a colon (eg x:y)", numOfSplits)
}
return parts, nil
}

// Contains takes a string slice and checks if another string value is in it.
func Contains(s []string, e string) bool {
for _, a := range s {
Expand Down
4 changes: 2 additions & 2 deletions rollbar/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ func TestInt64ToString_Basic(t *testing.T) {
}

func TestParseCompositeID_Valid(t *testing.T) {
s1, s2, parseErr := ParseCompositeID("hello:moto")
s1, s2, parseErr := ParseCompositeImportID("hello:moto")

assert.Nil(t, parseErr)
assert.Equal(t, "hello", s1)
assert.Equal(t, "moto", s2)
}

func TestParseCompositeID_Invalid(t *testing.T) {
_, _, parseErr := ParseCompositeID("hello:moto:again")
_, _, parseErr := ParseCompositeImportID("hello:moto:again")
assert.NotNil(t, parseErr)
}
45 changes: 45 additions & 0 deletions rollbar/import_rollbar_team_project_association_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package rollbar

import (
"fmt"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
"testing"
)

func TestAccRollbarTeamProjectAssociation_importBasic(t *testing.T) {
teamName := fmt.Sprintf("team-%s", acctest.RandString(10))
projectName := fmt.Sprintf("project-%s", acctest.RandString(10))

resource.Test(t, resource.TestCase{
PreCheck: func() {
testAccPreCheck(t)
},
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: testAccCheckRollbarTeamProjectAssociation_basic(teamName, projectName),
},
{
ResourceName: "rollbar_team_project_association.foobar",
ImportState: true,
ImportStateVerify: true,
ImportStateIdFunc: testAccRollbarTeamProjectAssociationImportStateIdFunc(
"rollbar_team_project_association.foobar"),
},
},
})
}

func testAccRollbarTeamProjectAssociationImportStateIdFunc(resourceName string) resource.ImportStateIdFunc {
return func(s *terraform.State) (string, error) {
rs, ok := s.RootModule().Resources[resourceName]
if !ok {
return "", fmt.Errorf("not found: %s", resourceName)
}

return fmt.Sprintf("%s:%s", rs.Primary.Attributes["team_id"],
rs.Primary.Attributes["project_id"]), nil
}
}
Loading

0 comments on commit a113219

Please sign in to comment.