Connection details mapping generates incorrect field name casing for nested JSON fields
- Dominant language
- Go
- Stars
- 481
- Forks
- 131
- Avg merge
- 2d 1h
- Merged PRs (30d)
- 11
Description
### What happened?
Upjet's automatic connection details mapping generation doesn't handle nested field name casing correctly when JSON struct tags use different casing than Go field names. This creates inconsistent field references in the generated `GetConnectionDetailsMapping()` function.
**Expected Behavior:**
The generated connection details mapping should reference field names that match the JSON struct tags, ensuring consistency with the actual field paths used in the CRD.
**Actual Behavior:**
The connection details mapping references field names that don't match the JSON struct tags, causing a mismatch between the generated mapping and the actual struct field paths.
**Example:**
**Struct Definition** (from `zz_storagelocation_types.go`):
```go
type GCPStorageConfigParameters struct {
// +kubebuilder:validation:Optional
GCPJSONCredentialsSecretRef *v1.SecretKeySelector `json:"gcpjsonCredentialsSecretRef,omitempty" tf:"-"`
// ↑ lowercase 'j'
}
```
**Generated Connection Details Mapping** (from `zz_storagelocation_terraformed.go`):
```go
func (tr *StorageLocation) GetConnectionDetailsMapping() map[string]string {
return map[string]string{
"gcp_storage_config[*].gcp_json_credentials": "spec.forProvider.gcpStorageConfig[*].gcpJsonCredentialsSecretRef"
// ↑ capital 'J' (incorrect)
}
}
```
**Should be:**
```go
func (tr *StorageLocation) GetConnectionDetailsMapping() map[string]string {
return map[string]string{
"gcp_storage_config[*].gcp_json_credentials": "spec.forProvider.gcpStorageConfig[*].gcpjsonCredentialsSecretRef"
// ↑ lowercase 'j' (correct)
}
}
```
**Impact:**
- Potentially breaks connection details mapping for resources with sensitive fields that have this casing mismatch
- Creates inconsistency between generated code and actual struct definitions
- Confusing for developers who expect the mapping to match the JSON field paths
### How can we reproduce it?
1. **Create a Terraform resource** with nested configuration blocks containing sensitive fields where:
- Go struct field uses camelCase (e.g., `GCPJSONCredentialsSecretRef`)
- JSON tag uses different casing (e.g., `json:"gcpjsonCredentialsSecretRef"`)
2. **Generate the provider code:**
```bash
make generate
```
3. **Observe the generated terraformed file** (e.g., `apis/*/v1alpha1/zz_*_terraformed.go`) and check the `GetConnectionDetailsMapping()` function
4. **Compare the field names** in the connection details mapping with the JSON struct tags in the types file
**Example repository demonstrating the issue:**
- **Repository:** https://github.com/crossplane-contrib/provider-palette
- **Branch:** `tf-0.23.7-cp` (or `main`)
- **Provider:** `provider-palette` (spectrocloud resources)
- **Affected resources:** `spectrocloud_backup_storage_location`, `spectrocloud_cloudaccount_gcp`
- **Files to check:**
- [`apis/backup/v1alpha1/zz_storagelocation_types.go`](https://github.com/crossplane-contrib/provider-palette/blob/main/apis/backup/v1alpha1/zz_storagelocation_types.go) (line 139)
- [`apis/backup/v1alpha1/zz_storagelocation_terraformed.go`](https://github.com/crossplane-contrib/provider-palette/blob/main/apis/backup/v1alpha1/zz_storagelocation_terraformed.go) (line 24)
- [`apis/cloudaccount/v1alpha1/zz_gcp_terraformed.go`](https://github.com/crossplane-contrib/provider-palette/blob/main/apis/cloudaccount/v1alpha1/zz_gcp_terraformed.go) (line 24)
**Steps to reproduce with provider-palette:**
```bash
git clone https://github.com/crossplane-contrib/provider-palette.git
cd provider-palette
git checkout tf-0.23.7-cp
make generate
# Check the generated files mentioned above
```
**Attempted workaround that doesn't work:**
Using `Sensitive.AddFieldPath()` in resource configuration only adds additional field paths rather than overriding the auto-generated incorrect ones:
```go
r.Sensitive.AddFieldPath("gcp_storage_config[*].gcp_json_credentials", "spec.forProvider.gcpStorageConfig[*].gcpjsonCredentialsSecretRef")
```
**Environment:**
- **Upjet Version:** `v1.3.0`
- **Provider:** provider-palette (spectrocloud resources)
- **Go Version:** `1.23.10` (toolchain `1.24.0`)
- Issue occurs during `make generate` process
- Affects any provider using nested configuration blocks with sensitive fields that have JSON tag casing differences
- Discovered on provider-palette but likely affects other providers with similar patterns
Contributor guide
Assessment
This issue has not been assessed yet.