Skip to content

Commit

Permalink
Merge pull request #296 from heroku/issue/296/davidji99-upgrade-terra…
Browse files Browse the repository at this point in the history
…formplugin

Upgrade terraform-plugin-sdk to v2+
  • Loading branch information
davidji99 authored Mar 1, 2021
2 parents ab42563 + ba4cc44 commit 9150302
Show file tree
Hide file tree
Showing 2,407 changed files with 802 additions and 679,203 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/acceptance-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,5 @@ jobs:
HEROKU_NON_ADMIN_TEST_USER: [email protected]
HEROKU_SLUG_ID: 8527dbf3-c0a0-4255-beab-aca0aad1dfc9
HEROKU_USER_ID: 007fa6e2-00a1-429e-92a0-7bbe14b063fc
GOFLAGS: "-mod=vendor"
# GOFLAGS: "-mod=vendor"
# TF_LOG: DEBUG
2 changes: 1 addition & 1 deletion GNUmakefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ test: fmtcheck
xargs -t -n4 go test -v $(TESTARGS) -timeout=30s -parallel=4

testacc: fmtcheck
TF_ACC=1 go test $(TEST) -v $(TESTARGS) -timeout=240m -ldflags="-X=github.com/heroku/terraform-provider-heroku/v3/version.ProviderVersion=test"
TF_ACC=1 go test $(TEST) -v $(TESTARGS) -timeout=240m -ldflags="-X=github.com/heroku/terraform-provider-heroku/v4/version.ProviderVersion=test"

vet:
@echo "go vet ."
Expand Down
7 changes: 3 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
module github.com/heroku/terraform-provider-heroku/v3
module github.com/heroku/terraform-provider-heroku/v4

require (
github.com/bgentry/go-netrc v0.0.0-20140422174119-9fd32a8b3d3d
github.com/google/uuid v1.1.1
github.com/hashicorp/go-multierror v1.0.0
github.com/hashicorp/go-uuid v1.0.1
github.com/hashicorp/hcl v0.0.0-20180404174102-ef8a98b0bbce // indirect
github.com/hashicorp/terraform-plugin-sdk v1.15.0
github.com/hashicorp/terraform-plugin-sdk/v2 v2.4.3
github.com/heroku/heroku-go/v5 v5.2.1
github.com/mitchellh/go-homedir v1.1.0
github.com/verybluebot/tarinator-go v0.0.0-20190613183509-5ab4e1193986
)

go 1.14
go 1.15
384 changes: 333 additions & 51 deletions go.sum

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion helper/test/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"os"
"testing"

"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
)

type TestConfigKey int
Expand Down
104 changes: 104 additions & 0 deletions helper/test/helper.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
package test

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

const (
sentinelIndex = "*"
)

// The below few functions were copied from the AWS provider.

// TestCheckTypeSetElemAttr is a resource.TestCheckFunc that accepts a resource
// name, an attribute path, which should use the sentinel value '*' for indexing
// into a TypeSet. The function verifies that an element matches the provided
// value.
//
// Use this function over SDK provided TestCheckFunctions when validating a
// TypeSet where its elements are a simple value
func TestCheckTypeSetElemAttr(name, attr, value string) resource.TestCheckFunc {
return func(s *terraform.State) error {
is, err := instanceState(s, name)
if err != nil {
return err
}

err = testCheckTypeSetElem(is, attr, value)
if err != nil {
return fmt.Errorf("%q error: %s", name, err)
}

return nil
}
}

// TestCheckTypeSetElemAttrPair is a TestCheckFunc that verifies a pair of name/key
// combinations are equal where the first uses the sentinel value to index into a
// TypeSet.
//
// E.g., tfawsresource.TestCheckTypeSetElemAttrPair("aws_autoscaling_group.bar", "availability_zones.*", "data.aws_availability_zones.available", "names.0")
func TestCheckTypeSetElemAttrPair(nameFirst, keyFirst, nameSecond, keySecond string) resource.TestCheckFunc {
return func(s *terraform.State) error {
isFirst, err := instanceState(s, nameFirst)
if err != nil {
return err
}

isSecond, err := instanceState(s, nameSecond)
if err != nil {
return err
}

vSecond, okSecond := isSecond.Attributes[keySecond]
if !okSecond {
return fmt.Errorf("%s: Attribute %q not set, cannot be checked against TypeSet", nameSecond, keySecond)
}

return testCheckTypeSetElem(isFirst, keyFirst, vSecond)
}
}

// instanceState returns the primary instance state for the given
// resource name in the root module.
func instanceState(s *terraform.State, name string) (*terraform.InstanceState, error) {
ms := s.RootModule()
rs, ok := ms.Resources[name]
if !ok {
return nil, fmt.Errorf("Not found: %s in %s", name, ms.Path)
}

is := rs.Primary
if is == nil {
return nil, fmt.Errorf("No primary instance: %s in %s", name, ms.Path)
}

return is, nil
}

func testCheckTypeSetElem(is *terraform.InstanceState, attr, value string) error {
attrParts := strings.Split(attr, ".")
if attrParts[len(attrParts)-1] != sentinelIndex {
return fmt.Errorf("%q does not end with the special value %q", attr, sentinelIndex)
}
for stateKey, stateValue := range is.Attributes {
if stateValue == value {
stateKeyParts := strings.Split(stateKey, ".")
if len(stateKeyParts) == len(attrParts) {
for i := range attrParts {
if attrParts[i] != stateKeyParts[i] && attrParts[i] != sentinelIndex {
break
}
if i == len(attrParts)-1 {
return nil
}
}
}
}
}

return fmt.Errorf("no TypeSet element %q, with value %q in state: %#v", attr, value, is.Attributes)
}
6 changes: 3 additions & 3 deletions heroku/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ import (
"runtime"

"github.com/bgentry/go-netrc/netrc"
"github.com/hashicorp/terraform-plugin-sdk/helper/logging"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/logging"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
heroku "github.com/heroku/heroku-go/v5"
"github.com/heroku/terraform-provider-heroku/v3/version"
"github.com/heroku/terraform-provider-heroku/v4/version"
homedir "github.com/mitchellh/go-homedir"
)

