diff --git a/cli/bpmetadata/tfconfig.go b/cli/bpmetadata/tfconfig.go index 7363f5985a5..e589bdc8558 100644 --- a/cli/bpmetadata/tfconfig.go +++ b/cli/bpmetadata/tfconfig.go @@ -535,6 +535,9 @@ func mergeExistingOutputTypes(newInterfaces, existingInterfaces *BlueprintInterf } for i, output := range newInterfaces.Outputs { + if output.Type != nil { + continue + } if existingOutput, ok := existingOutputs[output.Name]; ok && existingOutput.Type != nil { newInterfaces.Outputs[i].Type = existingOutput.Type } diff --git a/cli/bpmetadata/tfconfig_test.go b/cli/bpmetadata/tfconfig_test.go index 7e1ea600365..b65a44dbef7 100644 --- a/cli/bpmetadata/tfconfig_test.go +++ b/cli/bpmetadata/tfconfig_test.go @@ -351,21 +351,31 @@ func TestMergeExistingOutputTypes(t *testing.T) { name string newInterfacesFile string existingInterfacesFile string + expectedInterfacesFile string }{ { name: "No existing types", newInterfacesFile: "interfaces_without_output_types_metadata.yaml", existingInterfacesFile: "interfaces_without_output_types_metadata.yaml", + expectedInterfacesFile: "interfaces_without_output_types_metadata.yaml", }, { name: "One complex existing type is preserved", newInterfacesFile: "interfaces_without_output_types_metadata.yaml", existingInterfacesFile: "interfaces_with_partial_output_types_metadata.yaml", + expectedInterfacesFile: "interfaces_with_partial_output_types_metadata.yaml", }, { name: "All existing types (both simple and complex) are preserved", newInterfacesFile: "interfaces_without_output_types_metadata.yaml", existingInterfacesFile: "interfaces_with_full_output_types_metadata.yaml", + expectedInterfacesFile: "interfaces_with_full_output_types_metadata.yaml", + }, + { + name: "Previous types are not overwriting newly generated types", + newInterfacesFile: "interfaces_with_new_output_types_metadata.yaml", + existingInterfacesFile: "interfaces_with_partial_output_types_metadata.yaml", + expectedInterfacesFile: "interfaces_with_new_output_types_metadata.yaml", }, } @@ -382,8 +392,12 @@ func TestMergeExistingOutputTypes(t *testing.T) { // Perform the merge mergeExistingOutputTypes(newInterfaces.Spec.Interfaces, existingInterfaces.Spec.Interfaces) + // Load expected interfaces from file + expectedInterfaces, err := UnmarshalMetadata(metadataTestdataPath, tt.expectedInterfacesFile) + require.NoError(t, err) + // Assert that the merged interfaces match the expected outcome - assert.Equal(t, existingInterfaces.Spec.Interfaces, newInterfaces.Spec.Interfaces) + assert.Equal(t, expectedInterfaces.Spec.Interfaces, newInterfaces.Spec.Interfaces) }) } } diff --git a/cli/testdata/bpmetadata/metadata/interfaces_with_new_output_types_metadata.yaml b/cli/testdata/bpmetadata/metadata/interfaces_with_new_output_types_metadata.yaml new file mode 100644 index 00000000000..424365c833c --- /dev/null +++ b/cli/testdata/bpmetadata/metadata/interfaces_with_new_output_types_metadata.yaml @@ -0,0 +1,16 @@ +apiVersion: blueprints.cloud.google.com/v1alpha1 +kind: BlueprintMetadata +metadata: + name: terraform-google-network +spec: + interfaces: + outputs: + - name: cluster_id + description: Cluster ID + type: string + - name: endpoint + description: Cluster endpoint + type: + - tuple + - string + number \ No newline at end of file