Skip to content

fix types overrides#54

Merged
hugoShaka merged 2 commits intomainfrom
hugo/fix-types-overrides
Nov 26, 2025
Merged

fix types overrides#54
hugoShaka merged 2 commits intomainfrom
hugo/fix-types-overrides

Conversation

@hugoShaka
Copy link
Copy Markdown
Contributor

This PR fixes the schema_types configuration by:

  • not overriding CastFrom with CastTo
  • setting go types to the saem times we use to cast from

Required for: gravitational/teleport#61680

Demo

This is my config

schema_types:
  'DiscoveryConfig.spec.aws.Params.JoinMethod':
    type: "github.com/hashicorp/terraform-plugin-framework/types.StringType"
    value_type: "github.com/hashicorp/terraform-plugin-framework/types.String"
    cast_to_type: "string"
    cast_from_type: "github.com/gravitational/teleport/api/types.JoinMethod"

This is the code before this change:

{
	a, ok := tf.Attrs["join_method"]
	if !ok {
		diags.Append(attrReadMissingDiag{"DiscoveryConfig.spec.aws.Params.JoinMethod"})
	} else {
		v, ok := a.(github.com_hashicorp_terraform_plugin_framework_types.String)
		if !ok {
			diags.Append(attrReadConversionFailureDiag{"DiscoveryConfig.spec.aws.Params.JoinMethod", "github.com/hashicorp/terraform-plugin-framework/types.String"})
		} else {
			// this is the wrong type, should match the type from `cast_from_type` but is trying to find the type in the proto package (doesn't make sense as we are in an override)
			var t github.com_gravitational_teleport_api_gen_proto_go_teleport_discoveryconfig_v1.JoinMethod
			if !v.Null && !v.Unknown {
				// this is using the `cast_to` instead of the `cast_from`
				t = string(v.Value)
			}
			obj.JoinMethod = t
		}
	}
}

This is the code after this change:

{
	a, ok := tf.Attrs["join_method"]
	if !ok {
		diags.Append(attrReadMissingDiag{"DiscoveryConfig.spec.aws.Params.JoinMethod"})
	} else {
		v, ok := a.(github.com_hashicorp_terraform_plugin_framework_types.String)
		if !ok {
			diags.Append(attrReadConversionFailureDiag{"DiscoveryConfig.spec.aws.Params.JoinMethod", "github.com/hashicorp/terraform-plugin-framework/types.String"})
		} else {
			var t github.com_gravitational_teleport_api_types.JoinMethod
			if !v.Null && !v.Unknown {
				t = github.com_gravitational_teleport_api_types.JoinMethod(v.Value)
			}
			obj.JoinMethod = t
		}
	}
}

Comment thread VERSION
@@ -1 +1 @@
v3.0.2
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll cut the release once the PR is merged. I'm just lazy and don't want to do a second PR just to bump the version

Copy link
Copy Markdown
Contributor

@r0mant r0mant left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bot.

@hugoShaka hugoShaka merged commit eda0e2d into main Nov 26, 2025
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants