Skip to content
This repository has been archived by the owner on Dec 30, 2024. It is now read-only.

Commit

Permalink
fix: single nested type (#36)
Browse files Browse the repository at this point in the history
  • Loading branch information
azrod authored Oct 23, 2023
1 parent 958c743 commit 963e3fe
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 46 deletions.
41 changes: 0 additions & 41 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,41 +0,0 @@
# Please set your repository in file:
- .golangci.yml

# Add secret in your Gihub
- GITHUB_TOKEN in dependabot_changelog
- CHANGELOG_PAT in generate_changelog.yml (to Push on main)
- DOC_PAT in page.yml (to generate documentation)

# Show example below:

<div align="center">
<a href="https://github.com/FrangipaneTeam/terraform-plugin-framework-supertype/releases/latest">
<img alt="Latest release" src="https://img.shields.io/github/v/release/FrangipaneTeam/terraform-plugin-framework-supertype?style=for-the-badge&logo=starship&color=C9CBFF&logoColor=D9E0EE&labelColor=302D41&include_prerelease&sort=semver" />
</a>
<a href="https://github.com/FrangipaneTeam/terraform-plugin-framework-supertype/pulse">
<img alt="Last commit" src="https://img.shields.io/github/last-commit/FrangipaneTeam/terraform-plugin-framework-supertype?style=for-the-badge&logo=starship&color=8bd5ca&logoColor=D9E0EE&labelColor=302D41"/>
</a>
<a href="https://github.com/FrangipaneTeam/terraform-plugin-framework-supertype/stargazers">
<img alt="Stars" src="https://img.shields.io/github/stars/FrangipaneTeam/terraform-plugin-framework-supertype?style=for-the-badge&logo=starship&color=c69ff5&logoColor=D9E0EE&labelColor=302D41" />
</a>
<a href="https://github.com/FrangipaneTeam/terraform-plugin-framework-supertype/issues">
<img alt="Issues" src="https://img.shields.io/github/issues/FrangipaneTeam/terraform-plugin-framework-supertype?style=for-the-badge&logo=bilibili&color=F5E0DC&logoColor=D9E0EE&labelColor=302D41" />
</a>
</div>

## terraform-plugin-framework-supertype

supertype is a custom type of Terraform type issue from Terraform schema, like SuperShema it's a meta Objet and function to permit you to manipulate Go object and Terrform object.

This is a try to solve these issues :

* CustomType is defined in the Schema on each Attributes fields on resources and datasources.
* Each kind of Terraform Type is take into account:
* * Simple: String, Bool, Int64, Float64
* * Array: List, Map, Set
* * Nested: ListNested, MapNested, SetNested, SingleNested


### Documentation

For more information about the supertype, please refer to the [documentation](https://github.frangipane.io/terraform/supertype/why).
26 changes: 21 additions & 5 deletions single_nested_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,29 @@ type SingleNestedType struct {
}

func (t SingleNestedType) Equal(o attr.Type) bool {
other, ok := o.(basetypes.ObjectType)
switch o.(type) {
case SingleNestedType:
other, ok := o.(SingleNestedType)
if !ok {
return false
}

if !ok {
return t.ObjectType.Equal(other.ObjectType)
case basetypes.ObjectType:
other, ok := o.(basetypes.ObjectType)
if !ok {
return false
}

return t.ObjectType.Equal(other)
default:
return false
}

return t.ObjectType.Equal(other)
}

func (t SingleNestedType) String() string {
var res strings.Builder
res.WriteString("types.ObjectType[")
res.WriteString("supertypes.SingleNestedType[")
keys := make([]string, 0, len(t.AttrTypes))
for k := range t.AttrTypes {
keys = append(keys, k)
Expand Down Expand Up @@ -80,3 +91,8 @@ func (t SingleNestedType) ValueFromTerraform(ctx context.Context, in tftypes.Val

return value, nil
}

func (t SingleNestedType) ValueType(ctx context.Context) attr.Value {
// SingleNestedValue defined in the value type section
return SingleNestedValue{}
}

0 comments on commit 963e3fe

Please sign in to comment.