Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove attribute and block schema templates #99

Merged
merged 42 commits into from
Jan 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
b5cb6d2
Replace datasource_convert pkg with constructors
bendbennett Nov 30, 2023
402d687
Renaming datasource_generate pkg to datasource
bendbennett Nov 30, 2023
375dfe1
Reusing predefined functions
bendbennett Nov 30, 2023
a190703
Switching to using constructor functions for provider generator types
bendbennett Dec 1, 2023
0cad168
Moving provider_generate package to provider
bendbennett Dec 1, 2023
3bda0ed
Switching to using constructor functions for resource generator types
bendbennett Dec 1, 2023
1da1a67
Linting and copyright headers
bendbennett Dec 1, 2023
6f486d7
Remove bool attribute template and bool framework schema attribute
bendbennett Dec 2, 2023
52adb5a
Move handling of schema CustomTye to AttributeType
bendbennett Dec 3, 2023
d6c28a2
Add copyright headers
bendbennett Dec 3, 2023
1143e38
Merge remote-tracking branch 'origin/main' into remove-schema-templates
bendbennett Dec 14, 2023
f6b835f
Remove unused constructor and file
bendbennett Dec 14, 2023
d84c613
Refactoring resource bool attribute
bendbennett Dec 19, 2023
7144b36
Merge remote-tracking branch 'origin/main' into remove-schema-templates
bendbennett Dec 19, 2023
4cc865d
Merge remote-tracking branch 'origin/main' into remove-schema-templates
bendbennett Dec 21, 2023
0279b7d
Refactoring datasource list attribute
bendbennett Dec 21, 2023
52f1907
Renaming AttributeType to CustomTypePrimitive
bendbennett Dec 21, 2023
e81f7cd
Refactor datasource object attribute
bendbennett Dec 22, 2023
ae46d43
Refactor datasource single nested attribute
bendbennett Dec 23, 2023
68745d0
Refactor datasource list nested attribute
bendbennett Dec 28, 2023
d48b834
Refactor datasource float64, int64, number, and string sttributes
bendbennett Dec 28, 2023
93f206e
Refactor datasource map, and set attributes
bendbennett Dec 28, 2023
ce5872c
Refactor datasource map nested, and set nested attributes
bendbennett Dec 28, 2023
46a4186
Refactor datasource list nested block
bendbennett Dec 30, 2023
691cbf5
Refactor datasource set nested block
bendbennett Dec 30, 2023
ccf8045
Refactor datasource single nested block
bendbennett Dec 30, 2023
05d76a4
Removing unused interfaces
bendbennett Dec 30, 2023
eb3583e
Refactoring custom type collection, object, and primitive
bendbennett Dec 31, 2023
3d28b33
Refactoring provider attributes and blocks
bendbennett Jan 1, 2024
581644f
Refactoring resource float64, int64, number and string attributes
bendbennett Jan 1, 2024
a7f0614
Refactoring resource list attribute
bendbennett Jan 4, 2024
ed51a91
Uodating to latest version of spec
bendbennett Jan 4, 2024
467d607
Refactoring resource map and list attributes
bendbennett Jan 5, 2024
5f09e3d
Refactoring resource object attribute
bendbennett Jan 5, 2024
74f4718
Refactoring resource list nested attribute
bendbennett Jan 6, 2024
1e4ac74
Refactoring resource map and set nested attributes
bendbennett Jan 6, 2024
14aaf5c
Removing top-level associated external type from list, map, set neste…
bendbennett Jan 6, 2024
58eca87
Refactoring resource single nested attribute
bendbennett Jan 6, 2024
6f67e12
Refactoring resource list nested block
bendbennett Jan 6, 2024
60c6001
Refactoring resource set nested block
bendbennett Jan 7, 2024
77f4690
Refactoring resource single nested block
bendbennett Jan 7, 2024
a873aa9
Merge branch 'main' into remove-schema-templates
bendbennett Jan 9, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ go 1.21
require (
github.com/google/go-cmp v0.6.0
github.com/hashicorp/cli v1.1.6
github.com/hashicorp/terraform-plugin-codegen-spec v0.1.1-0.20231024091233-c659ac8a54fc
github.com/hashicorp/terraform-plugin-codegen-spec v0.1.1-0.20240104173918-8a979efa31b3
github.com/hashicorp/terraform-plugin-framework v1.4.2
github.com/hashicorp/terraform-plugin-go v0.19.0
github.com/mattn/go-colorable v0.1.13
)

