diff --git a/.speakeasy/gen.lock b/.speakeasy/gen.lock index e6994be..a092270 100644 --- a/.speakeasy/gen.lock +++ b/.speakeasy/gen.lock @@ -1,12 +1,12 @@ lockVersion: 2.0.0 id: 45f3018a-30de-4d91-ab55-1ad3f43bb6de management: - docChecksum: 6c94ad8e3e080570f4cc4e7acc8299f5 + docChecksum: b2a8ea3da2c0564f2ac23b47baa1503a docVersion: 1.0.0 speakeasyVersion: 1.405.9 generationVersion: 2.429.0 - releaseVersion: 1.0.1 - configChecksum: eaad5d2fe7a3aa72234da152f45e42e0 + releaseVersion: 1.0.2 + configChecksum: 8385635e0dd549d2a448fcb26d4b9605 features: terraform: additionalDependencies: 0.1.0 @@ -56,7 +56,6 @@ generatedFiles: - internal/provider/reflect/primitive.go - internal/provider/reflect/slice.go - internal/provider/reflect/struct.go - - internal/provider/types/config.go - internal/provider/utils.go - internal/sdk/.gitattributes - internal/sdk/.gitignore diff --git a/README.md b/README.md index 0906f9f..3a6f9ef 100644 --- a/README.md +++ b/README.md @@ -42,7 +42,7 @@ terraform { required_providers { epilot-custom-variable = { source = "epilot-dev/epilot-custom-variable" - version = "1.0.1" + version = "1.0.2" } } } diff --git a/docs/data-sources/custom_variable.md b/docs/data-sources/custom_variable.md index bd01bb8..9b1db09 100644 --- a/docs/data-sources/custom_variable.md +++ b/docs/data-sources/custom_variable.md @@ -27,7 +27,7 @@ data "epilot-custom-variable_custom_variable" "my_customvariable" { ### Read-Only -- `config` (Attributes) Variable configuration (see [below for nested schema](#nestedatt--config)) +- `config` (String) Parsed as JSON. - `created_at` (String) Creation time - `created_by` (String) Created by - `helper_logic` (String) The helper function logic @@ -39,6 +39,3 @@ data "epilot-custom-variable_custom_variable" "my_customvariable" { - `type` (String) Custom variable type - `updated_at` (String) Last update time - `updated_by` (String) Updated by - - -### Nested Schema for `config` diff --git a/docs/index.md b/docs/index.md index dded641..364abf9 100644 --- a/docs/index.md +++ b/docs/index.md @@ -17,7 +17,7 @@ terraform { required_providers { epilot-custom-variable = { source = "epilot-dev/epilot-custom-variable" - version = "1.0.0" + version = "1.0.2" } } } diff --git a/docs/resources/custom_variable.md b/docs/resources/custom_variable.md index b4c7263..7e57278 100644 --- a/docs/resources/custom_variable.md +++ b/docs/resources/custom_variable.md @@ -14,9 +14,7 @@ CustomVariable Resource ```terraform resource "epilot-custom-variable_custom_variable" "my_customvariable" { - config = { - # ... - } + config = "{ \"see\": \"documentation\" }" created_at = "2022-04-19T12:41:43.662Z" created_by = 100042 helper_logic = "return param1 * param2;" @@ -41,7 +39,7 @@ resource "epilot-custom-variable_custom_variable" "my_customvariable" { ### Optional -- `config` (Attributes) Variable configuration. Requires replacement if changed. (see [below for nested schema](#nestedatt--config)) +- `config` (String) Requires replacement if changed.; Parsed as JSON. - `created_at` (String) Creation time. Requires replacement if changed. - `created_by` (String) Created by. Requires replacement if changed. - `helper_logic` (String) The helper function logic. Requires replacement if changed. @@ -55,9 +53,6 @@ resource "epilot-custom-variable_custom_variable" "my_customvariable" { - `updated_at` (String) Last update time. Requires replacement if changed. - `updated_by` (String) Updated by. Requires replacement if changed. - -### Nested Schema for `config` - ## Import Import is supported using the following syntax: diff --git a/examples/provider/provider.tf b/examples/provider/provider.tf index bcac82c..b3f06e8 100644 --- a/examples/provider/provider.tf +++ b/examples/provider/provider.tf @@ -2,7 +2,7 @@ terraform { required_providers { epilot-custom-variable = { source = "epilot-dev/epilot-custom-variable" - version = "1.0.1" + version = "1.0.2" } } } diff --git a/examples/resources/epilot-custom-variable_custom_variable/resource.tf b/examples/resources/epilot-custom-variable_custom_variable/resource.tf index cfef26f..b3f9b01 100644 --- a/examples/resources/epilot-custom-variable_custom_variable/resource.tf +++ b/examples/resources/epilot-custom-variable_custom_variable/resource.tf @@ -1,7 +1,5 @@ resource "epilot-custom-variable_custom_variable" "my_customvariable" { - config = { - # ... - } + config = "{ \"see\": \"documentation\" }" created_at = "2022-04-19T12:41:43.662Z" created_by = 100042 helper_logic = "return param1 * param2;" diff --git a/examples/tests/provider.tf b/examples/tests/provider.tf deleted file mode 100644 index 1d13b74..0000000 --- a/examples/tests/provider.tf +++ /dev/null @@ -1,26 +0,0 @@ -terraform { - required_providers { - epilot-custom-variable = { - source = "epilot-dev/epilot-custom-variable" - version = "1.0.0" - } - } -} - -variable "epilot_auth" { - type = string -} -variable "custom_variables_api_url" { - type = string - default = "https://template-variables-api.dev.sls.epilot.io" -} - -provider "epilot-custom-variable" { - epilot_auth = var.epilot_auth - server_url = var.custom_variables_api_url -} - -# import { -# to = epilot-custom-variable_custom_variable.my_variable -# id = "25bad807-bf36-4ce4-8aca-27b6420597ac" -# } \ No newline at end of file diff --git a/examples/tests/variables.tf b/examples/tests/variables.tf deleted file mode 100644 index b6e4acb..0000000 --- a/examples/tests/variables.tf +++ /dev/null @@ -1,15 +0,0 @@ -# __generated__ by Terraform -# Please review these resources and move them into your main configuration files. - -# __generated__ by Terraform from "25bad807-bf36-4ce4-8aca-27b6420597ac" -resource "epilot-custom-variable_custom_variable" "my_variable" { - config = { - } - helper_logic = null - helper_params = [] - key = "test_manifest_3" - name = "test manifest 3" - tags = [] - template = "Hello, world!" - type = "custom" -} diff --git a/final.yaml b/final.yaml index b5ae009..7b72f8d 100644 --- a/final.yaml +++ b/final.yaml @@ -560,11 +560,6 @@ components: type: string description: The helper function logic example: return param1 * param2; - config: - type: object - description: Variable configuration - example: - $ref: "#/components/examples/TableConfig/value" template: type: string description: Handlebar template that used to generate the variable content @@ -691,6 +686,7 @@ components: type: string description: Updated by example: 100042 + config: {} examples: ExampleMain: value: diff --git a/gen.yaml b/gen.yaml index 7076e2b..1735c0f 100644 --- a/gen.yaml +++ b/gen.yaml @@ -30,7 +30,7 @@ go: outputModelSuffix: output packageName: openapi terraform: - version: 1.0.1 + version: 1.0.2 additionalDataSources: [] additionalDependencies: {} additionalResources: [] diff --git a/internal/provider/customvariable_data_source.go b/internal/provider/customvariable_data_source.go index 3d59d53..a56569c 100644 --- a/internal/provider/customvariable_data_source.go +++ b/internal/provider/customvariable_data_source.go @@ -5,7 +5,6 @@ package provider import ( "context" "fmt" - tfTypes "github.com/epilot-dev/terraform-provider-epilot-custom-variable/internal/provider/types" "github.com/epilot-dev/terraform-provider-epilot-custom-variable/internal/sdk" "github.com/epilot-dev/terraform-provider-epilot-custom-variable/internal/sdk/models/operations" "github.com/hashicorp/terraform-plugin-framework/datasource" @@ -29,19 +28,19 @@ type CustomVariableDataSource struct { // CustomVariableDataSourceModel describes the data model. type CustomVariableDataSourceModel struct { - Config *tfTypes.Config `tfsdk:"config"` - CreatedAt types.String `tfsdk:"created_at"` - CreatedBy types.String `tfsdk:"created_by"` - HelperLogic types.String `tfsdk:"helper_logic"` - HelperParams []types.String `tfsdk:"helper_params"` - ID types.String `tfsdk:"id"` - Key types.String `tfsdk:"key"` - Name types.String `tfsdk:"name"` - Tags []types.String `tfsdk:"tags"` - Template types.String `tfsdk:"template"` - Type types.String `tfsdk:"type"` - UpdatedAt types.String `tfsdk:"updated_at"` - UpdatedBy types.String `tfsdk:"updated_by"` + Config types.String `tfsdk:"config"` + CreatedAt types.String `tfsdk:"created_at"` + CreatedBy types.String `tfsdk:"created_by"` + HelperLogic types.String `tfsdk:"helper_logic"` + HelperParams []types.String `tfsdk:"helper_params"` + ID types.String `tfsdk:"id"` + Key types.String `tfsdk:"key"` + Name types.String `tfsdk:"name"` + Tags []types.String `tfsdk:"tags"` + Template types.String `tfsdk:"template"` + Type types.String `tfsdk:"type"` + UpdatedAt types.String `tfsdk:"updated_at"` + UpdatedBy types.String `tfsdk:"updated_by"` } // Metadata returns the data source type name. @@ -55,9 +54,9 @@ func (r *CustomVariableDataSource) Schema(ctx context.Context, req datasource.Sc MarkdownDescription: "CustomVariable DataSource", Attributes: map[string]schema.Attribute{ - "config": schema.SingleNestedAttribute{ + "config": schema.StringAttribute{ Computed: true, - Description: `Variable configuration`, + Description: `Parsed as JSON.`, }, "created_at": schema.StringAttribute{ Computed: true, diff --git a/internal/provider/customvariable_data_source_sdk.go b/internal/provider/customvariable_data_source_sdk.go index 64f225c..0fa2ab5 100644 --- a/internal/provider/customvariable_data_source_sdk.go +++ b/internal/provider/customvariable_data_source_sdk.go @@ -3,7 +3,7 @@ package provider import ( - tfTypes "github.com/epilot-dev/terraform-provider-epilot-custom-variable/internal/provider/types" + "encoding/json" "github.com/epilot-dev/terraform-provider-epilot-custom-variable/internal/sdk/models/shared" "github.com/hashicorp/terraform-plugin-framework/types" ) @@ -15,9 +15,10 @@ func (r *CustomVariableDataSourceModel) RefreshFromSharedCustomVariable(resp *sh r.Tags = append(r.Tags, types.StringValue(v)) } if resp.Config == nil { - r.Config = nil + r.Config = types.StringNull() } else { - r.Config = &tfTypes.Config{} + configResult, _ := json.Marshal(resp.Config) + r.Config = types.StringValue(string(configResult)) } r.CreatedAt = types.StringPointerValue(resp.CreatedAt) r.CreatedBy = types.StringPointerValue(resp.CreatedBy) diff --git a/internal/provider/customvariable_resource.go b/internal/provider/customvariable_resource.go index e8ad0a9..fab4b4c 100644 --- a/internal/provider/customvariable_resource.go +++ b/internal/provider/customvariable_resource.go @@ -6,17 +6,15 @@ import ( "context" "fmt" speakeasy_listplanmodifier "github.com/epilot-dev/terraform-provider-epilot-custom-variable/internal/planmodifiers/listplanmodifier" - speakeasy_objectplanmodifier "github.com/epilot-dev/terraform-provider-epilot-custom-variable/internal/planmodifiers/objectplanmodifier" speakeasy_stringplanmodifier "github.com/epilot-dev/terraform-provider-epilot-custom-variable/internal/planmodifiers/stringplanmodifier" - tfTypes "github.com/epilot-dev/terraform-provider-epilot-custom-variable/internal/provider/types" "github.com/epilot-dev/terraform-provider-epilot-custom-variable/internal/sdk" "github.com/epilot-dev/terraform-provider-epilot-custom-variable/internal/sdk/models/operations" + "github.com/epilot-dev/terraform-provider-epilot-custom-variable/internal/validators" "github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator" "github.com/hashicorp/terraform-plugin-framework/path" "github.com/hashicorp/terraform-plugin-framework/resource" "github.com/hashicorp/terraform-plugin-framework/resource/schema" "github.com/hashicorp/terraform-plugin-framework/resource/schema/listplanmodifier" - "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" "github.com/hashicorp/terraform-plugin-framework/schema/validator" @@ -39,19 +37,19 @@ type CustomVariableResource struct { // CustomVariableResourceModel describes the resource data model. type CustomVariableResourceModel struct { - Config *tfTypes.Config `tfsdk:"config"` - CreatedAt types.String `tfsdk:"created_at"` - CreatedBy types.String `tfsdk:"created_by"` - HelperLogic types.String `tfsdk:"helper_logic"` - HelperParams []types.String `tfsdk:"helper_params"` - ID types.String `tfsdk:"id"` - Key types.String `tfsdk:"key"` - Name types.String `tfsdk:"name"` - Tags []types.String `tfsdk:"tags"` - Template types.String `tfsdk:"template"` - Type types.String `tfsdk:"type"` - UpdatedAt types.String `tfsdk:"updated_at"` - UpdatedBy types.String `tfsdk:"updated_by"` + Config types.String `tfsdk:"config"` + CreatedAt types.String `tfsdk:"created_at"` + CreatedBy types.String `tfsdk:"created_by"` + HelperLogic types.String `tfsdk:"helper_logic"` + HelperParams []types.String `tfsdk:"helper_params"` + ID types.String `tfsdk:"id"` + Key types.String `tfsdk:"key"` + Name types.String `tfsdk:"name"` + Tags []types.String `tfsdk:"tags"` + Template types.String `tfsdk:"template"` + Type types.String `tfsdk:"type"` + UpdatedAt types.String `tfsdk:"updated_at"` + UpdatedBy types.String `tfsdk:"updated_by"` } func (r *CustomVariableResource) Metadata(ctx context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) { @@ -62,14 +60,17 @@ func (r *CustomVariableResource) Schema(ctx context.Context, req resource.Schema resp.Schema = schema.Schema{ MarkdownDescription: "CustomVariable Resource", Attributes: map[string]schema.Attribute{ - "config": schema.SingleNestedAttribute{ + "config": schema.StringAttribute{ Computed: true, Optional: true, - PlanModifiers: []planmodifier.Object{ - objectplanmodifier.RequiresReplaceIfConfigured(), - speakeasy_objectplanmodifier.SuppressDiff(speakeasy_objectplanmodifier.ExplicitSuppress), + PlanModifiers: []planmodifier.String{ + stringplanmodifier.RequiresReplaceIfConfigured(), + speakeasy_stringplanmodifier.SuppressDiff(speakeasy_stringplanmodifier.ExplicitSuppress), + }, + Description: `Requires replacement if changed.; Parsed as JSON.`, + Validators: []validator.String{ + validators.IsValidJSON(), }, - Description: `Variable configuration. Requires replacement if changed.`, }, "created_at": schema.StringAttribute{ Computed: true, diff --git a/internal/provider/customvariable_resource_sdk.go b/internal/provider/customvariable_resource_sdk.go index 013299f..f115534 100644 --- a/internal/provider/customvariable_resource_sdk.go +++ b/internal/provider/customvariable_resource_sdk.go @@ -3,7 +3,7 @@ package provider import ( - tfTypes "github.com/epilot-dev/terraform-provider-epilot-custom-variable/internal/provider/types" + "encoding/json" "github.com/epilot-dev/terraform-provider-epilot-custom-variable/internal/sdk/models/shared" "github.com/hashicorp/terraform-plugin-framework/types" ) @@ -47,10 +47,6 @@ func (r *CustomVariableResourceModel) ToSharedCustomVariable() *shared.CustomVar } else { helperLogic = nil } - var config *shared.Config - if r.Config != nil { - config = &shared.Config{} - } template := new(string) if !r.Template.IsUnknown() && !r.Template.IsNull() { *template = r.Template.ValueString() @@ -81,6 +77,10 @@ func (r *CustomVariableResourceModel) ToSharedCustomVariable() *shared.CustomVar } else { updatedBy = nil } + var config interface{} + if !r.Config.IsUnknown() && !r.Config.IsNull() { + _ = json.Unmarshal([]byte(r.Config.ValueString()), &config) + } out := shared.CustomVariable{ ID: id, Type: typeVar, @@ -89,12 +89,12 @@ func (r *CustomVariableResourceModel) ToSharedCustomVariable() *shared.CustomVar Tags: tags, HelperParams: helperParams, HelperLogic: helperLogic, - Config: config, Template: template, CreatedAt: createdAt, CreatedBy: createdBy, UpdatedAt: updatedAt, UpdatedBy: updatedBy, + Config: config, } return &out } @@ -106,9 +106,10 @@ func (r *CustomVariableResourceModel) RefreshFromSharedCustomVariable(resp *shar r.Tags = append(r.Tags, types.StringValue(v)) } if resp.Config == nil { - r.Config = nil + r.Config = types.StringNull() } else { - r.Config = &tfTypes.Config{} + configResult, _ := json.Marshal(resp.Config) + r.Config = types.StringValue(string(configResult)) } r.CreatedAt = types.StringPointerValue(resp.CreatedAt) r.CreatedBy = types.StringPointerValue(resp.CreatedBy) diff --git a/internal/provider/types/config.go b/internal/provider/types/config.go deleted file mode 100644 index ca782d0..0000000 --- a/internal/provider/types/config.go +++ /dev/null @@ -1,6 +0,0 @@ -// Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. - -package types - -type Config struct { -} diff --git a/internal/sdk/models/shared/customvariable.go b/internal/sdk/models/shared/customvariable.go index ed32ea9..aaf841b 100644 --- a/internal/sdk/models/shared/customvariable.go +++ b/internal/sdk/models/shared/customvariable.go @@ -37,10 +37,6 @@ func (e *CustomVariableType) UnmarshalJSON(data []byte) error { } } -// Config - Variable configuration -type Config struct { -} - type CustomVariable struct { // ID ID *string `json:"id,omitempty"` @@ -56,8 +52,6 @@ type CustomVariable struct { HelperParams []string `json:"helper_params,omitempty"` // The helper function logic HelperLogic *string `json:"helper_logic,omitempty"` - // Variable configuration - Config *Config `json:"config,omitempty"` // Handlebar template that used to generate the variable content Template *string `json:"template,omitempty"` // Creation time @@ -68,6 +62,7 @@ type CustomVariable struct { UpdatedAt *string `json:"updated_at,omitempty"` // Updated by UpdatedBy *string `json:"updated_by,omitempty"` + Config any `json:"config,omitempty"` } func (o *CustomVariable) GetID() *string { @@ -119,13 +114,6 @@ func (o *CustomVariable) GetHelperLogic() *string { return o.HelperLogic } -func (o *CustomVariable) GetConfig() *Config { - if o == nil { - return nil - } - return o.Config -} - func (o *CustomVariable) GetTemplate() *string { if o == nil { return nil @@ -160,3 +148,10 @@ func (o *CustomVariable) GetUpdatedBy() *string { } return o.UpdatedBy } + +func (o *CustomVariable) GetConfig() any { + if o == nil { + return nil + } + return o.Config +} diff --git a/overlay.yaml b/overlay.yaml index f672aab..1673ad5 100644 --- a/overlay.yaml +++ b/overlay.yaml @@ -29,6 +29,8 @@ actions: - target: $["paths"]["/v1/custom-variables/{id}"]["delete"] update: x-speakeasy-entity-operation: CustomVariable#delete - # - target: $["components"]["parameters"]["CustomVariableIdPathParam"] - # update: - # x-speakeasy-match: id + - target: $["components"]["schemas"]["CustomVariable"]["properties"]["config"] + remove: true + - target: $["components"]["schemas"]["CustomVariable"]["properties"] + update: + config: {}