Skip to content

Commit c4be68f

Browse files
authored
Use map instead of BAC API type as intermediate type for TGC cai2hcl conversion of networksecurity BackendAuthenticationConfig (#15117)
1 parent 3ed6187 commit c4be68f

File tree

2 files changed

+17
-14
lines changed

2 files changed

+17
-14
lines changed

mmv1/third_party/cai2hcl/services/networksecurity/backend_authentication_config.go

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import (
66
"github.com/GoogleCloudPlatform/terraform-google-conversion/v6/cai2hcl/common"
77
"github.com/GoogleCloudPlatform/terraform-google-conversion/v6/caiasset"
88
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
9-
netsecapi "google.golang.org/api/networksecurity/v1"
109
)
1110

1211
// BackendAuthenticationConfigAssetType is the CAI asset type name.
@@ -75,20 +74,16 @@ func (c *BackendAuthenticationConfigConverter) convertResourceData(asset *caiass
7574
func flattenBackendAuthenticationConfig(resource *caiasset.AssetResource) (map[string]any, error) {
7675
result := make(map[string]any)
7776

78-
var backendAuthenticationConfig *netsecapi.BackendAuthenticationConfig
79-
if err := common.DecodeJSON(resource.Data, &backendAuthenticationConfig); err != nil {
80-
return nil, err
81-
}
82-
83-
result["name"] = flattenName(backendAuthenticationConfig.Name)
84-
result["labels"] = backendAuthenticationConfig.Labels
85-
result["description"] = backendAuthenticationConfig.Description
86-
result["client_certificate"] = backendAuthenticationConfig.ClientCertificate
87-
result["trust_config"] = backendAuthenticationConfig.TrustConfig
88-
result["well_known_roots"] = backendAuthenticationConfig.WellKnownRoots
89-
result["project"] = flattenProjectName(backendAuthenticationConfig.Name)
77+
resourceData := resource.Data
9078

91-
result["location"] = resource.Location
79+
result["name"] = flattenName(resourceData["name"].(string))
80+
result["labels"] = resourceData["labels"]
81+
result["description"] = resourceData["description"]
82+
result["client_certificate"] = resourceData["clientCertificate"]
83+
result["trust_config"] = resourceData["trustConfig"]
84+
result["well_known_roots"] = resourceData["wellKnownRoots"]
85+
result["project"] = flattenProjectName(resourceData["name"].(string))
86+
result["location"] = flattenLocation(resourceData["name"].(string))
9287

9388
return result, nil
9489
}

mmv1/third_party/cai2hcl/services/networksecurity/utils.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,11 @@ func flattenProjectName(name string) string {
1414
}
1515
return tokens[1]
1616
}
17+
18+
func flattenLocation(name string) string {
19+
tokens := strings.Split(name, "/")
20+
if len(tokens) < 6 || tokens[2] != "locations" {
21+
return ""
22+
}
23+
return tokens[3]
24+
}

0 commit comments

Comments
 (0)