diff --git a/VERSION b/VERSION index f3b15f3..1defe53 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -v2.0.2 +v2.1.0 diff --git a/config.go b/config.go index 95da5a3..5fa7008 100644 --- a/config.go +++ b/config.go @@ -135,6 +135,9 @@ type Config struct { // should be used for the given package names, it can be used when the // correct import path is not found automatically. ImportPathOverrides map[string]string `yaml:"import_path_overrides,omitempty"` + // CustomTypes fields marks fields as custom types like the + // "gogoproto.customtype" tag would do. + CustomTypes map[string]string `yaml:"custom_types,omitempty"` // params represents CLI params passed from the plugin params map[string]string `yaml:"-"` diff --git a/field_build_context.go b/field_build_context.go index 756431d..4b70f6f 100644 --- a/field_build_context.go +++ b/field_build_context.go @@ -307,12 +307,17 @@ func (c *FieldBuildContext) IsMessage() bool { } // IsCustomType returns true if fields has gogo.custom_type flag +// or if there's a custom type override in configuration. func (c *FieldBuildContext) IsCustomType() bool { - return c.field.IsCustomType() + _, ok := c.config.CustomTypes[c.GetPath()] + return c.field.IsCustomType() || ok } // GetCustomType returns true if fields has gogo.custom_type flag func (c *FieldBuildContext) GetCustomType() string { + if customType, ok := c.config.CustomTypes[c.GetPath()]; ok { + return customType + } return c.field.GetCustomType() } diff --git a/test/config.yaml b/test/config.yaml index 8abe592..7ed39a7 100644 --- a/test/config.yaml +++ b/test/config.yaml @@ -48,3 +48,6 @@ plan_modifiers: validators: "Test.Str": - UseMockValidator() + +custom_types: + "Test.StringOverride": StringCustom diff --git a/test/copy_from_terraform_test.go b/test/copy_from_terraform_test.go index 3725e7a..42a157e 100644 --- a/test/copy_from_terraform_test.go +++ b/test/copy_from_terraform_test.go @@ -195,3 +195,12 @@ func TestCopyFromNullableEmbeddedFieldWithoutValue(t *testing.T) { // should be nil require.Nil(t, target.MaxAgeDuration) } + +func TestCopyFromStringOverride(t *testing.T) { + obj := copyFromTerraformObject(t) + + target := Test{} + require.False(t, CopyTestFromTerraform(context.Background(), obj, &target).HasError()) + + require.Equal(t, "a/b/c", target.StringOverride) +} diff --git a/test/custom_types.go b/test/custom_types.go index e7a1946..8c14945 100644 --- a/test/custom_types.go +++ b/test/custom_types.go @@ -3,6 +3,7 @@ package test import ( "context" fmt "fmt" + "strings" time "time" "github.com/hashicorp/terraform-plugin-framework/attr" @@ -78,3 +79,65 @@ func CopyToBoolSpecial(diags diag.Diagnostics, obj []BoolCustom, t attr.Type, v return value } + +// StringCustom is a custom type that maps a Terraform List of string, onto a +// single go string by joining all elements with "/". + +// GenSchemaStringCustom returns the StringCustom schema. +func GenSchemaStringCustom(_ context.Context) tfsdk.Attribute { + return tfsdk.Attribute{ + Type: types.ListType{ + ElemType: types.StringType, + }, + } +} + +// CopyFromStringCustom copies the value from Terraform (a list of strings) into +// the source (a single string) by joining all elements with "/". +func CopyFromStringCustom(diags diag.Diagnostics, tf attr.Value, obj *string) { + v, ok := tf.(types.List) + if !ok { + diags.AddError("Error reading value from Terraform", fmt.Sprintf("Failed to cast %T to types.List", tf)) + return + } + + items := make([]string, 0) + for _, raw := range v.Elems { + el, ok := raw.(types.String) + if !ok { + diags.AddError("Error reading value from Terraform", fmt.Sprintf("Failed to cast %T to types.Bool", raw)) + return + } + + if !el.Null && !el.Unknown { + items = append(items, el.Value) + } + } + + *obj = strings.Join(items, "/") +} + +// CopyToStringCustom copies a source value (single string) into the Terraform +// value (a list of strings) by splitting the string on every "/". +func CopyToStringCustom(diags diag.Diagnostics, obj string, t attr.Type, v attr.Value) attr.Value { + value, ok := v.(types.List) + if !ok { + value = types.List{ + Null: true, + Unknown: false, + ElemType: types.StringType, + } + } + + if len(obj) > 0 { + if value.Elems == nil { + value.Elems = make([]attr.Value, len(obj)) + } + + for i, b := range strings.Split(obj, "/") { + value.Elems[i] = types.String{Null: false, Unknown: false, Value: b} + } + } + + return value +} diff --git a/test/fixtures.go b/test/fixtures.go index 0493593..f431969 100644 --- a/test/fixtures.go +++ b/test/fixtures.go @@ -423,6 +423,11 @@ func copyFromTerraformObject(t *testing.T) types.Object { }, }, "max_age": DurationValue{Value: duration}, + "string_override": types.List{Elems: []attr.Value{ + types.String{Value: "a"}, + types.String{Value: "b"}, + types.String{Value: "c"}, + }}, }, AttrTypes: obj.AttrTypes, } diff --git a/test/test.pb.go b/test/test.pb.go index 295a0d1..ee4bf2c 100644 --- a/test/test.pb.go +++ b/test/test.pb.go @@ -128,8 +128,11 @@ type Test struct { // *Test_StringBranch OneOfWithEmptyMessage isTest_OneOfWithEmptyMessage `protobuf_oneof:"OneOfWithEmptyMessage"` // EmbeddedField encapsulates fields which can be shared among various types - EmbeddedField `protobuf:"bytes,38,opt,name=EmbeddedField,proto3,embedded=EmbeddedField" json:""` - *MaxAgeDuration `protobuf:"bytes,39,opt,name=EmbedNullable,proto3,embedded=EmbedNullable" json:""` + EmbeddedField `protobuf:"bytes,38,opt,name=EmbeddedField,proto3,embedded=EmbeddedField" json:""` + *MaxAgeDuration `protobuf:"bytes,39,opt,name=EmbedNullable,proto3,embedded=EmbedNullable" json:""` + // BoolCustomOverride []bool field, gogoproto.customtype is not set but there + // is custom_type override in the configuration + StringOverride string `protobuf:"bytes,40,opt,name=StringOverride,proto3" json:"StringOverride,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` @@ -535,77 +538,78 @@ func init() { func init() { proto.RegisterFile("test.proto", fileDescriptor_c161fcfdc0c3ff1e) } var fileDescriptor_c161fcfdc0c3ff1e = []byte{ - // 1141 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x56, 0xcb, 0x72, 0x1a, 0x47, - 0x14, 0xa5, 0x19, 0x24, 0xe0, 0x0a, 0x21, 0x74, 0x85, 0xa4, 0x36, 0x8e, 0x99, 0x31, 0xb1, 0xe3, - 0x89, 0xab, 0x82, 0x22, 0xe4, 0x52, 0xa5, 0x9c, 0x57, 0x65, 0x22, 0x29, 0x8e, 0x1d, 0x20, 0x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be, 0xed, 0xd0, 0x92, 0xa6, 0xe8, - 0x79, 0x16, 0x42, 0x50, 0x87, 0xb5, 0x20, 0x3a, 0x1c, 0x8e, 0x9d, 0x0b, 0xba, 0x2e, 0x48, 0x71, - 0x18, 0xf7, 0xa1, 0xe8, 0xde, 0x54, 0x69, 0x2f, 0xdc, 0x50, 0x53, 0xf4, 0x9c, 0x51, 0xfc, 0x73, - 0xa6, 0x42, 0x90, 0x61, 0x31, 0x16, 0xbe, 0x07, 0x79, 0xc3, 0xbd, 0xcc, 0x42, 0xb2, 0xa1, 0x29, - 0x7a, 0x81, 0x05, 0x00, 0x1e, 0xc1, 0xaa, 0x7f, 0x58, 0x82, 0x51, 0xd6, 0x94, 0xff, 0x38, 0xe7, - 0x8c, 0x38, 0xe3, 0xa8, 0x0c, 0x3f, 0x03, 0x8c, 0x6e, 0x80, 0x30, 0xdb, 0xd4, 0x94, 0x85, 0x8d, - 0x4a, 0xe0, 0xe1, 0x7d, 0x58, 0x6e, 0x71, 0xdb, 0xe1, 0x5d, 0xba, 0x25, 0xae, 0x59, 0xa1, 0x2e, - 0x5a, 0x8d, 0xc4, 0x8c, 0x8c, 0x5b, 0x0b, 0x6c, 0xce, 0xc0, 0x87, 0x50, 0x94, 0x23, 0xff, 0xea, - 0x6f, 0x5f, 0xa3, 0x21, 0x2c, 0xc6, 0x44, 0x06, 0x95, 0x28, 0x12, 0xb9, 0xe2, 0xf4, 0x5a, 0x9f, - 0x37, 0xa8, 0xb0, 0x01, 0x20, 0xb3, 0x62, 0xc5, 0x37, 0xc4, 0xf6, 0x25, 0xcd, 0x3f, 0xc4, 0x42, + // 1158 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x56, 0xcd, 0x72, 0x1a, 0x47, + 0x17, 0xa5, 0x19, 0x24, 0xe0, 0x0a, 0x21, 0x74, 0x85, 0xa4, 0x36, 0xfe, 0xcc, 0x8c, 0xf9, 0xfc, + 0x33, 0x71, 0x55, 0x70, 0x84, 0x5c, 0xaa, 0x94, 0xf3, 0x57, 0x99, 0x48, 0x8a, 0x63, 0x07, 0x48, + 0x5a, 0x56, 0xbc, 0x74, 0x0d, 0xa2, 0x8d, 0x70, 0x80, 0xa1, 0x98, 0xc1, 0x25, 0xbd, 0x45, 0x96, + 0xc9, 0x1b, 0x69, 0xa9, 0x65, 0x2a, 0x0b, 0x52, 0xf1, 0x52, 0x8f, 0x90, 0x55, 0x6a, 0xba, 0x99, + 0x5f, 0x46, 0x4e, 0xec, 0x5d, 0xdf, 0x73, 0xcf, 0x39, 0xd3, 0xdd, 0xb7, 0xfb, 0x4e, 0x03, 0x38, + 0xdc, 0x76, 0xea, 0xe3, 0x89, 0xe5, 0x58, 0x98, 0x71, 0xc7, 0x95, 0x72, 0xcf, 0xea, 0x59, 0x02, + 0x78, 0xe8, 0x8e, 0x64, 0xae, 0xa2, 0xf6, 0x2c, 0xab, 0x37, 0xe0, 0x0f, 0x45, 0xd4, 0x99, 0xbe, + 0x7a, 0xe8, 0xf4, 0x87, 0xdc, 0x76, 0xcc, 0xe1, 0x58, 0x12, 0x6a, 0x97, 0xeb, 0x90, 0x79, 0xce, + 0x6d, 0x07, 0x2b, 0xa0, 0x1c, 0x39, 0x13, 0x4a, 0x34, 0xa2, 0xe7, 0x8d, 0xdc, 0xd5, 0x4c, 0xcd, + 0xd8, 0xce, 0x64, 0x87, 0xb9, 0x20, 0x96, 0x61, 0xe9, 0xbb, 0x91, 0xb3, 0xdb, 0xa0, 0x69, 0x8d, + 0xe8, 0x4b, 0x4c, 0x06, 0x73, 0x74, 0xef, 0x11, 0x55, 0x34, 0xa2, 0x2b, 0x4c, 0x06, 0x2e, 0x7a, + 0x38, 0xb0, 0x4c, 0x87, 0x66, 0x34, 0xa2, 0xa7, 0x99, 0x0c, 0x70, 0x0b, 0x96, 0xf7, 0xad, 0x69, + 0x67, 0xc0, 0xe9, 0x92, 0x46, 0x74,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xdf, 0x56, 0x53, 0x9d, 0x65, 0xf1, 0xe0, 0xd8, 0xfd, 0x27, 0x00, 0x00, 0xff, 0xff, 0xd5, 0xb0, + 0x20, 0xb8, 0x6c, 0x0c, 0x00, 0x00, } diff --git a/test/test.proto b/test/test.proto index 01fd0fc..ca89301 100644 --- a/test/test.proto +++ b/test/test.proto @@ -166,6 +166,13 @@ message Test { (gogoproto.jsontag) = "", (gogoproto.embed) = true ]; + + // StringOverride is represented by a single string in the go struct, but by + // a list of strings in the Terraform Schema. The plugin's configuration + // specifies a custom_type (StringCustom), the generator should use the + // functions "GenSchemaStringCustom", "CopyFromStringCustom", + // "CopyToStringCustom" instead of attempting to generate them. + string StringOverride = 40; } message MaxAgeDuration { @@ -223,4 +230,3 @@ message EmbeddedNestedField { // EmbeddedNestedString string field string EmbeddedNestedString = 1 [(gogoproto.jsontag) = "embedded_nested_string"]; } - diff --git a/test/test_terraform.go b/test/test_terraform.go index 2f3f019..e1a3e18 100644 --- a/test/test_terraform.go +++ b/test/test_terraform.go @@ -434,6 +434,7 @@ func GenSchemaTest(ctx context.Context) (github_com_hashicorp_terraform_plugin_f Optional: true, Type: github_com_hashicorp_terraform_plugin_framework_types.ListType{ElemType: github_com_hashicorp_terraform_plugin_framework_types.StringType}, }, + "string_override": GenSchemaStringCustom(ctx), "timestamp": { Description: "Timestamp time.Time field", Optional: true, @@ -2101,6 +2102,13 @@ func CopyTestFromTerraform(_ context.Context, tf github_com_hashicorp_terraform_ } } } + { + a, ok := tf.Attrs["string_override"] + if !ok { + diags.Append(attrReadMissingDiag{"Test.StringOverride"}) + } + CopyFromStringCustom(diags, a, &obj.StringOverride) + } { a, ok := tf.Attrs["timestamp"] if !ok { @@ -4972,6 +4980,15 @@ func CopyTestToTerraform(ctx context.Context, obj *Test, tf *github_com_hashicor } } } + { + t, ok := tf.AttrTypes["string_override"] + if !ok { + diags.Append(attrWriteMissingDiag{"Test.StringOverride"}) + } else { + v := CopyToStringCustom(diags, obj.StringOverride, t, tf.Attrs["string_override"]) + tf.Attrs["string_override"] = v + } + } { t, ok := tf.AttrTypes["timestamp"] if !ok {