Skip to content

Commit

Permalink
Update Terraform SDK to V2
Browse files Browse the repository at this point in the history
Use v2.4.1 version of terraform-plugin-sdk.

Cleanup imports.

Change `validation.SingleIP()` -> `validation.IsIPAddress`,
`validation.ValidateRFC3339TimeString` -> `validation.IsRFC3339Time`.

Replace `Removed` Schema property with `Deprecated`.

Provide context into CustomizeDiff functions.

Use functions with the new signatures to configure the Provider with
Terraform SDK V2.

Add context into resourceImagesImageV2UpdateComputedAttributes.

Fix gofmt in pathorcontents package.

Fix networking_port_v2 datasource issue: "profile: StateFunc is
extraneous, value should just be changed before setting on computed-only
field" by removing custom StateFunc.

Fix containerinfra_cluster_v1 resource issuze: "kubeconfig: TypeMap with
Elem *Resource not supported, use TypeList/TypeSet with Elem *Resource
or TypeMap with Elem *Schema" by changing type to Type.Schema and
updating flattenContainerInfraV1Kubeconfig function.

Change the deprecated "Providers" field of resource.Test to
"ProviderFactories".

Use CreateContext, ReadContext, UpdateContext, DeleteContext instead of
deprecated resource functions. Use diag.Diagnostics and Context for
those functions.
  • Loading branch information
ozerovandrei committed Feb 27, 2021
1 parent 674189c commit cfadc45
Show file tree
Hide file tree
Showing 427 changed files with 4,363 additions and 3,881 deletions.
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ go 1.15
require (
github.com/gophercloud/gophercloud v0.16.0
github.com/gophercloud/utils v0.0.0-20210216074907-f6de111f2eae
github.com/hashicorp/terraform-plugin-sdk v1.16.0
github.com/hashicorp/terraform-plugin-sdk/v2 v2.4.4
github.com/mitchellh/go-homedir v1.1.0
github.com/stretchr/testify v1.4.0
github.com/stretchr/testify v1.6.1
gopkg.in/yaml.v2 v2.4.0
)
88 changes: 44 additions & 44 deletions go.sum

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package main

import (
"github.com/hashicorp/terraform-plugin-sdk/plugin"
"github.com/hashicorp/terraform-plugin-sdk/v2/plugin"
"github.com/terraform-provider-openstack/terraform-provider-openstack/openstack"
)

Expand Down
3 changes: 1 addition & 2 deletions openstack/blockstorage_extensions.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ import (
"fmt"

"github.com/gophercloud/gophercloud/openstack/blockstorage/extensions/schedulerhints"

"github.com/hashicorp/terraform-plugin-sdk/helper/hashcode"
"github.com/gophercloud/utils/terraform/hashcode"
)

