Skip to content
This repository has been archived by the owner on Jun 30, 2018. It is now read-only.

Commit

Permalink
Adds filters to integration datasource
Browse files Browse the repository at this point in the history
  • Loading branch information
ewilde committed Oct 26, 2017
1 parent 506148a commit 01b0161
Show file tree
Hide file tree
Showing 5 changed files with 128 additions and 5 deletions.
14 changes: 14 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
language: go
go:
- 1.9.x
script:
- make
env:
global:
- |
RUNSCOPE_INTEGRATION_DESC="Slack: #general channel, send message on all test runs"
- DEBUG=1
- TF_LOG=DEBUG
- TF_ACC=1
- secure: WuBIDsitJiSSj43a+sz4R9cDY2AF2ODerVkx2eKxXIXtKRLqjBxiQD8gekfTIprbiMfsOCMPr5cjp1AmjuZCWu10DrshAbPvTP6h5Fvm10CRkpdojyOoJZuRrhhZwpaahxo2tE53iLHXtQ+5CMKOecG1Z2ts7b3jWny93AVwuD+Jmft27KqBcFPceOL9mQgdMEBOTjTV5wdhKrRtiyzrVUx50odkuKXGKGFT8GdKyvF6KxuOA2TK+2o7tFiswEUXTWZUNM6weC84Mx/74VSy0tzy6+fTaDkYR5X4BcXQNthctLeElpw/bSqGWJZcEmLOBnPwbB5Si56f/jS5COdQ0bXmuQD+eE16vI+F5ufXHibP4Uh8ltLMEkj5YD6PWNL4A5xAnOps4zLBM43wxtRl00d9BmSn30VlY8TfTQALSR5CC/zB6ciNQm+Or9Awgolucj7MDA/dgreEElDRS2j/Gl9JlJ3DuKUWwEHn9KU3g4bYnnRqUSVWVjoPg+jOkkUWC+hb8N7KF89VUV+J7LvsfMJM5b3030WPIGug2GLc1avVrWGHPTgTXit6/HueLSuHdeD/nQOqBTarzAHdNP72ACcbcuaknAUUdo9nTZQUVCbjca8PkBveIosQP07RHBtoxixkgkNSLialZx2Uhlgu2MWbp8r1GEBauJMxLu4voBY=
- secure: Om90Aveg0wYEu4SAdsjOWHrumvV7tIVCENelnGEPBQY9Fx3kFfPJEqLC1AnzRNITjwB0aRzFPAqoaAiEj1zIxxPdYC+H9XKbD48We+jBeHv8v/hgrKbeaZZqUzTqS5YYYZGV9gHosB9cGkdBhlHvfMPzw8M/l+j6OEbicPNGfuO8Q1OkNmFPI5oM4vO8seXbf6NXko3wXY/pMMtUssUKAzUfFZLUNv5T6VpHIpdT5YzkAPoGpto22joW1cTADni3xToaA90meN4DqBKYarrzxvqiLYsjl1SWV3D0Uk+zxjeu7smfROo8zkyratPPvUQu6x/MvjuwDrupaLJi9ffnW7utIJQuSJ1W5Au6aQYuZr16VJ9k9myns6lfkrvP2y1CIUgbUKV+JiScL0OOiCBI2sa7ipuzjtE6HbmPMqYb7wx4XsqSn7qLlvkg1Nn99UCU75WAxK95K62ZLqFmcqG5AMIqwU8LKpvCAv+wwiUW7Cw9p1X2hwTC+UxpUBJN8k6SonRmULh9h84LSpoCxA1g2bD1fuJvX3Oe74MmK1rHYZM0FXJM7W48wrD1fwR7IHtUh/5//3yeIRIFIg8YAYCKxr7MpGEBcG2HrILEmbzDydOUR9zG20BVFVXMqKRWyFITcJvScP8cHnrEOXFObZxCwrxIXxEltrc+x2XKxAmkzEg=
14 changes: 10 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
GOFMT_FILES?=$$(find . -name '*.go' |grep -v vendor)

default: build
default: build test testacc

test: fmtcheck
go test -v . ./plugin/providers/runscope
Expand All @@ -9,13 +9,19 @@ testacc: fmtcheck
@test "${RUNSCOPE_ACCESS_TOKEN}" || (echo '$$RUNSCOPE_ACCESS_TOKEN required' && exit 1)
@test "${RUNSCOPE_TEAM_ID}" || (echo '$$RUNSCOPE_TEAM_ID required' && exit 1)

TF_ACC=1 go test -v ./plugin/providers/runscope -run="TestAcc" -timeout 20m
go test -v ./plugin/providers/runscope -run="TestAcc" -timeout 20m

build: deps fmtcheck vet
build: fmtcheck vet testacc
@go install
@mkdir -p ~/.terraform.d/plugins/
@cp $(GOPATH)/bin/terraform-provider-runscope ~/.terraform.d/plugins/
@echo "Build succeeded"

