Skip to content

Commit

Permalink
fix design import
Browse files Browse the repository at this point in the history
  • Loading branch information
Nishu Goel committed Feb 27, 2024
1 parent 3fa4422 commit 5d76e33
Show file tree
Hide file tree
Showing 19 changed files with 638 additions and 127 deletions.
9 changes: 6 additions & 3 deletions .speakeasy/gen.lock
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
lockVersion: 2.0.0
id: 998a101f-1cb6-4c08-9fd1-b3ee7a1cdeb4
management:
docChecksum: f67b1c543f51ae0de55d5760fa9c3ac8
docChecksum: 768e60427d69fae99d7835102c656810
docVersion: 0.0.1
speakeasyVersion: internal
generationVersion: 2.230.1
releaseVersion: 0.6.6
configChecksum: 136cf59b22046c022c28151c8851bd07
releaseVersion: 0.6.8
configChecksum: aac2033ce474211953e6cb0d2dad78e3
features:
terraform:
core: 3.8.1
globalSecurity: 2.81.2
globalServerURLs: 2.82.1
unions: 2.81.7
generatedFiles:
- internal/sdk/sdk.go
- examples/README.md
Expand Down Expand Up @@ -92,6 +93,8 @@ generatedFiles:
- internal/sdk/pkg/models/shared/getdesignres.go
- internal/sdk/pkg/models/shared/updatedesignreq.go
- internal/sdk/pkg/models/shared/security.go
- internal/provider/type_brand_id.go
- internal/provider/type_custom_theme.go
- internal/provider/type_consumer_data.go
- internal/provider/type_file_data.go
- internal/provider/type_logo_data.go
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ terraform {
required_providers {
epilot-designbuilder = {
source = "epilot-dev/epilot-designbuilder"
version = "0.6.6"
version = "0.6.8"
}
}
}
Expand Down
6 changes: 4 additions & 2 deletions designbuilder.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,9 @@ components:
type: object
properties:
brand_id:
type: string
oneOf:
- type: string
- type: number
brand_name:
type: string
user:
Expand Down Expand Up @@ -384,7 +386,7 @@ components:
type: object
properties:
custom_theme:
type: string
type: object
use_custom_theme:
type: boolean
ConsumerData:
Expand Down
2 changes: 1 addition & 1 deletion examples/provider/provider.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ terraform {
required_providers {
epilot-designbuilder = {
source = "epilot-dev/epilot-designbuilder"
version = "0.6.6"
version = "0.6.8"
}
}
}
Expand Down
2 changes: 0 additions & 2 deletions examples/resources/epilot-designbuilder_design/resource.tf
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
resource "epilot-designbuilder_design" "my_design" {
brand_id = "...my_brand_id..."
brand_name = "...my_brand_name..."
created_at = "2021-01-30T08:30:00Z"
created_by = "...my_created_by..."
custom_theme = "...my_custom_theme..."
edited = true
id = "4d59415d-9b16-41f7-8b78-bf5bc35ca152"
last_modified_at = "...my_last_modified_at..."
Expand Down
2 changes: 1 addition & 1 deletion gen.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ generation:
nameResolutionDec2023: false
telemetryEnabled: false
terraform:
version: 0.6.6
version: 0.6.8
author: epilot-dev
imports:
option: openapi
Expand Down
15 changes: 12 additions & 3 deletions internal/provider/design_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,16 @@ func (r *DesignDataSource) Schema(ctx context.Context, req datasource.SchemaRequ
"design": schema.SingleNestedAttribute{
Computed: true,
Attributes: map[string]schema.Attribute{
"brand_id": schema.StringAttribute{
"brand_id": schema.SingleNestedAttribute{
Computed: true,
Attributes: map[string]schema.Attribute{
"str": schema.StringAttribute{
Computed: true,
},
"number": schema.NumberAttribute{
Computed: true,
},
},
},
"brand_name": schema.StringAttribute{
Computed: true,
Expand All @@ -59,8 +67,9 @@ func (r *DesignDataSource) Schema(ctx context.Context, req datasource.SchemaRequ
"created_by": schema.StringAttribute{
Computed: true,
},
"custom_theme": schema.StringAttribute{
Computed: true,
"custom_theme": schema.SingleNestedAttribute{
Computed: true,
Attributes: map[string]schema.Attribute{},
},
"edited": schema.BoolAttribute{
Computed: true,
Expand Down
23 changes: 21 additions & 2 deletions internal/provider/design_data_source_sdk.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,37 @@ import (
"encoding/json"
"github.com/epilot-dev/terraform-provider-epilot-designbuilder/internal/sdk/pkg/models/shared"
"github.com/hashicorp/terraform-plugin-framework/types"
"math/big"
)

func (r *DesignDataSourceModel) RefreshFromSharedGetDesignRes(resp *shared.GetDesignRes) {
if resp.Design == nil {
r.Design = nil
} else {
r.Design = &GetDesignResDesign{}
r.Design.BrandID = types.StringPointerValue(resp.Design.BrandID)
if resp.Design.BrandID == nil {
r.Design.BrandID = nil
} else {
r.Design.BrandID = &BrandID{}
if resp.Design.BrandID.Str != nil {
r.Design.BrandID.Str = types.StringPointerValue(resp.Design.BrandID.Str)
}
if resp.Design.BrandID.Number != nil {
if resp.Design.BrandID.Number != nil {
r.Design.BrandID.Number = types.NumberValue(big.NewFloat(float64(*resp.Design.BrandID.Number)))
} else {
r.Design.BrandID.Number = types.NumberNull()
}
}
}
r.Design.BrandName = types.StringPointerValue(resp.Design.BrandName)
r.Design.CreatedAt = types.StringPointerValue(resp.Design.CreatedAt)
r.Design.CreatedBy = types.StringPointerValue(resp.Design.CreatedBy)
r.Design.CustomTheme = types.StringPointerValue(resp.Design.CustomTheme)
if resp.Design.CustomTheme == nil {
r.Design.CustomTheme = nil
} else {
r.Design.CustomTheme = &CustomTheme{}
}
r.Design.Edited = types.BoolValue(resp.Design.Edited)
r.Design.ID = types.StringPointerValue(resp.Design.ID)
r.Design.LastModifiedAt = types.StringPointerValue(resp.Design.LastModifiedAt)
Expand Down
66 changes: 52 additions & 14 deletions internal/provider/design_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"fmt"
speakeasy_boolplanmodifier "github.com/epilot-dev/terraform-provider-epilot-designbuilder/internal/planmodifiers/boolplanmodifier"
speakeasy_listplanmodifier "github.com/epilot-dev/terraform-provider-epilot-designbuilder/internal/planmodifiers/listplanmodifier"
speakeasy_numberplanmodifier "github.com/epilot-dev/terraform-provider-epilot-designbuilder/internal/planmodifiers/numberplanmodifier"
speakeasy_objectplanmodifier "github.com/epilot-dev/terraform-provider-epilot-designbuilder/internal/planmodifiers/objectplanmodifier"
speakeasy_stringplanmodifier "github.com/epilot-dev/terraform-provider-epilot-designbuilder/internal/planmodifiers/stringplanmodifier"
"github.com/epilot-dev/terraform-provider-epilot-designbuilder/internal/sdk"
Expand All @@ -21,6 +22,7 @@ import (
"github.com/hashicorp/terraform-plugin-framework/resource/schema"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/boolplanmodifier"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/listplanmodifier"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/numberplanmodifier"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/objectplanmodifier"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier"
Expand All @@ -44,11 +46,11 @@ type DesignResource struct {

// DesignResourceModel describes the resource data model.
type DesignResourceModel struct {
BrandID types.String `tfsdk:"brand_id"`
BrandID *BrandID `tfsdk:"brand_id"`
BrandName types.String `tfsdk:"brand_name"`
CreatedAt types.String `tfsdk:"created_at"`
CreatedBy types.String `tfsdk:"created_by"`
CustomTheme types.String `tfsdk:"custom_theme"`
CustomTheme *CustomTheme `tfsdk:"custom_theme"`
Design *GetDesignResDesign `tfsdk:"design"`
Edited types.Bool `tfsdk:"edited"`
ID types.String `tfsdk:"id"`
Expand All @@ -68,14 +70,37 @@ func (r *DesignResource) Schema(ctx context.Context, req resource.SchemaRequest,
MarkdownDescription: "Design Resource",

Attributes: map[string]schema.Attribute{
"brand_id": schema.StringAttribute{
"brand_id": schema.SingleNestedAttribute{
Computed: true,
PlanModifiers: []planmodifier.String{
stringplanmodifier.RequiresReplaceIfConfigured(),
speakeasy_stringplanmodifier.SuppressDiff(speakeasy_stringplanmodifier.ExplicitSuppress),
PlanModifiers: []planmodifier.Object{
objectplanmodifier.RequiresReplaceIfConfigured(),
speakeasy_objectplanmodifier.SuppressDiff(speakeasy_objectplanmodifier.ExplicitSuppress),
},
Optional: true,
Attributes: map[string]schema.Attribute{
"str": schema.StringAttribute{
Computed: true,
PlanModifiers: []planmodifier.String{
stringplanmodifier.RequiresReplaceIfConfigured(),
speakeasy_stringplanmodifier.SuppressDiff(speakeasy_stringplanmodifier.ExplicitSuppress),
},
Optional: true,
Description: `Requires replacement if changed. `,
},
"number": schema.NumberAttribute{
Computed: true,
PlanModifiers: []planmodifier.Number{
numberplanmodifier.RequiresReplaceIfConfigured(),
speakeasy_numberplanmodifier.SuppressDiff(speakeasy_numberplanmodifier.ExplicitSuppress),
},
Optional: true,
Description: `Requires replacement if changed. `,
},
},
Optional: true,
Description: `Requires replacement if changed. `,
Validators: []validator.Object{
validators.ExactlyOneChild(),
},
},
"brand_name": schema.StringAttribute{
Computed: true,
Expand Down Expand Up @@ -104,20 +129,32 @@ func (r *DesignResource) Schema(ctx context.Context, req resource.SchemaRequest,
Optional: true,
Description: `Requires replacement if changed. `,
},
"custom_theme": schema.StringAttribute{
"custom_theme": schema.SingleNestedAttribute{
Computed: true,
PlanModifiers: []planmodifier.String{
stringplanmodifier.RequiresReplaceIfConfigured(),
speakeasy_stringplanmodifier.SuppressDiff(speakeasy_stringplanmodifier.ExplicitSuppress),
PlanModifiers: []planmodifier.Object{
objectplanmodifier.RequiresReplaceIfConfigured(),
speakeasy_objectplanmodifier.SuppressDiff(speakeasy_objectplanmodifier.ExplicitSuppress),
},
Optional: true,
Attributes: map[string]schema.Attribute{},
Description: `Requires replacement if changed. `,
},
"design": schema.SingleNestedAttribute{
Computed: true,
Attributes: map[string]schema.Attribute{
"brand_id": schema.StringAttribute{
"brand_id": schema.SingleNestedAttribute{
Computed: true,
Attributes: map[string]schema.Attribute{
"str": schema.StringAttribute{
Computed: true,
},
"number": schema.NumberAttribute{
Computed: true,
},
},
Validators: []validator.Object{
validators.ExactlyOneChild(),
},
},
"brand_name": schema.StringAttribute{
Computed: true,
Expand All @@ -129,8 +166,9 @@ func (r *DesignResource) Schema(ctx context.Context, req resource.SchemaRequest,
"created_by": schema.StringAttribute{
Computed: true,
},
"custom_theme": schema.StringAttribute{
Computed: true,
"custom_theme": schema.SingleNestedAttribute{
Computed: true,
Attributes: map[string]schema.Attribute{},
},
"edited": schema.BoolAttribute{
Computed: true,
Expand Down
Loading

0 comments on commit 5d76e33

Please sign in to comment.