This repository has been archived by the owner on Dec 30, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: add map and mapNested * ci(generate): changes by go generate * ci: remove unused CI to avoid error --------- Co-authored-by: gaetanars <gaetanars@users.noreply.github.com>
- Loading branch information
Showing
4 changed files
with
233 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
// code generated by go generate - look at type_attribute.go.tmpl for source file | ||
package superschema | ||
|
||
import ( | ||
"context" | ||
|
||
schemaD "github.com/hashicorp/terraform-plugin-framework/datasource/schema" | ||
schemaR "github.com/hashicorp/terraform-plugin-framework/resource/schema" | ||
) | ||
|
||
var _ Attribute = MapAttribute{} | ||
|
||
type MapAttribute struct { | ||
Common *schemaR.MapAttribute | ||
Resource *schemaR.MapAttribute | ||
DataSource *schemaD.MapAttribute | ||
} | ||
|
||
// IsResource returns true if the attribute is a resource attribute. | ||
func (s MapAttribute) IsResource() bool { | ||
return s.Resource != nil || s.Common != nil | ||
} | ||
|
||
// IsDataSource returns true if the attribute is a data source attribute. | ||
func (s MapAttribute) IsDataSource() bool { | ||
return s.DataSource != nil || s.Common != nil | ||
} | ||
|
||
//nolint:dupl | ||
func (s MapAttribute) GetResource(ctx context.Context) schemaR.Attribute { | ||
var ( | ||
common schemaR.MapAttribute | ||
resource schemaR.MapAttribute | ||
) | ||
|
||
if s.Common != nil { | ||
common = *s.Common | ||
} | ||
|
||
if s.Resource != nil { | ||
resource = *s.Resource | ||
} | ||
|
||
a := schemaR.MapAttribute{ | ||
Required: computeIsRequired(common, resource), | ||
Optional: computeIsOptional(common, resource), | ||
Computed: computeIsComputed(common, resource), | ||
Sensitive: computeIsSensitive(common, resource), | ||
MarkdownDescription: computeMarkdownDescription(common, resource), | ||
Description: computeDescription(common, resource), | ||
DeprecationMessage: computeDeprecationMessage(common, resource), | ||
ElementType: common.ElementType, | ||
} | ||
|
||
if s.Resource != nil { | ||
if s.Resource.ElementType != nil { | ||
a.ElementType = s.Resource.ElementType | ||
} | ||
} | ||
|
||
a.Validators = append(a.Validators, common.Validators...) | ||
a.Validators = append(a.Validators, resource.Validators...) | ||
a.PlanModifiers = append(a.PlanModifiers, common.PlanModifiers...) | ||
a.PlanModifiers = append(a.PlanModifiers, resource.PlanModifiers...) | ||
|
||
defaultVDescription := "" | ||
if s.Resource != nil { | ||
if s.Resource.Default != nil { | ||
a.Default = s.Resource.Default | ||
defaultVDescription = s.Resource.Default.MarkdownDescription(ctx) | ||
} | ||
} | ||
|
||
a.MarkdownDescription = genResourceAttrDescription(ctx, a.MarkdownDescription, defaultVDescription, a.Validators, a.PlanModifiers) | ||
return a | ||
} | ||
|
||
//nolint:dupl | ||
func (s MapAttribute) GetDataSource(ctx context.Context) schemaD.Attribute { | ||
var ( | ||
common schemaR.MapAttribute | ||
dataSource schemaD.MapAttribute | ||
) | ||
|
||
if s.Common != nil { | ||
common = *s.Common | ||
} | ||
|
||
if s.DataSource != nil { | ||
dataSource = *s.DataSource | ||
} | ||
|
||
a := schemaD.MapAttribute{ | ||
Required: computeIsRequired(common, dataSource), | ||
Optional: computeIsOptional(common, dataSource), | ||
Computed: computeIsComputed(common, dataSource), | ||
Sensitive: computeIsSensitive(common, dataSource), | ||
MarkdownDescription: computeMarkdownDescription(common, dataSource), | ||
Description: computeDescription(common, dataSource), | ||
DeprecationMessage: computeDeprecationMessage(common, dataSource), | ||
ElementType: common.ElementType, | ||
} | ||
|
||
if s.DataSource != nil { | ||
if s.DataSource.ElementType != nil { | ||
a.ElementType = s.DataSource.ElementType | ||
} | ||
} | ||
|
||
a.Validators = append(a.Validators, common.Validators...) | ||
a.Validators = append(a.Validators, dataSource.Validators...) | ||
|
||
a.MarkdownDescription = genDataSourceAttrDescription(ctx, a.MarkdownDescription, a.Validators) | ||
|
||
return a | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
// code generated by go generate - look at type_attribute.go.tmpl for source file | ||
package superschema | ||
|
||
import ( | ||
"context" | ||
|
||
schemaD "github.com/hashicorp/terraform-plugin-framework/datasource/schema" | ||
schemaR "github.com/hashicorp/terraform-plugin-framework/resource/schema" | ||
) | ||
|
||
var _ Attribute = MapNestedAttribute{} | ||
|
||
type MapNestedAttribute struct { | ||
Common *schemaR.MapNestedAttribute | ||
Resource *schemaR.MapNestedAttribute | ||
DataSource *schemaD.MapNestedAttribute | ||
Attributes Attributes | ||
} | ||
|
||
// IsResource returns true if the attribute is a resource attribute. | ||
func (s MapNestedAttribute) IsResource() bool { | ||
return s.Resource != nil || s.Common != nil | ||
} | ||
|
||
// IsDataSource returns true if the attribute is a data source attribute. | ||
func (s MapNestedAttribute) IsDataSource() bool { | ||
return s.DataSource != nil || s.Common != nil | ||
} | ||
|
||
//nolint:dupl | ||
func (s MapNestedAttribute) GetResource(ctx context.Context) schemaR.Attribute { | ||
var ( | ||
common schemaR.MapNestedAttribute | ||
resource schemaR.MapNestedAttribute | ||
) | ||
|
||
if s.Common != nil { | ||
common = *s.Common | ||
} | ||
|
||
if s.Resource != nil { | ||
resource = *s.Resource | ||
} | ||
|
||
a := schemaR.MapNestedAttribute{ | ||
Required: computeIsRequired(common, resource), | ||
Optional: computeIsOptional(common, resource), | ||
Computed: computeIsComputed(common, resource), | ||
Sensitive: computeIsSensitive(common, resource), | ||
MarkdownDescription: computeMarkdownDescription(common, resource), | ||
Description: computeDescription(common, resource), | ||
DeprecationMessage: computeDeprecationMessage(common, resource), | ||
NestedObject: schemaR.NestedAttributeObject{ | ||
Attributes: s.Attributes.process(ctx, resourceT).(map[string]schemaR.Attribute), | ||
}, | ||
} | ||
|
||
a.Validators = append(a.Validators, common.Validators...) | ||
a.Validators = append(a.Validators, resource.Validators...) | ||
a.PlanModifiers = append(a.PlanModifiers, common.PlanModifiers...) | ||
a.PlanModifiers = append(a.PlanModifiers, resource.PlanModifiers...) | ||
|
||
defaultVDescription := "" | ||
if s.Resource != nil { | ||
if s.Resource.Default != nil { | ||
a.Default = s.Resource.Default | ||
defaultVDescription = s.Resource.Default.MarkdownDescription(ctx) | ||
} | ||
} | ||
|
||
a.MarkdownDescription = genResourceAttrDescription(ctx, a.MarkdownDescription, defaultVDescription, a.Validators, a.PlanModifiers) | ||
return a | ||
} | ||
|
||
//nolint:dupl | ||
func (s MapNestedAttribute) GetDataSource(ctx context.Context) schemaD.Attribute { | ||
var ( | ||
common schemaR.MapNestedAttribute | ||
dataSource schemaD.MapNestedAttribute | ||
) | ||
|
||
if s.Common != nil { | ||
common = *s.Common | ||
} | ||
|
||
if s.DataSource != nil { | ||
dataSource = *s.DataSource | ||
} | ||
|
||
a := schemaD.MapNestedAttribute{ | ||
Required: computeIsRequired(common, dataSource), | ||
Optional: computeIsOptional(common, dataSource), | ||
Computed: computeIsComputed(common, dataSource), | ||
Sensitive: computeIsSensitive(common, dataSource), | ||
MarkdownDescription: computeMarkdownDescription(common, dataSource), | ||
Description: computeDescription(common, dataSource), | ||
DeprecationMessage: computeDeprecationMessage(common, dataSource), | ||
NestedObject: schemaD.NestedAttributeObject{ | ||
Attributes: s.Attributes.process(ctx, dataSourceT).(map[string]schemaD.Attribute), | ||
}, | ||
} | ||
|
||
a.Validators = append(a.Validators, common.Validators...) | ||
a.Validators = append(a.Validators, dataSource.Validators...) | ||
|
||
a.MarkdownDescription = genDataSourceAttrDescription(ctx, a.MarkdownDescription, a.Validators) | ||
|
||
return a | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters