Skip to content

Commit

Permalink
Fixes for recent issues (#246)
Browse files Browse the repository at this point in the history
* Value conversion error fix

* Support import
  • Loading branch information
beevital authored Jan 17, 2024
1 parent 14f5649 commit ed1f326
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 1 deletion.
14 changes: 13 additions & 1 deletion fivetran/framework/core/model/connector_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,19 @@ func getValue(fieldType attr.Type, value, local interface{}, fieldsMap map[strin
return types.Int64Null()
}
// value in json decoded response is always float64 for any kind of numbers
return types.Int64Value(int64(value.(float64)))
if fValue, ok := value.(float64); ok {
return types.Int64Value(int64(fValue))
}
if sValue, ok := value.(string); ok {
if sValue == "" {
return types.Int64Null()
}
i, err := strconv.Atoi(sValue)
if err == nil {
return types.Int64Value(int64(i))
}
}
panic(fmt.Sprintf("Can't convert upstream value %v to types.Int64Type", value))
}
if complexType, ok := fieldType.(attr.TypeWithAttributeTypes); ok {
if value == nil {
Expand Down
6 changes: 6 additions & 0 deletions fivetran/framework/resources/connector.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/fivetran/terraform-provider-fivetran/fivetran/framework/core"
"github.com/fivetran/terraform-provider-fivetran/fivetran/framework/core/model"
fivetranSchema "github.com/fivetran/terraform-provider-fivetran/fivetran/framework/core/schema"
"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/types"
Expand All @@ -25,6 +26,7 @@ type connector struct {
// Ensure the implementation satisfies the desired interfaces.
var _ resource.ResourceWithConfigure = &connector{}
var _ resource.ResourceWithUpgradeState = &connector{}
var _ resource.ResourceWithImportState = &connector{}

func (r *connector) Metadata(ctx context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) {
resp.TypeName = req.ProviderTypeName + "_connector"
Expand All @@ -38,6 +40,10 @@ func (r *connector) Schema(ctx context.Context, req resource.SchemaRequest, resp
}
}

func (r *connector) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) {
resource.ImportStatePassthroughID(ctx, path.Root("id"), req, resp)
}

func (r *connector) UpgradeState(ctx context.Context) map[int64]resource.StateUpgrader {

v0ConfigTfTypes := model.GetTfTypes(common.GetConfigFieldsMap(), 1)
Expand Down
6 changes: 6 additions & 0 deletions fivetran/framework/resources/connector_schema_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/fivetran/terraform-provider-fivetran/fivetran/framework/core/model"
"github.com/fivetran/terraform-provider-fivetran/fivetran/framework/core/schema"
configSchema "github.com/fivetran/terraform-provider-fivetran/modules/connector/schema"
"github.com/hashicorp/terraform-plugin-framework/path"
"github.com/hashicorp/terraform-plugin-framework/resource"
"github.com/hashicorp/terraform-plugin-framework/types"
)
Expand All @@ -22,6 +23,7 @@ type connectorSchema struct {

// Ensure the implementation satisfies the desired interfaces.
var _ resource.ResourceWithConfigure = &connectorSchema{}
var _ resource.ResourceWithImportState = &connectorSchema{}

func (r *connectorSchema) Metadata(ctx context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) {
resp.TypeName = req.ProviderTypeName + "_connector_schema_config"
Expand All @@ -31,6 +33,10 @@ func (r *connectorSchema) Schema(ctx context.Context, req resource.SchemaRequest
resp.Schema = schema.GetConnectorSchemaResourceSchema(ctx)
}

func (r *connectorSchema) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) {
resource.ImportStatePassthroughID(ctx, path.Root("id"), req, resp)
}

func (r *connectorSchema) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) {
if r.GetClient() == nil {
resp.Diagnostics.AddError(
Expand Down
6 changes: 6 additions & 0 deletions fivetran/framework/resources/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/fivetran/terraform-provider-fivetran/fivetran/framework/core"
"github.com/fivetran/terraform-provider-fivetran/fivetran/framework/core/model"
fivetranSchema "github.com/fivetran/terraform-provider-fivetran/fivetran/framework/core/schema"
"github.com/hashicorp/terraform-plugin-framework/path"
"github.com/hashicorp/terraform-plugin-framework/resource"
"github.com/hashicorp/terraform-plugin-framework/resource/schema"
)
Expand All @@ -21,6 +22,7 @@ type user struct {

// Ensure the implementation satisfies the desired interfaces.
var _ resource.ResourceWithConfigure = &user{}
var _ resource.ResourceWithImportState = &user{}

func (r *user) Metadata(ctx context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) {
resp.TypeName = req.ProviderTypeName + "_user"
Expand All @@ -32,6 +34,10 @@ func (r *user) Schema(ctx context.Context, req resource.SchemaRequest, resp *res
}
}

func (r *user) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) {
resource.ImportStatePassthroughID(ctx, path.Root("id"), req, resp)
}

func (r *user) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) {
if r.GetClient() == nil {
resp.Diagnostics.AddError(
Expand Down

0 comments on commit ed1f326

Please sign in to comment.