Skip to content

Commit

Permalink
linting
Browse files Browse the repository at this point in the history
  • Loading branch information
tombuildsstuff committed Jun 18, 2021
1 parent 788dda6 commit 2d4d7bc
Show file tree
Hide file tree
Showing 11 changed files with 56 additions and 57 deletions.
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/v2/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/v2/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/v2/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
5 changes: 3 additions & 2 deletions azurerm/internal/acceptance/ssh/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package ssh

import (
"bytes"
"context"
"fmt"
"log"
"time"
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
8 changes: 4 additions & 4 deletions azurerm/internal/acceptance/testcase.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,11 @@ 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]func() (*schema.Provider, error){
"azurerm": func() (*schema.Provider, error) {
"azurerm": func() (*schema.Provider, error) { //nolint:unparam
azurerm := provider.TestAzureProvider()
return azurerm, nil
},
"azurerm-alt": func() (*schema.Provider, error) {
"azurerm-alt": func() (*schema.Provider, error) { //nolint:unparam
azurerm := provider.TestAzureProvider()
return azurerm, nil
},
Expand All @@ -99,11 +99,11 @@ func (td TestData) runAcceptanceTest(t *testing.T, testCase resource.TestCase) {

func (td TestData) runAcceptanceSequentialTest(t *testing.T, testCase resource.TestCase) {
testCase.ProviderFactories = map[string]func() (*schema.Provider, error){
"azurerm": func() (*schema.Provider, error) {
"azurerm": func() (*schema.Provider, error) { //nolint:unparam
azurerm := provider.TestAzureProvider()
return azurerm, nil
},
"azurerm-alt": func() (*schema.Provider, error) {
"azurerm-alt": func() (*schema.Provider, error) { //nolint:unparam
azurerm := provider.TestAzureProvider()
return azurerm, nil
},
Expand Down
20 changes: 11 additions & 9 deletions azurerm/internal/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import (
"os"
"strings"

"github.com/hashicorp/terraform-plugin-sdk/v2/diag"

"github.com/hashicorp/go-azure-helpers/authentication"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
Expand Down Expand Up @@ -242,13 +244,13 @@ func azureProvider(supportLegacyTestSuite bool) *schema.Provider {
}
}

p.ConfigureFunc = providerConfigure(p)
p.ConfigureContextFunc = providerConfigure(p)

return p
}

func providerConfigure(p *schema.Provider) schema.ConfigureFunc {
return func(d *schema.ResourceData) (interface{}, error) {
func providerConfigure(p *schema.Provider) schema.ConfigureContextFunc {
return func(ctx context.Context, d *schema.ResourceData) (interface{}, diag.Diagnostics) {
var auxTenants []string
if v, ok := d.Get("auxiliary_tenant_ids").([]interface{}); ok && len(v) > 0 {
auxTenants = *utils.ExpandStringSlice(v)
Expand All @@ -257,7 +259,7 @@ func providerConfigure(p *schema.Provider) schema.ConfigureFunc {
}

if len(auxTenants) > 3 {
return nil, fmt.Errorf("The provider only supports 3 auxiliary tenant IDs")
return nil, diag.FromErr(fmt.Errorf("The provider only supports 3 auxiliary tenant IDs"))
}

metadataHost := d.Get("metadata_host").(string)
Expand Down Expand Up @@ -294,7 +296,7 @@ func providerConfigure(p *schema.Provider) schema.ConfigureFunc {

config, err := builder.Build()
if err != nil {
return nil, fmt.Errorf("Error building AzureRM Client: %s", err)
return nil, diag.FromErr(fmt.Errorf("Error building AzureRM Client: %s", err))
}

terraformVersion := p.TerraformVersion
Expand All @@ -321,7 +323,7 @@ func providerConfigure(p *schema.Provider) schema.ConfigureFunc {
}
client, err := clients.Build(context.TODO(), clientBuilder)
if err != nil {
return nil, err
return nil, diag.FromErr(err)
}

client.StopContext = context.TODO()
Expand All @@ -332,16 +334,16 @@ func providerConfigure(p *schema.Provider) schema.ConfigureFunc {
ctx := client.StopContext
providerList, err := client.Resource.ProvidersClient.List(ctx, nil, "")
if err != nil {
return nil, fmt.Errorf("Unable to list provider registration status, it is possible that this is due to invalid "+
return nil, diag.FromErr(fmt.Errorf("Unable to list provider registration status, it is possible that this is due to invalid "+
"credentials or the service principal does not have permission to use the Resource Manager API, Azure "+
"error: %s", err)
"error: %s", err))
}

availableResourceProviders := providerList.Values()
requiredResourceProviders := resourceproviders.Required()

if err := resourceproviders.EnsureRegistered(ctx, *client.Resource.ProvidersClient, availableResourceProviders, requiredResourceProviders); err != nil {
return nil, fmt.Errorf(resourceProviderRegistrationErrorFmt, err)
return nil, diag.FromErr(fmt.Errorf(resourceProviderRegistrationErrorFmt, err))
}
}

Expand Down
2 changes: 1 addition & 1 deletion azurerm/internal/provider/provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func TestResourcesSupportCustomTimeouts(t *testing.T) {
}

// every Resource has to have a Create, Read & Destroy timeout
if resource.Timeouts.Create == nil && resource.Create != nil {
if resource.Timeouts.Create == nil && resource.Create != nil { //nolint:SA1019
t.Fatalf("Resource %q defines a Create method but no Create Timeout", resourceName)
}
if resource.Timeouts.Delete == nil && resource.Delete != nil {
Expand Down
26 changes: 13 additions & 13 deletions azurerm/internal/sdk/plugin_sdk_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func TestAccPluginSDKAndDecoder(t *testing.T) {
// lintignore:AT001
resource.ParallelTest(t, resource.TestCase{
ProviderFactories: map[string]func() (*schema.Provider, error){
"validator": func() (*schema.Provider, error) {
"validator": func() (*schema.Provider, error) { //nolint:unparam
return &schema.Provider{
DataSourcesMap: map[string]*schema.Resource{},
ResourcesMap: map[string]*schema.Resource{
Expand Down Expand Up @@ -150,7 +150,7 @@ func TestAccPluginSDKAndDecoder(t *testing.T) {
},
},
},
Create: func(d *schema.ResourceData, i interface{}) error {
Create: func(d *schema.ResourceData, i interface{}) error { //nolint:SA1019
d.SetId("some-id")
d.Set("hello", "world")
d.Set("random_number", 42)
Expand Down Expand Up @@ -263,13 +263,13 @@ func TestAccPluginSDKAndDecoderOptionalComputed(t *testing.T) {
// lintignore:AT001
resource.ParallelTest(t, resource.TestCase{
ProviderFactories: map[string]func() (*schema.Provider, error){
"validator": func() (*schema.Provider, error) {
"validator": func() (*schema.Provider, error) { //nolint:unparam
return &schema.Provider{
DataSourcesMap: map[string]*schema.Resource{},
ResourcesMap: map[string]*schema.Resource{
"validator_decoder_specified": {
Schema: commonSchema,
Create: func(d *schema.ResourceData, i interface{}) error {
Create: func(d *schema.ResourceData, i interface{}) error { //nolint:SA1019
d.SetId("some-id")
return nil
},
Expand All @@ -285,7 +285,7 @@ func TestAccPluginSDKAndDecoderOptionalComputed(t *testing.T) {

"validator_decoder_unspecified": {
Schema: commonSchema,
Create: func(d *schema.ResourceData, i interface{}) error {
Create: func(d *schema.ResourceData, i interface{}) error { //nolint:SA1019
d.SetId("some-id")
d.Set("hello", "value-from-create")
d.Set("number", 42)
Expand Down Expand Up @@ -349,7 +349,7 @@ func TestAccPluginSDKAndDecoderOptionalComputedOverride(t *testing.T) {
// lintignore:AT001
resource.ParallelTest(t, resource.TestCase{
ProviderFactories: map[string]func() (*schema.Provider, error){
"validator": func() (*schema.Provider, error) {
"validator": func() (*schema.Provider, error) { //nolint:unparam
return &schema.Provider{
DataSourcesMap: map[string]*schema.Resource{},
ResourcesMap: map[string]*schema.Resource{
Expand All @@ -371,7 +371,7 @@ func TestAccPluginSDKAndDecoderOptionalComputedOverride(t *testing.T) {
Computed: true,
},
},
Create: func(d *schema.ResourceData, i interface{}) error {
Create: func(d *schema.ResourceData, i interface{}) error { //nolint:SA1019
d.SetId("some-id")
d.Set("hello", "value-from-create")
d.Set("number", 42)
Expand Down Expand Up @@ -455,7 +455,7 @@ func TestAccPluginSDKAndDecoderSets(t *testing.T) {
// lintignore:AT001
resource.ParallelTest(t, resource.TestCase{
ProviderFactories: map[string]func() (*schema.Provider, error){
"validator": func() (*schema.Provider, error) {
"validator": func() (*schema.Provider, error) { //nolint:unparam
return &schema.Provider{
DataSourcesMap: map[string]*schema.Resource{},
ResourcesMap: map[string]*schema.Resource{
Expand Down Expand Up @@ -490,7 +490,7 @@ func TestAccPluginSDKAndDecoderSets(t *testing.T) {
},
},
},
Create: func(d *schema.ResourceData, i interface{}) error {
Create: func(d *schema.ResourceData, i interface{}) error { //nolint:SA1019
d.SetId("some-id")
d.Set("set_of_strings", []string{
"some",
Expand Down Expand Up @@ -648,7 +648,7 @@ func TestAccPluginSDKAndEncoder(t *testing.T) {
// lintignore:AT001
resource.ParallelTest(t, resource.TestCase{
ProviderFactories: map[string]func() (*schema.Provider, error){
"validator": func() (*schema.Provider, error) {
"validator": func() (*schema.Provider, error) { //nolint:unparam
return &schema.Provider{
DataSourcesMap: map[string]*schema.Resource{},
ResourcesMap: map[string]*schema.Resource{
Expand Down Expand Up @@ -763,7 +763,7 @@ func TestAccPluginSDKAndEncoder(t *testing.T) {
},
},
},
Create: func(d *schema.ResourceData, i interface{}) error {
Create: func(d *schema.ResourceData, i interface{}) error { //nolint:SA1019
wrapper := ResourceMetaData{
ResourceData: d,
Logger: ConsoleLogger{},
Expand Down Expand Up @@ -866,7 +866,7 @@ func TestAccPluginSDKReturnsComputedFields(t *testing.T) {
// lintignore:AT001
resource.ParallelTest(t, resource.TestCase{
ProviderFactories: map[string]func() (*schema.Provider, error){
"validator": func() (*schema.Provider, error) {
"validator": func() (*schema.Provider, error) { //nolint:unparam
return &schema.Provider{
DataSourcesMap: map[string]*schema.Resource{},
ResourcesMap: map[string]*schema.Resource{
Expand Down Expand Up @@ -980,7 +980,7 @@ func computedFieldsResource() *schema.Resource {
},
},
},
Create: func(d *schema.ResourceData, meta interface{}) error {
Create: func(d *schema.ResourceData, meta interface{}) error { //nolint:SA1019
d.SetId("does-not-matter")
return readFunc(d, meta)
},
Expand Down
2 changes: 1 addition & 1 deletion azurerm/internal/services/compute/image_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ func (ImageResource) generalizeVirtualMachine(data acceptance.TestData) func(con
ssh.LinuxAgentDeprovisionCommand,
},
}
if err := sshGeneralizationCommand.Run(); err != nil {
if err := sshGeneralizationCommand.Run(ctx); err != nil {
return fmt.Errorf("Bad: running generalization command: %+v", err)
}

Expand Down
3 changes: 2 additions & 1 deletion azurerm/internal/tf/schema/import_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package schema

import (
"context"
"fmt"
"log"
"testing"
Expand Down Expand Up @@ -37,7 +38,7 @@ func TestValidateResourceIDPriorToImport(t *testing.T) {
f := ValidateResourceIDPriorToImport(v.validator)
resourceData := &schema.ResourceData{}
resourceData.SetId("hello")
_, err := f.State(resourceData, nil)
_, err := f.StateContext(context.TODO(), resourceData, nil)
wasImported := err == nil

if v.shouldBeImported != wasImported {
Expand Down
Loading

0 comments on commit 2d4d7bc

Please sign in to comment.