Skip to content

Commit

Permalink
fix: config property
Browse files Browse the repository at this point in the history
  • Loading branch information
Mateus Nardo committed Oct 10, 2024
1 parent c11ff12 commit 90937d7
Show file tree
Hide file tree
Showing 18 changed files with 75 additions and 138 deletions.
7 changes: 3 additions & 4 deletions .speakeasy/gen.lock
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ terraform {
required_providers {
epilot-custom-variable = {
source = "epilot-dev/epilot-custom-variable"
version = "1.0.1"
version = "1.0.2"
}
}
}
Expand Down
5 changes: 1 addition & 4 deletions docs/data-sources/custom_variable.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

<a id="nestedatt--config"></a>
### Nested Schema for `config`
2 changes: 1 addition & 1 deletion docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ terraform {
required_providers {
epilot-custom-variable = {
source = "epilot-dev/epilot-custom-variable"
version = "1.0.0"
version = "1.0.2"
}
}
}
Expand Down
9 changes: 2 additions & 7 deletions docs/resources/custom_variable.md
Original file line number Diff line number Diff line change
Expand Up @@ -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;"
Expand All @@ -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.
Expand All @@ -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.

<a id="nestedatt--config"></a>
### Nested Schema for `config`

## Import

Import is supported using the following syntax:
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-custom-variable = {
source = "epilot-dev/epilot-custom-variable"
version = "1.0.1"
version = "1.0.2"
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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;"
Expand Down
26 changes: 0 additions & 26 deletions examples/tests/provider.tf

This file was deleted.

15 changes: 0 additions & 15 deletions examples/tests/variables.tf

This file was deleted.

6 changes: 1 addition & 5 deletions final.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -691,6 +686,7 @@ components:
type: string
description: Updated by
example: 100042
config: {}
examples:
ExampleMain:
value:
Expand Down
2 changes: 1 addition & 1 deletion gen.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ go:
outputModelSuffix: output
packageName: openapi
terraform:
version: 1.0.1
version: 1.0.2
additionalDataSources: []
additionalDependencies: {}
additionalResources: []
Expand Down
31 changes: 15 additions & 16 deletions internal/provider/customvariable_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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.
Expand All @@ -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,
Expand Down
7 changes: 4 additions & 3 deletions internal/provider/customvariable_data_source_sdk.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand All @@ -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)
Expand Down
43 changes: 22 additions & 21 deletions internal/provider/customvariable_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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) {
Expand All @@ -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,
Expand Down
17 changes: 9 additions & 8 deletions internal/provider/customvariable_resource_sdk.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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,
Expand All @@ -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
}
Expand All @@ -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)
Expand Down
6 changes: 0 additions & 6 deletions internal/provider/types/config.go

This file was deleted.

Loading

0 comments on commit 90937d7

Please sign in to comment.