Expand All @@ -21,7 +22,6 @@ require (
github.com/hashicorp/errwrap v1.1.0 // indirect
github.com/hashicorp/go-hclog v1.5.0 // indirect
github.com/hashicorp/go-multierror v1.1.1 // indirect
github.com/hashicorp/terraform-plugin-go v0.19.0 // indirect
github.com/hashicorp/terraform-plugin-log v0.9.0 // indirect
github.com/huandu/xstrings v1.4.0 // indirect
github.com/imdario/mergo v0.3.16 // indirect
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ github.com/hashicorp/go-hclog v1.5.0/go.mod h1:W4Qnvbt70Wk/zYJryRzDRU/4r0kIg0PVH
github.com/hashicorp/go-multierror v1.0.0/go.mod h1:dHtQlpGsu+cZNNAkkCN/P3hoUDHhCYQXV3UM06sGGrk=
github.com/hashicorp/go-multierror v1.1.1 h1:H5DkEtf6CXdFp0N0Em5UCwQpXMWke8IA0+lD48awMYo=
github.com/hashicorp/go-multierror v1.1.1/go.mod h1:iw975J/qwKPdAO1clOe2L8331t/9/fmwbPZ6JB6eMoM=
github.com/hashicorp/terraform-plugin-codegen-spec v0.1.1-0.20231024091233-c659ac8a54fc h1:VmMk5vOSJgpWOuBsI4ZBZkcsrkLq0fKoyKvKFnbBuxk=
github.com/hashicorp/terraform-plugin-codegen-spec v0.1.1-0.20231024091233-c659ac8a54fc/go.mod h1:PQn6bDD8UWoAVJoHXqFk2i/RmLbeQBjbiP38i+E+YIw=
github.com/hashicorp/terraform-plugin-codegen-spec v0.1.1-0.20240104173918-8a979efa31b3 h1:2yq1HJPw4LpV/vIm++wcCYZfbNGQftwVWIv/FAAxHZ4=
github.com/hashicorp/terraform-plugin-codegen-spec v0.1.1-0.20240104173918-8a979efa31b3/go.mod h1:PQn6bDD8UWoAVJoHXqFk2i/RmLbeQBjbiP38i+E+YIw=
github.com/hashicorp/terraform-plugin-framework v1.4.2 h1:P7a7VP1GZbjc4rv921Xy5OckzhoiO3ig6SGxwelD2sI=
github.com/hashicorp/terraform-plugin-framework v1.4.2/go.mod h1:GWl3InPFZi2wVQmdVnINPKys09s9mLmTZr95/ngLnbY=
github.com/hashicorp/terraform-plugin-go v0.19.0 h1:BuZx/6Cp+lkmiG0cOBk6Zps0Cb2tmqQpDM3iAtnhDQU=
Expand Down
62 changes: 62 additions & 0 deletions internal/convert/computed_optional_required.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0

package convert

import (
"bytes"

specschema "github.com/hashicorp/terraform-plugin-codegen-spec/schema"
)

type ComputedOptionalRequired struct {
computedOptionalRequired specschema.ComputedOptionalRequired
}

func NewComputedOptionalRequired(c specschema.ComputedOptionalRequired) ComputedOptionalRequired {
return ComputedOptionalRequired{
computedOptionalRequired: c,
}
}

func (c ComputedOptionalRequired) Equal(other ComputedOptionalRequired) bool {
return c.computedOptionalRequired.Equal(other.computedOptionalRequired)
}

func (c ComputedOptionalRequired) IsComputed() bool {
if c.computedOptionalRequired == specschema.Computed || c.computedOptionalRequired == specschema.ComputedOptional {
return true
}

return false
}

func (c ComputedOptionalRequired) IsOptional() bool {
if c.computedOptionalRequired == specschema.Optional || c.computedOptionalRequired == specschema.ComputedOptional {
return true
}

return false
}

func (c ComputedOptionalRequired) IsRequired() bool {
return c.computedOptionalRequired == specschema.Required
}

func (c ComputedOptionalRequired) Schema() []byte {
var b bytes.Buffer

if c.IsRequired() {
b.WriteString("Required: true,\n")
}

if c.IsOptional() {
b.WriteString("Optional: true,\n")
}

if c.IsComputed() {
b.WriteString("Computed: true,\n")
}

return b.Bytes()
}
108 changes: 0 additions & 108 deletions internal/convert/convert.go

This file was deleted.

88 changes: 88 additions & 0 deletions internal/convert/custom_type_collection.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0

package convert

import (
"fmt"

specschema "github.com/hashicorp/terraform-plugin-codegen-spec/schema"

"github.com/hashicorp/terraform-plugin-codegen-framework/internal/format"
)

const (
CustomCollectionTypeList CustomCollectionTypes = "List"
CustomCollectionTypeMap CustomCollectionTypes = "Map"
CustomCollectionTypeSet CustomCollectionTypes = "Set"
)

type CustomCollectionTypes string

func (c CustomCollectionTypes) Equal(other CustomCollectionTypes) bool {
return c == other
}

type CustomTypeCollection struct {
associatedExternalType *specschema.AssociatedExternalType
customCollectionType CustomCollectionTypes
customType *specschema.CustomType
elementType string
name string
}

// NewCustomTypeCollection constructs an CustomTypeCollection which is used to determine whether a CustomType
// should be assigned to a collection attribute in the schema.
//
// If a CustomType has been declared in the spec, then the CustomType.Type will be used as
// the CustomType in the schema.
//
// If the spec CustomType is nil, and the spec AssociatedExternalType is not nil, the generator
// will create custom Type and Value types using the attribute name, and the generated custom
// Type type will be used as the CustomType in the schema.
func NewCustomTypeCollection(c *specschema.CustomType, a *specschema.AssociatedExternalType, cct CustomCollectionTypes, elemType, name string) CustomTypeCollection {
return CustomTypeCollection{
associatedExternalType: a,
customCollectionType: cct,
customType: c,
elementType: elemType,
name: name,
}
}

func (c CustomTypeCollection) Equal(other CustomTypeCollection) bool {
if !c.associatedExternalType.Equal(other.associatedExternalType) {
return false
}

if !c.customCollectionType.Equal(other.customCollectionType) {
return false
}

if !c.customType.Equal(other.customType) {
return false
}

if c.elementType != other.elementType {
return false
}

return c.name == other.name
}

func (c CustomTypeCollection) Schema() []byte {
var customType string

switch {
case c.customType != nil:
customType = c.customType.Type
case c.associatedExternalType != nil:
customType = fmt.Sprintf("%sType{\ntypes.%sType{\nElemType: %s,\n},\n}", format.ToPascalCase(c.name), c.customCollectionType, c.elementType)
}

if customType != "" {
return []byte(fmt.Sprintf("CustomType: %s,\n", customType))
}

return nil
}
40 changes: 40 additions & 0 deletions internal/convert/custom_type_nested_collection.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0

package convert

import (
"fmt"

specschema "github.com/hashicorp/terraform-plugin-codegen-spec/schema"
)

type CustomTypeNestedCollection struct {
customType *specschema.CustomType
}

// NewCustomTypeNestedCollection constructs an CustomTypeNestedCollection which is used to determine whether a CustomType
// should be assigned to a nested attribute in the schema.
//
// If a CustomType has been declared in the spec, then the CustomType.Type will be used as
// the CustomType in the schema.
//
// If the spec CustomType is nil, the generator will create custom Type and Value types using the attribute
// name, and the generated custom Type type will be used as the CustomType in the schema.
func NewCustomTypeNestedCollection(c *specschema.CustomType) CustomTypeNestedCollection {
return CustomTypeNestedCollection{
customType: c,
}
}

func (a CustomTypeNestedCollection) Equal(other CustomTypeNestedCollection) bool {
return a.customType.Equal(other.customType)
}

func (a CustomTypeNestedCollection) Schema() []byte {
if a.customType != nil && a.customType.Type != "" {
return []byte(fmt.Sprintf("CustomType: %s,\n", a.customType.Type))
}

return nil
}
57 changes: 57 additions & 0 deletions internal/convert/custom_type_nested_object.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0

package convert

import (
"fmt"

specschema "github.com/hashicorp/terraform-plugin-codegen-spec/schema"

"github.com/hashicorp/terraform-plugin-codegen-framework/internal/format"
)

type CustomTypeNestedObject struct {
customType *specschema.CustomType
name string
}

// NewCustomTypeNestedObject constructs an CustomTypeNestedObject which is used to determine whether a CustomType
// should be assigned to a nested attribute object in the schema.
//
// If a CustomType has been declared in the spec, then the CustomType.Type will be used as
// the CustomType in the schema.
//
// If the spec CustomType is nil, the generator will create custom Type and Value types using the attribute
// name, and the generated custom Type type will be used as the CustomType in the schema.
func NewCustomTypeNestedObject(c *specschema.CustomType, name string) CustomTypeNestedObject {
return CustomTypeNestedObject{
customType: c,
name: name,
}
}

func (c CustomTypeNestedObject) Equal(other CustomTypeNestedObject) bool {
if !c.customType.Equal(other.customType) {
return false
}

return c.name == other.name
}

func (c CustomTypeNestedObject) Schema() []byte {
var customTypeType string

switch {
case c.customType != nil:
customTypeType = c.customType.Type
default:
customTypeType = fmt.Sprintf("%sType{\nObjectType: types.ObjectType{\nAttrTypes: %sValue{}.AttributeTypes(ctx),\n},\n}", format.ToPascalCase(c.name), format.ToPascalCase(c.name))
}

if customTypeType != "" {
return []byte(fmt.Sprintf("CustomType: %s,\n", customTypeType))
}

return nil
}
Loading
Loading