Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement basic functionality for StructToSchema #3788

Merged

Conversation

edwardfeng-db
Copy link
Contributor

@edwardfeng-db edwardfeng-db commented Jul 17, 2024

Changes

  • Baisc functionality for StructToSchema, everything is Optional now
  • Need to do:
    • Implement equivalent for CustomizableSchema
    • Make tfsdk structs contain information about optional and computed
    • Handle recursive data types

Tests

  • make test run locally
  • relevant change in docs/ folder
  • covered with integration tests in internal/acceptance
  • relevant acceptance tests are passing
  • using Go SDK

@edwardfeng-db edwardfeng-db requested review from a team as code owners July 17, 2024 14:49
@edwardfeng-db edwardfeng-db requested review from mgyucht and tanmay-db and removed request for a team July 17, 2024 14:49
Copy link
Contributor

@tanmay-db tanmay-db left a comment

Choose a reason for hiding this comment

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

Had some comments but core logic LGTM.

scm[fieldName] = schema.SingleNestedAttribute{Attributes: nestedScm, Optional: true}
}
} else {
panic(fmt.Errorf("unknown type for field: %s", typeField.Name))
Copy link
Contributor

Choose a reason for hiding this comment

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

should we also print the type as well here?

@@ -289,3 +290,105 @@ func checkTheStringInForceSendFields(fieldName string, forceSendFields []string)
}
return false
}

func pluginFrameworkTypeToSchema(v reflect.Value) map[string]schema.Attribute {
Copy link
Contributor

Choose a reason for hiding this comment

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

This would also need to include aliases and tracking context that we currently have to typeToSchema for sdkv2?

Example -- we use tracking context for depth:

		if tc.depthExceeded(typeField) {
			// Skip the field if recursion depth is over the limit.
			log.Printf("[TRACE] over recursion limit, skipping field: %s, max depth: %d", getNameForType(typeField.Type), tc.getMaxDepthForTypeField(typeField))
			continue
		}

and aliases while getting field name:

fieldName := chooseFieldNameWithAliases(typeField, v.Type(), aliases)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For tracking context yes, alias no.

Tracking context is coming up as the next step for recursion depth limit.

In the future all of alias information will go directly into the proto layer with annotations, so we don't have to worry about them in tf

@edwardfeng-db edwardfeng-db changed the title [Plugin Framework] Implement basic functionality for StructToSchema Implement basic functionality for StructToSchema Jul 19, 2024
@edwardfeng-db edwardfeng-db merged commit cf5d4bb into terraform-plugin-framework Jul 19, 2024
3 of 10 checks passed
@edwardfeng-db edwardfeng-db deleted the edwardfeng-db/struct-to-schema branch July 19, 2024 12:05
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.

2 participants