Expand Down
2 changes: 1 addition & 1 deletion heroku/data_source_heroku_addon.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package heroku

import (
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)

func dataSourceHerokuAddon() *schema.Resource {
Expand Down
4 changes: 2 additions & 2 deletions heroku/data_source_heroku_addon_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import (
"fmt"
"testing"

"github.com/hashicorp/terraform-plugin-sdk/helper/acctest"
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
)

func TestAccDatasourceHerokuAddon_Basic(t *testing.T) {
Expand Down
7 changes: 6 additions & 1 deletion heroku/data_source_heroku_app.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package heroku

import (
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)

func dataSourceHerokuApp() *schema.Resource {
Expand Down Expand Up @@ -91,6 +91,11 @@ func dataSourceHerokuApp() *schema.Resource {
},
},
},

"uuid": {
Type: schema.TypeString,
Computed: true,
},
},
}
}
Expand Down
6 changes: 3 additions & 3 deletions heroku/data_source_heroku_app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ import (
"os"
"testing"

"github.com/hashicorp/terraform-plugin-sdk/helper/acctest"
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
)

func TestAccDatasourceHerokuApp_Basic(t *testing.T) {
appName := fmt.Sprintf("tftest-%s", acctest.RandString(10))
appStack := "heroku-16"
appStack := "heroku-20"
gitUrl := fmt.Sprintf("https://git.heroku.com/%s.git", appName)
webUrl := fmt.Sprintf("https://%s.herokuapp.com/", appName)
herokuHostname := fmt.Sprintf("%s.herokuapp.com", appName)
Expand Down
2 changes: 1 addition & 1 deletion heroku/data_source_heroku_pipeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package heroku

import (
"context"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)

func dataSourceHerokuPipeline() *schema.Resource {
Expand Down
4 changes: 2 additions & 2 deletions heroku/data_source_heroku_pipeline_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ package heroku

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

Expand Down
2 changes: 1 addition & 1 deletion heroku/data_source_heroku_space.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package heroku

import (
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)

func dataSourceHerokuSpace() *schema.Resource {
Expand Down
2 changes: 1 addition & 1 deletion heroku/data_source_heroku_space_peering_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package heroku
import (
"context"

"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)

func dataSourceHerokuSpacePeeringInfo() *schema.Resource {
Expand Down
4 changes: 2 additions & 2 deletions heroku/data_source_heroku_space_peering_info_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import (
"fmt"
"testing"

"github.com/hashicorp/terraform-plugin-sdk/helper/acctest"
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
)

func TestAccDatasourceHerokuSpacePeeringInfo_Basic(t *testing.T) {
Expand Down
4 changes: 2 additions & 2 deletions heroku/data_source_heroku_space_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import (
"fmt"
"testing"

"github.com/hashicorp/terraform-plugin-sdk/helper/acctest"
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
)

func TestAccDatasourceHerokuSpace_Basic(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion heroku/data_source_heroku_team.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package heroku

import (
"context"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)

func dataSourceHerokuTeam() *schema.Resource {
Expand Down
2 changes: 1 addition & 1 deletion heroku/data_source_heroku_team_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package heroku

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

Expand Down
4 changes: 2 additions & 2 deletions heroku/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import (
"log"
"strings"

"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
heroku "github.com/heroku/heroku-go/v5"
"github.com/heroku/terraform-provider-heroku/v3/version"
"github.com/heroku/terraform-provider-heroku/v4/version"
)

// getAppName extracts the app attribute generically from a Heroku resource.
Expand Down
2 changes: 1 addition & 1 deletion heroku/import_heroku_account_feature_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package heroku

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

Expand Down
4 changes: 2 additions & 2 deletions heroku/import_heroku_addon_attachment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import (
"fmt"
"testing"

"github.com/hashicorp/terraform-plugin-sdk/helper/acctest"
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
)

func TestAccHerokuAddonAttachment_importBasic(t *testing.T) {
Expand Down
4 changes: 2 additions & 2 deletions heroku/import_heroku_addon_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import (
"fmt"
"testing"

"github.com/hashicorp/terraform-plugin-sdk/helper/acctest"
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
)

func TestAccHerokuAddon_importBasic(t *testing.T) {
Expand Down
4 changes: 2 additions & 2 deletions heroku/import_heroku_app_feature_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ package heroku

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

Expand Down
4 changes: 2 additions & 2 deletions heroku/import_heroku_app_release_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import (

"fmt"

"github.com/hashicorp/terraform-plugin-sdk/helper/acctest"
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
)

func TestAccHerokuAppRelease_importBasic(t *testing.T) {
Expand Down
6 changes: 3 additions & 3 deletions heroku/import_heroku_app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ import (
"fmt"
"testing"

"github.com/hashicorp/terraform-plugin-sdk/helper/acctest"
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
)

func TestAccHerokuApp_importBasic(t *testing.T) {
appName := fmt.Sprintf("tftest-%s", acctest.RandString(10))
appStack := "heroku-16"
appStack := "heroku-20"

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Expand Down
4 changes: 2 additions & 2 deletions heroku/import_heroku_app_webhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import (
"fmt"
"testing"

"github.com/hashicorp/terraform-plugin-sdk/helper/acctest"
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
)

func TestAccHerokuAppWebhook_importBasic(t *testing.T) {
Expand Down
Loading

0 comments on commit 9150302

Please sign in to comment.