build-gox: deps fmtcheck vet
gox -osarch="linux/amd64 windows/amd64 darwin/amd64" \
-output="pkg/{{.OS}}_{{.Arch}}/terraform-provider-runscope" .

release:
release: build-gox
@test "${VERSION}" || (echo 'VERSION name required' && exit 1)
rm -f pkg/darwin_amd64/terraform-provider-runscope_${VERSION}_darwin_amd64.zip
zip pkg/darwin_amd64/terraform-provider-runscope_${VERSION}_darwin_amd64.zip pkg/darwin_amd64/terraform-provider-runscope
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
[![Build Status](https://travis-ci.org/ewilde/terraform-provider-runscope.svg?branch=master)](https://travis-ci.org/ewilde/terraform-provider-runscope)

# Terraform Runscope Provider

- Website: https://www.terraform.io
Expand Down
55 changes: 54 additions & 1 deletion runscope/data_source_runscope_integration.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,32 @@ func dataSourceRunscopeIntegration() *schema.Resource {
Type: schema.TypeString,
Required: true,
},
"filter": &schema.Schema{
Type: schema.TypeSet,
Optional: true,
ForceNew: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Required: true,
},
"values": {
Type: schema.TypeList,
Required: true,
Elem: &schema.Schema{Type: schema.TypeString},
},
},
},
},
"type": {
Type: schema.TypeString,
Required: true,
},
"description": {
Type: schema.TypeString,
Computed: true,
},
},
}
}
Expand All @@ -30,6 +52,7 @@ func dataSourceRunscopeIntegrationRead(d *schema.ResourceData, meta interface{})
log.Printf("[INFO] Reading Runscope integration")

searchType := d.Get("type").(string)
filters, filtersOk := d.GetOk("filter")

resp, err := client.ListIntegrations(d.Get("team_uuid").(string))
if err != nil {
Expand All @@ -39,18 +62,48 @@ func dataSourceRunscopeIntegrationRead(d *schema.ResourceData, meta interface{})
found := &runscope.Integration{}
for _, integration := range resp {
if integration.IntegrationType == searchType {
if filtersOk {
if !integrationFiltersTest(integration, filters.(*schema.Set)) {
continue
}
}
found = integration
break
}
}

if found == nil {
return fmt.Errorf("Unable to locate any user with the email: %s", searchType)
return fmt.Errorf("Unable to locate any integrations with the type: %s", searchType)
}

d.SetId(found.ID)
d.Set("id", found.ID)
d.Set("type", found.IntegrationType)
d.Set("description", found.Description)

return nil
}

func integrationFiltersTest(integration *runscope.Integration, filters *schema.Set) bool {
for _, v := range filters.List() {
m := v.(map[string]interface{})

for _, e := range m["values"].([]interface{}) {
switch m["name"].(string) {
case "id":
if integration.ID == e {
return true
}
case "type":
if integration.IntegrationType == e {
return true
}
default:
if integration.Description == e {
return true
}
}
}
}
return false
}
48 changes: 48 additions & 0 deletions runscope/data_source_runscope_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ func testAccDataSourceRunscopeIntegration(dataSource string) resource.TestCheckF
return fmt.Errorf("Expected to get an integration type slack from runscope data resource")
}

if a["description"] == "" {
return fmt.Errorf("Expected to get an integration description from runscope data resource")
}

return nil
}
}
Expand All @@ -50,3 +54,47 @@ data "runscope_integration" "by_type" {
type = "slack"
}
`

func TestAccDataSourceRunscopeIntegration_Filter(t *testing.T) {

teamId := os.Getenv("RUNSCOPE_TEAM_ID")
integrationDesc := os.Getenv("RUNSCOPE_INTEGRATION_DESC")

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: fmt.Sprintf(testAccDataSourceRunscopeIntegrationFilterConfig, teamId, integrationDesc),
Check: resource.ComposeTestCheckFunc(
testAccDataSourceRunscopeIntegrationFilter("data.runscope_integration.by_type"),
),
},
},
})
}

func testAccDataSourceRunscopeIntegrationFilter(dataSource string) resource.TestCheckFunc {
return func(s *terraform.State) error {
r := s.RootModule().Resources[dataSource]
a := r.Primary.Attributes
integrationDesc := os.Getenv("RUNSCOPE_INTEGRATION_DESC")

if a["description"] != integrationDesc {
return fmt.Errorf("Expected integration description %s to be %s", a["description"], integrationDesc)
}

return nil
}
}

const testAccDataSourceRunscopeIntegrationFilterConfig = `
data "runscope_integration" "by_type" {
team_uuid = "%s"
type = "slack"
filter = {
name = "description"
values = ["%s","other test description"]
}
}
`

0 comments on commit 01b0161

Please sign in to comment.