func expandBlockStorageExtensionsSchedulerHints(v schedulerhints.SchedulerHints) map[string]interface{} {
Expand Down
3 changes: 2 additions & 1 deletion openstack/blockstorage_extensions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ package openstack
import (
"testing"

"github.com/gophercloud/gophercloud/openstack/blockstorage/extensions/schedulerhints"
"github.com/stretchr/testify/assert"

"github.com/gophercloud/gophercloud/openstack/blockstorage/extensions/schedulerhints"
)

func blockStorageExtensionsSchedulerHints() schedulerhints.SchedulerHints {
Expand Down
3 changes: 2 additions & 1 deletion openstack/blockstorage_volume_attach_v2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ package openstack
import (
"testing"

"github.com/gophercloud/gophercloud/openstack/blockstorage/extensions/volumeactions"
"github.com/stretchr/testify/assert"

"github.com/gophercloud/gophercloud/openstack/blockstorage/extensions/volumeactions"
)

func TestExpandBlockStorageV2AttachMode(t *testing.T) {
Expand Down
3 changes: 2 additions & 1 deletion openstack/blockstorage_volume_attach_v3_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ package openstack
import (
"testing"

"github.com/gophercloud/gophercloud/openstack/blockstorage/extensions/volumeactions"
"github.com/stretchr/testify/assert"

"github.com/gophercloud/gophercloud/openstack/blockstorage/extensions/volumeactions"
)

func TestExpandBlockStorageV3AttachMode(t *testing.T) {
Expand Down
6 changes: 3 additions & 3 deletions openstack/blockstorage_volume_v1.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import (
"bytes"
"fmt"

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

"github.com/gophercloud/gophercloud"
"github.com/gophercloud/gophercloud/openstack/blockstorage/v1/volumes"

"github.com/hashicorp/terraform-plugin-sdk/helper/hashcode"
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
"github.com/gophercloud/utils/terraform/hashcode"
)

func flattenBlockStorageVolumeV1Attachments(v []map[string]interface{}) []map[string]interface{} {
Expand Down
4 changes: 2 additions & 2 deletions openstack/blockstorage_volume_v1_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import (
"testing"
"time"

"github.com/gophercloud/gophercloud/openstack/blockstorage/v1/volumes"

"github.com/stretchr/testify/assert"

"github.com/gophercloud/gophercloud/openstack/blockstorage/v1/volumes"
)

func blockStorageVolumeV1VolumeFixture() *volumes.Volume {
Expand Down
6 changes: 3 additions & 3 deletions openstack/blockstorage_volume_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import (
"bytes"
"fmt"

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

"github.com/gophercloud/gophercloud"
"github.com/gophercloud/gophercloud/openstack/blockstorage/v2/volumes"

"github.com/hashicorp/terraform-plugin-sdk/helper/hashcode"
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
"github.com/gophercloud/utils/terraform/hashcode"
)

func flattenBlockStorageVolumeV2Attachments(v []volumes.Attachment) []map[string]interface{} {
Expand Down
4 changes: 2 additions & 2 deletions openstack/blockstorage_volume_v2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import (
"testing"
"time"

"github.com/gophercloud/gophercloud/openstack/blockstorage/v2/volumes"

"github.com/stretchr/testify/assert"

"github.com/gophercloud/gophercloud/openstack/blockstorage/v2/volumes"
)

func blockStorageVolumeV2VolumeFixture() volumes.Volume {
Expand Down
6 changes: 3 additions & 3 deletions openstack/blockstorage_volume_v3.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import (
"bytes"
"fmt"

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

"github.com/gophercloud/gophercloud"
"github.com/gophercloud/gophercloud/openstack/blockstorage/v3/volumes"

"github.com/hashicorp/terraform-plugin-sdk/helper/hashcode"
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
"github.com/gophercloud/utils/terraform/hashcode"
)

func flattenBlockStorageVolumeV3Attachments(v []volumes.Attachment) []map[string]interface{} {
Expand Down
4 changes: 2 additions & 2 deletions openstack/blockstorage_volume_v3_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import (
"testing"
"time"

"github.com/gophercloud/gophercloud/openstack/blockstorage/v3/volumes"

"github.com/stretchr/testify/assert"

"github.com/gophercloud/gophercloud/openstack/blockstorage/v3/volumes"
)

func blockStorageVolumeV3VolumeFixture() volumes.Volume {
Expand Down
4 changes: 1 addition & 3 deletions openstack/compute_flavor_v2.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package openstack

import (
"github.com/gophercloud/gophercloud/openstack/compute/v2/flavors"
)
import "github.com/gophercloud/gophercloud/openstack/compute/v2/flavors"

func expandComputeFlavorV2ExtraSpecs(raw map[string]interface{}) flavors.ExtraSpecsOpts {
extraSpecs := make(flavors.ExtraSpecsOpts, len(raw))
Expand Down
2 changes: 1 addition & 1 deletion openstack/compute_floatingip_associate_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"fmt"
"strings"

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

"github.com/gophercloud/gophercloud"
"github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/floatingips"
Expand Down
3 changes: 2 additions & 1 deletion openstack/compute_instance_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,13 @@ import (
"log"
"os"

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

"github.com/gophercloud/gophercloud"
"github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/tenantnetworks"
"github.com/gophercloud/gophercloud/openstack/compute/v2/servers"
"github.com/gophercloud/gophercloud/openstack/networking/v2/networks"
"github.com/gophercloud/gophercloud/openstack/networking/v2/ports"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
)

const (
Expand Down
4 changes: 2 additions & 2 deletions openstack/compute_interface_attach_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ import (
"log"
"strings"

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

"github.com/gophercloud/gophercloud"
"github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/attachinterfaces"

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

func computeInterfaceAttachV2AttachFunc(
Expand Down
4 changes: 1 addition & 3 deletions openstack/compute_keypair_v2.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package openstack

import (
"github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/keypairs"
)
import "github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/keypairs"

// ComputeKeyPairV2CreateOpts is a custom KeyPair struct to include the ValueSpecs field.
type ComputeKeyPairV2CreateOpts struct {
Expand Down
7 changes: 4 additions & 3 deletions openstack/compute_secgroup_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@ import (
"log"
"strings"

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

"github.com/gophercloud/gophercloud"
"github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/secgroups"
"github.com/hashicorp/terraform-plugin-sdk/helper/hashcode"
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/gophercloud/utils/terraform/hashcode"
)

func computeSecGroupV2RulesCheckForErrors(d *schema.ResourceData) error {
Expand Down
3 changes: 2 additions & 1 deletion openstack/compute_servergroup_v2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ package openstack
import (
"testing"

"github.com/stretchr/testify/assert"

"github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/servergroups"
th "github.com/gophercloud/gophercloud/testhelper"
thclient "github.com/gophercloud/gophercloud/testhelper/client"
"github.com/stretchr/testify/assert"
)

func TestComputeServerGroupV2CreateOpts(t *testing.T) {
Expand Down
4 changes: 2 additions & 2 deletions openstack/compute_volume_attach_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import (
"log"
"strings"

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

"github.com/gophercloud/gophercloud"
"github.com/gophercloud/gophercloud/openstack/blockstorage/v3/volumes"
"github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/volumeattach"

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

func computeVolumeAttachV2ParseID(id string) (string, string, error) {
Expand Down
4 changes: 1 addition & 3 deletions openstack/compute_volume_attach_v2_test.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package openstack

import (
"testing"
)
import "testing"

func TestComputeVolumeAttachV2ParseID(t *testing.T) {
id := "foo/bar"
Expand Down
28 changes: 12 additions & 16 deletions openstack/containerinfra_shared_v1.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,14 @@ import (
"os"
"strings"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"gopkg.in/yaml.v2"

"github.com/gophercloud/gophercloud"
"github.com/gophercloud/gophercloud/openstack/containerinfra/v1/certificates"
"github.com/gophercloud/gophercloud/openstack/containerinfra/v1/clusters"
"github.com/gophercloud/gophercloud/openstack/containerinfra/v1/clustertemplates"

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

yaml "gopkg.in/yaml.v2"
)

const (
Expand Down Expand Up @@ -170,13 +169,10 @@ type kubernetesConfigUserData struct {
ClientCertificateData string `yaml:"client-certificate-data"`
}

func flattenContainerInfraV1Kubeconfig(d *schema.ResourceData, containerInfraClient *gophercloud.ServiceClient) (map[string]interface{}, error) {
var kubeconfig map[string]interface{}
name := d.Get("name").(string)
host := d.Get("api_address").(string)

if d.Get("kubeconfig.client_certificate").(string) != "" {
return d.Get("kubeconfig").(map[string]interface{}), nil
func flattenContainerInfraV1Kubeconfig(d *schema.ResourceData, containerInfraClient *gophercloud.ServiceClient) (map[string]string, error) {
clientSert, ok := d.Get("kubeconfig.client_certificate").(string)
if ok && clientSert != "" {
return d.Get("kubeconfig").(map[string]string), nil
}

certificateAuthority, err := certificates.Get(containerInfraClient, d.Id()).Extract()
Expand Down Expand Up @@ -228,20 +224,20 @@ func flattenContainerInfraV1Kubeconfig(d *schema.ResourceData, containerInfraCli
return nil, fmt.Errorf("Error requesting client certificate: %s", err)
}

name := d.Get("name").(string)
host := d.Get("api_address").(string)
rawKubeconfig, err := renderKubeconfig(name, host, []byte(certificateAuthority.PEM), []byte(clientCertificate.PEM), pemClientKey)
if err != nil {
return nil, fmt.Errorf("Error rendering kubeconfig: %s", err)
}

kubeconfig = map[string]interface{}{
return map[string]string{
"raw_config": string(rawKubeconfig),
"host": host,
"cluster_ca_certificate": certificateAuthority.PEM,
"client_certificate": clientCertificate.PEM,
"client_key": string(pemClientKey),
}

return kubeconfig, nil
}, nil
}

func renderKubeconfig(name string, host string, clusterCaCertificate []byte, clientCertificate []byte, clientKey []byte) ([]byte, error) {
Expand Down
4 changes: 2 additions & 2 deletions openstack/containerinfra_shared_v1_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ package openstack
import (
"testing"

"github.com/gophercloud/gophercloud/openstack/containerinfra/v1/clustertemplates"

"github.com/stretchr/testify/assert"

"github.com/gophercloud/gophercloud/openstack/containerinfra/v1/clustertemplates"
)

func TestExpandContainerInfraV1LabelsMap(t *testing.T) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
package openstack

import (
"fmt"
"context"
"sort"

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

"github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/availabilityzones"
"github.com/hashicorp/terraform-plugin-sdk/helper/hashcode"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/helper/validation"
"github.com/gophercloud/utils/terraform/hashcode"
)

func dataSourceBlockStorageAvailabilityZonesV3() *schema.Resource {
return &schema.Resource{
Read: dataSourceBlockStorageAvailabilityZonesV3Read,
ReadContext: dataSourceBlockStorageAvailabilityZonesV3Read,
Schema: map[string]*schema.Schema{
"region": {
Type: schema.TypeString,
Expand All @@ -38,20 +40,20 @@ func dataSourceBlockStorageAvailabilityZonesV3() *schema.Resource {
}
}

func dataSourceBlockStorageAvailabilityZonesV3Read(d *schema.ResourceData, meta interface{}) error {
func dataSourceBlockStorageAvailabilityZonesV3Read(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
config := meta.(*Config)
client, err := config.BlockStorageV3Client(GetRegion(d, config))
if err != nil {
return fmt.Errorf("Error creating OpenStack block storage client: %s", err)
return diag.Errorf("Error creating OpenStack block storage client: %s", err)
}

allPages, err := availabilityzones.List(client).AllPages()
if err != nil {
return fmt.Errorf("Error retrieving openstack_blockstorage_availability_zones_v3: %s", err)
return diag.Errorf("Error retrieving openstack_blockstorage_availability_zones_v3: %s", err)
}
zoneInfo, err := availabilityzones.ExtractAvailabilityZones(allPages)
if err != nil {
return fmt.Errorf("Error extracting openstack_blockstorage_availability_zones_v3 from response: %s", err)
return diag.Errorf("Error extracting openstack_blockstorage_availability_zones_v3 from response: %s", err)
}

stateBool := d.Get("state").(string) == "available"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ import (
"regexp"
"testing"

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

func TestAccBlockStorageV3AvailabilityZonesV3_basic(t *testing.T) {
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
PreCheck: func() { testAccPreCheck(t) },
ProviderFactories: testAccProviders,
Steps: []resource.TestStep{
{
Config: testAccBlockStorageV3AvailabilityZonesConfig,
Expand Down

0 comments on commit cfadc45

Please sign in to comment.