Skip to content

Commit

Permalink
Migrate vkcs_db_datastore_capabilities data source to terraform-plugi…
Browse files Browse the repository at this point in the history
…n-framework

* Add provider based on terraform-provider-framework

* Switch tests to terraform-plugin-testing

* Support terraform-plugin-framework in schema customization

---------

Co-authored-by: panic <[email protected]>
  • Loading branch information
Gvg14u147 and paaanic committed Jun 5, 2023
1 parent 673b8cd commit b9aae92
Show file tree
Hide file tree
Showing 242 changed files with 2,701 additions and 1,384 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Terraform VKCS Provider
Requirements
------------

- [Terraform](https://www.terraform.io/downloads.html) 1.0.x
- [Terraform](https://www.terraform.io/downloads.html) 1.1.5 and later
- [Go](https://golang.org/doc/install) 1.18 (to build the provider plugin)

Using The Provider
Expand Down
26 changes: 14 additions & 12 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@ require (
github.com/gophercloud/gophercloud v0.24.0
github.com/gophercloud/utils v0.0.0-20220307143606-8e7800759d16
github.com/hashicorp/go-cty v1.4.1-0.20200414143053-d3edf31b6320
github.com/hashicorp/terraform-plugin-sdk/v2 v2.24.0
github.com/hashicorp/terraform-plugin-framework v1.2.0
github.com/hashicorp/terraform-plugin-go v0.15.0
github.com/hashicorp/terraform-plugin-mux v0.10.0
github.com/hashicorp/terraform-plugin-sdk/v2 v2.26.1
github.com/hashicorp/terraform-plugin-testing v1.2.0
github.com/mitchellh/go-homedir v1.1.0
github.com/mitchellh/mapstructure v1.5.0
github.com/satori/go.uuid v1.2.0
Expand All @@ -17,28 +21,26 @@ require (

require (
github.com/agext/levenshtein v1.2.3 // indirect
github.com/apparentlymart/go-cidr v1.1.0 // indirect
github.com/apparentlymart/go-textseg/v13 v13.0.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/fatih/color v1.13.0 // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/hashicorp/errwrap v1.1.0 // indirect
github.com/hashicorp/go-checkpoint v0.5.0 // indirect
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
github.com/hashicorp/go-hclog v1.4.0 // indirect
github.com/hashicorp/go-hclog v1.5.0 // indirect
github.com/hashicorp/go-multierror v1.1.1 // indirect
github.com/hashicorp/go-plugin v1.4.8 // indirect
github.com/hashicorp/go-plugin v1.4.9 // indirect
github.com/hashicorp/go-uuid v1.0.3 // indirect
github.com/hashicorp/go-version v1.6.0 // indirect
github.com/hashicorp/hc-install v0.5.0 // indirect
github.com/hashicorp/hcl/v2 v2.16.2 // indirect
github.com/hashicorp/logutils v1.0.0 // indirect
github.com/hashicorp/terraform-exec v0.18.1 // indirect
github.com/hashicorp/terraform-json v0.16.0 // indirect
github.com/hashicorp/terraform-plugin-go v0.14.3 // indirect
github.com/hashicorp/terraform-plugin-log v0.8.0 // indirect
github.com/hashicorp/terraform-registry-address v0.1.0 // indirect
github.com/hashicorp/terraform-svchost v0.0.0-20200729002733-f050f53b9734 // indirect
github.com/hashicorp/terraform-registry-address v0.2.0 // indirect
github.com/hashicorp/terraform-svchost v0.0.1 // indirect
github.com/hashicorp/yamux v0.0.0-20211028200310-0bc27b27de87 // indirect
github.com/mattn/go-colorable v0.1.12 // indirect
github.com/mattn/go-isatty v0.0.14 // indirect
Expand All @@ -50,18 +52,18 @@ require (
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/stretchr/objx v0.4.0 // indirect
github.com/vmihailenco/msgpack v4.0.4+incompatible // indirect
github.com/vmihailenco/msgpack/v4 v4.3.12 // indirect
github.com/vmihailenco/tagparser v0.1.2 // indirect
github.com/vmihailenco/msgpack/v5 v5.3.5 // indirect
github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect
github.com/zclconf/go-cty v1.13.1 // indirect
golang.org/x/crypto v0.7.0 // indirect
golang.org/x/mod v0.8.0 // indirect
golang.org/x/net v0.8.0 // indirect
golang.org/x/sys v0.6.0 // indirect
golang.org/x/text v0.8.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/genproto v0.0.0-20220525015930-6ca3db687a9d // indirect
google.golang.org/grpc v1.51.0 // indirect
google.golang.org/protobuf v1.28.1 // indirect
google.golang.org/genproto v0.0.0-20230110181048-76db0878b65f // indirect
google.golang.org/grpc v1.54.0 // indirect
google.golang.org/protobuf v1.30.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
162 changes: 28 additions & 134 deletions go.sum

Large diffs are not rendered by default.

26 changes: 0 additions & 26 deletions helpers/providerjson/helpers.go

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
package providerjson
package json

import (
"encoding/json"
"os"

"github.com/vk-cs/terraform-provider-vkcs/helpers/providerjson/schema"
)

func ReadWithWrapper(filename string) (*ProviderWrapper, error) {
func ReadWithWrapper(filename string) (*schema.ProviderWrapper, error) {
f, err := os.Open(filename)
if err != nil {
return nil, err
}
defer f.Close()

var pw ProviderWrapper
var pw schema.ProviderWrapper
err = json.NewDecoder(f).Decode(&pw)
if err != nil {
return nil, err
Expand Down
33 changes: 33 additions & 0 deletions helpers/providerjson/json/write.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package json

import (
"encoding/json"
"os"

"github.com/vk-cs/terraform-provider-vkcs/helpers/providerjson/schema"
)

func DumpWithWrapper(wrapper *schema.ProviderWrapper) error {
if err := json.NewEncoder(os.Stdout).Encode(wrapper); err != nil {
return err
}

return nil
}

func WriteWithWrapper(wrapper *schema.ProviderWrapper, filename string) error {
f, err := os.Create(filename)
if err != nil {
return err
}
defer f.Close()

encoder := json.NewEncoder(f)
encoder.SetIndent("", " ")

if err := encoder.Encode(wrapper); err != nil {
return err
}

return nil
}
70 changes: 70 additions & 0 deletions helpers/providerjson/schema/helpers.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package schema

import (
"context"

"github.com/hashicorp/terraform-plugin-framework/datasource"
ds_schema "github.com/hashicorp/terraform-plugin-framework/datasource/schema"
"github.com/hashicorp/terraform-plugin-framework/provider"
"github.com/hashicorp/terraform-plugin-framework/resource"
rs_schema "github.com/hashicorp/terraform-plugin-framework/resource/schema"
sdkschema "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)

func (p *ProviderJSON) SDKSchema() map[string]*sdkschema.Schema {
return p.SDKProvider.Schema
}

func (p *ProviderJSON) SDKDataSourcesMap() map[string]*sdkschema.Resource {
return p.SDKProvider.DataSourcesMap
}

func (p *ProviderJSON) SDKResourcesMap() map[string]*sdkschema.Resource {
return p.SDKProvider.ResourcesMap
}

func (p *ProviderJSON) ResourcesMap() map[string]*rs_schema.Schema {
resourcesMap := make(map[string]*rs_schema.Schema)
ctx := context.Background()
providerMeta := provider.MetadataResponse{}
p.Provider.Metadata(ctx, provider.MetadataRequest{}, &providerMeta)

for _, f := range p.Provider.Resources(ctx) {
rs := f()
rsMeta := resource.MetadataResponse{}
rs.Metadata(ctx, resource.MetadataRequest{ProviderTypeName: providerMeta.TypeName}, &rsMeta)
rsSchema := resource.SchemaResponse{}
rs.Schema(ctx, resource.SchemaRequest{}, &rsSchema)
resourcesMap[rsMeta.TypeName] = &rsSchema.Schema
}

return resourcesMap
}

func (p *ProviderJSON) DataSourcesMap() map[string]*ds_schema.Schema {
dataSourcesMap := make(map[string]*ds_schema.Schema)
ctx := context.Background()
providerMeta := provider.MetadataResponse{}
p.Provider.Metadata(ctx, provider.MetadataRequest{}, &providerMeta)

for _, f := range p.Provider.DataSources(ctx) {
ds := f()
dsMeta := datasource.MetadataResponse{}
ds.Metadata(ctx, datasource.MetadataRequest{ProviderTypeName: providerMeta.TypeName}, &dsMeta)
dsSchema := datasource.SchemaResponse{}
ds.Schema(ctx, datasource.SchemaRequest{}, &dsSchema)
dataSourcesMap[dsMeta.TypeName] = &dsSchema.Schema
}

return dataSourcesMap
}

func NodeIsBlock(input SchemaJSON) bool {
if input.Type == SchemaTypeList || input.Type == SchemaTypeSet {
if _, ok := input.Elem.(ResourceJSON); ok {
return true
}
}

return false
}
Original file line number Diff line number Diff line change
@@ -1,21 +1,28 @@
package providerjson
package schema

import (
"encoding/json"

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

const (
SchemaTypeSet = "TypeSet"
SchemaTypeList = "TypeList"
SchemaTypeMap = "TypeMap"
SchemaTypeInt = "TypeInt"
SchemaTypeString = "String"
SchemaTypeBool = "Bool"
SchemaTypeFloat = "Float"
SchemaTypeString = "TypeString"
SchemaTypeBool = "TypeBool"
SchemaTypeFloat = "TypeFloat"
SchemaTypeNumber = "TypeNumber"
SchemaTypeObject = "TypeObject"
)

type ProviderJSON schema.Provider
type ProviderJSON struct {
SDKProvider *sdkschema.Provider
Provider provider.Provider
}

type SchemaJSON struct {
Type string `json:"type,omitempty"`
Expand Down Expand Up @@ -108,7 +115,8 @@ type ProviderSchemaJSON struct {
}

type ProviderWrapper struct {
ProviderName string `json:"provider_name"`
SchemaVersion string `json:"schema_version"`
ProviderSchema *ProviderSchemaJSON `json:"provider_schema,omitempty"`
ProviderName string `json:"provider_name"`
ProviderVersion string `json:"provider_version"`
SchemaVersion string `json:"schema_version"`
ProviderSchema *ProviderSchemaJSON `json:"provider_schema,omitempty"`
}
Loading

0 comments on commit b9aae92

Please sign in to comment.