Skip to content

Commit

Permalink
Merge pull request #12209 from terraform-providers/f/plugin-sdk2
Browse files Browse the repository at this point in the history
dependencies: upgrading to v2 of github.com/hashicorp/terraform-plugin-sdk
  • Loading branch information
tombuildsstuff authored Jun 21, 2021
2 parents cccaa7c + 4be9bc0 commit 5553d2c
Show file tree
Hide file tree
Showing 1,405 changed files with 50,753 additions and 160,349 deletions.
2 changes: 1 addition & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ linters:

linters-settings:
errcheck:
ignore: github.com/hashicorp/terraform-plugin-sdk/helper/schema:ForceNew|Set,fmt:.*,io:Close
ignore: github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema:ForceNew|Set,fmt:.*,io:Close
misspell:
ignore-words:
- hdinsight
Expand Down
4 changes: 1 addition & 3 deletions azurerm/helpers/validate/float.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,12 @@ package validate

import (
"fmt"

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

// FloatInSlice returns a SchemaValidateFunc which tests if the provided value
// is of type float64 and matches the value of an element in the valid slice
//
func FloatInSlice(valid []float64) schema.SchemaValidateFunc {
func FloatInSlice(valid []float64) func(interface{}, string) ([]string, []error) {
return func(i interface{}, k string) (warnings []string, errors []error) {
v, ok := i.(float64)
if !ok {
Expand Down
4 changes: 1 addition & 3 deletions azurerm/helpers/validate/port_or_port_range.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@ import (
"fmt"
"regexp"
"strconv"

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

func PortOrPortRangeWithin(min int, max int) schema.SchemaValidateFunc {
func PortOrPortRangeWithin(min int, max int) func(interface{}, string) ([]string, []error) {
return func(i interface{}, k string) (warnings []string, errors []error) {
v, ok := i.(string)
if !ok {
Expand Down
3 changes: 1 addition & 2 deletions azurerm/helpers/validate/time.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"time"

iso8601 "github.com/btubbs/datetime"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/rickb777/date/period"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/tf/validation"
)
Expand Down Expand Up @@ -63,7 +62,7 @@ func ISO8601DateTime(i interface{}, k string) (warnings []string, errors []error
return warnings, errors
}

func AzureTimeZoneString() schema.SchemaValidateFunc {
func AzureTimeZoneString() func(interface{}, string) ([]string, []error) {
// List collected from https://support.microsoft.com/en-gb/help/973627/microsoft-time-zone-index-values
// TODO look into programatic retrieval https://docs.microsoft.com/en-us/rest/api/maps/timezone/gettimezoneenumwindows
validTimeZones := []string{
Expand Down
4 changes: 2 additions & 2 deletions azurerm/internal/acceptance/check/that.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import (
"fmt"
"regexp"

"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/terraform"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance/helpers"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance/testclient"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance/types"
Expand Down
30 changes: 23 additions & 7 deletions azurerm/internal/acceptance/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,25 @@ package acceptance
import (
"fmt"
"math"
"math/rand"
"os"
"strconv"
"testing"

"github.com/Azure/go-autorest/autorest/azure"
"github.com/hashicorp/terraform-plugin-sdk/helper/acctest"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features"
)

const (
// charSetAlphaNum is the alphanumeric character set for use with randStringFromCharSet
charSetAlphaNum = "abcdefghijklmnopqrstuvwxyz012346789"
)

func init() {
// unit testing
if os.Getenv("TF_ACC") == "" {
return
}

EnsureProvidersAreInitialised()
}

type TestData struct {
Expand Down Expand Up @@ -55,16 +58,14 @@ type TestData struct {

// BuildTestData generates some test data for the given resource
func BuildTestData(t *testing.T, resourceType string, resourceLabel string) TestData {
EnsureProvidersAreInitialised()

env, err := Environment()
if err != nil {
t.Fatalf("Error retrieving Environment: %+v", err)
}

testData := TestData{
RandomInteger: RandTimeInt(),
RandomString: acctest.RandString(5),
RandomString: randString(5),
ResourceName: fmt.Sprintf("%s.%s", resourceType, resourceLabel),
Environment: *env,
EnvironmentName: EnvironmentName(),
Expand Down Expand Up @@ -122,5 +123,20 @@ func (td *TestData) RandomStringOfLength(len int) string {
panic("Invalid Test: RandomStringOfLength: length argument must be between 1 and 1024 characters")
}

return acctest.RandString(len)
return randString(len)
}

// randString generates a random alphanumeric string of the length specified
func randString(strlen int) string {
return randStringFromCharSet(strlen, charSetAlphaNum)
}

// randStringFromCharSet generates a random string by selecting characters from
// the charset provided
func randStringFromCharSet(strlen int, charSet string) string {
result := make([]byte, strlen)
for i := 0; i < strlen; i++ {
result[i] = charSet[rand.Intn(len(charSet))]
}
return string(result)
}
2 changes: 1 addition & 1 deletion azurerm/internal/acceptance/helpers/check_destroyed.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package helpers
import (
"fmt"

"github.com/hashicorp/terraform-plugin-sdk/terraform"
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance/types"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients"
)
Expand Down
2 changes: 1 addition & 1 deletion azurerm/internal/acceptance/helpers/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package helpers
import (
"fmt"

"github.com/hashicorp/terraform-plugin-sdk/terraform"
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance/types"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients"
)
Expand Down
2 changes: 1 addition & 1 deletion azurerm/internal/acceptance/helpers/exists.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package helpers
import (
"fmt"

"github.com/hashicorp/terraform-plugin-sdk/terraform"
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance/types"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/tf/pluginsdk"
Expand Down
4 changes: 2 additions & 2 deletions azurerm/internal/acceptance/plugin_sdk_aliases.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package acceptance
import (
"regexp"

"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/terraform"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/tf/pluginsdk"
)

Expand Down
22 changes: 0 additions & 22 deletions azurerm/internal/acceptance/providers.go

This file was deleted.

4 changes: 1 addition & 3 deletions azurerm/internal/acceptance/random.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,9 @@ import (
"strings"
"time"

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

const CharSetAlpha = acctest.CharSetAlpha

func RandTimeInt() int {
// acctest.RantInt() returns a value of size:
// 000000000000000000
Expand Down
7 changes: 4 additions & 3 deletions azurerm/internal/acceptance/ssh/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ package ssh

import (
"bytes"
"context"
"fmt"
"log"
"time"

"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"golang.org/x/crypto/ssh"
)

Expand All @@ -18,8 +19,8 @@ type Runner struct {
CommandsToRun []string
}

func (r Runner) Run() error {
if err := resource.Retry(5*time.Minute, r.tryRun); err != nil {
func (r Runner) Run(ctx context.Context) error {
if err := resource.RetryContext(ctx, 5*time.Minute, r.tryRun); err != nil {
return err
}

Expand Down
4 changes: 2 additions & 2 deletions azurerm/internal/acceptance/steps.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import (
"fmt"
"strings"

"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/terraform"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance/helpers"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance/testclient"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance/types"
Expand Down
27 changes: 12 additions & 15 deletions azurerm/internal/acceptance/testcase.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ import (
"fmt"
"testing"

"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/terraform"
"github.com/terraform-providers/terraform-provider-azuread/azuread"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"

"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance/helpers"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance/testclient"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance/types"
Expand Down Expand Up @@ -82,16 +83,12 @@ func RunTestsInSequence(t *testing.T, tests map[string]map[string]func(t *testin
}

func (td TestData) runAcceptanceTest(t *testing.T, testCase resource.TestCase) {
testCase.ProviderFactories = map[string]terraform.ResourceProviderFactory{
"azuread": func() (terraform.ResourceProvider, error) {
aad := azuread.Provider()
return aad, nil
},
"azurerm": func() (terraform.ResourceProvider, error) {
testCase.ProviderFactories = map[string]func() (*schema.Provider, error){
"azurerm": func() (*schema.Provider, error) { //nolint:unparam
azurerm := provider.TestAzureProvider()
return azurerm, nil
},
"azurerm-alt": func() (terraform.ResourceProvider, error) {
"azurerm-alt": func() (*schema.Provider, error) { //nolint:unparam
azurerm := provider.TestAzureProvider()
return azurerm, nil
},
Expand All @@ -101,12 +98,12 @@ func (td TestData) runAcceptanceTest(t *testing.T, testCase resource.TestCase) {
}

func (td TestData) runAcceptanceSequentialTest(t *testing.T, testCase resource.TestCase) {
testCase.ProviderFactories = map[string]terraform.ResourceProviderFactory{
"azuread": func() (terraform.ResourceProvider, error) {
aad := azuread.Provider()
return aad, nil
testCase.ProviderFactories = map[string]func() (*schema.Provider, error){
"azurerm": func() (*schema.Provider, error) { //nolint:unparam
azurerm := provider.TestAzureProvider()
return azurerm, nil
},
"azurerm": func() (terraform.ResourceProvider, error) {
"azurerm-alt": func() (*schema.Provider, error) { //nolint:unparam
azurerm := provider.TestAzureProvider()
return azurerm, nil
},
Expand Down
2 changes: 1 addition & 1 deletion azurerm/internal/acceptance/testing.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (

"github.com/Azure/go-autorest/autorest/azure"
"github.com/hashicorp/go-azure-helpers/authentication"
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
)

func PreCheck(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion azurerm/internal/common/client_options.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"github.com/Azure/go-autorest/autorest"
"github.com/Azure/go-autorest/autorest/azure"
"github.com/hashicorp/go-azure-helpers/sender"
"github.com/hashicorp/terraform-plugin-sdk/meta"
"github.com/hashicorp/terraform-plugin-sdk/v2/meta"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features"
"github.com/terraform-providers/terraform-provider-azurerm/version"
)
Expand Down
2 changes: 1 addition & 1 deletion azurerm/internal/identity/user_assigned.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package identity

import (
"github.com/hashicorp/terraform-plugin-sdk/helper/validation"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
msivalidate "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/msi/validate"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/tf/pluginsdk"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils"
Expand Down
2 changes: 1 addition & 1 deletion azurerm/internal/provider/features.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package provider

import (
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/tf/pluginsdk"
)
Expand Down
Loading

0 comments on commit 5553d2c

Please sign in to comment.