Skip to content

Commit cafcfba

Browse files
committed
use PUT so we can update the field upgradeable_to
1 parent 09667d6 commit cafcfba

2 files changed

Lines changed: 43 additions & 19 deletions

File tree

internal/services/redhatopenshift/redhat_openshift_cluster_resource.go

Lines changed: 41 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copyright IBM Corp. 2014, 2025
22
// SPDX-License-Identifier: MPL-2.0
33

4-
//go:generate go run ../../tools/generator-tests resourceidentity -resource-name redhat_openshift_cluster -service-package-name redhatopenshift -properties "name,resource_group_name" -known-values "subscription_id:data.Subscriptions.Primary"
4+
//go:generate go run ../../tools/generator-tests resourceidentity -resource-name redhat_openshift_cluster -service-package-name redhatopenshift -properties "name,resource_group_name" -known-values "subscription_id:data.Subscriptions.Primary" -test-expect-non-empty
55

66
package redhatopenshift
77

@@ -619,42 +619,66 @@ func (r RedHatOpenShiftCluster) Update() sdk.ResourceFunc {
619619
return fmt.Errorf("decoding: %+v", err)
620620
}
621621

622-
var update openshiftclusters.OpenShiftClusterUpdate
622+
existing, err := client.Get(ctx, *id)
623+
if err != nil {
624+
return fmt.Errorf("retrieving %s: %+v", id, err)
625+
}
626+
if existing.Model == nil {
627+
return fmt.Errorf("retrieving %s: `model` was nil", id)
628+
}
629+
if existing.Model.Properties == nil {
630+
return fmt.Errorf("retrieving %s: `properties` was nil", id)
631+
}
632+
633+
parameter := *existing.Model
634+
635+
// These properties are read-only and populated by Azure; including them in the update request body is rejected.
636+
parameter.SystemData = nil
637+
parameter.Properties.ProvisioningState = nil
638+
parameter.Properties.ConsoleProfile = nil
639+
parameter.Properties.WorkerProfilesStatus = nil
640+
if parameter.Properties.ClusterProfile != nil {
641+
parameter.Properties.ClusterProfile.OidcIssuer = nil
642+
}
643+
if parameter.Properties.ApiserverProfile != nil {
644+
parameter.Properties.ApiserverProfile.Url = nil
645+
parameter.Properties.ApiserverProfile.IP = nil
646+
}
647+
if parameter.Properties.IngressProfiles != nil {
648+
for i := range *parameter.Properties.IngressProfiles {
649+
(*parameter.Properties.IngressProfiles)[i].IP = nil
650+
}
651+
}
652+
if parameter.Properties.NetworkProfile != nil && parameter.Properties.NetworkProfile.LoadBalancerProfile != nil {
653+
parameter.Properties.NetworkProfile.LoadBalancerProfile.EffectiveOutboundIPs = nil
654+
}
623655

624656
if metadata.ResourceData.HasChange("identity") {
625657
expandedIdentity, err := identity.ExpandUserAssignedMapFromModel(state.Identity)
626658
if err != nil {
627659
return fmt.Errorf("expanding `identity`: %+v", err)
628660
}
629-
update.Identity = expandedIdentity
661+
parameter.Identity = expandedIdentity
630662
}
631663

632664
if metadata.ResourceData.HasChange("service_principal") {
633-
if update.Properties == nil {
634-
update.Properties = &openshiftclusters.OpenShiftClusterProperties{}
635-
}
636-
update.Properties.ServicePrincipalProfile = expandOpenshiftServicePrincipalProfile(state.ServicePrincipal)
665+
parameter.Properties.ServicePrincipalProfile = expandOpenshiftServicePrincipalProfile(state.ServicePrincipal)
637666
}
638667

639668
if metadata.ResourceData.HasChange("platform_workload_identity_profile") {
640-
if update.Properties == nil {
641-
update.Properties = &openshiftclusters.OpenShiftClusterProperties{}
642-
}
643-
update.Properties.PlatformWorkloadIdentityProfile = expandOpenshiftPlatformWorkloadIdentityProfile(state.PlatformWorkloadIdentityProfile)
669+
parameter.Properties.PlatformWorkloadIdentityProfile = expandOpenshiftPlatformWorkloadIdentityProfile(state.PlatformWorkloadIdentityProfile)
644670
}
645671

646672
if metadata.ResourceData.HasChange("network_profile") {
647-
if update.Properties == nil {
648-
update.Properties = &openshiftclusters.OpenShiftClusterProperties{}
649-
}
650-
update.Properties.NetworkProfile = expandOpenshiftNetworkProfile(state.NetworkProfile)
673+
parameter.Properties.NetworkProfile = expandOpenshiftNetworkProfile(state.NetworkProfile)
651674
}
652675

653676
if metadata.ResourceData.HasChange("tags") {
654-
update.Tags = pointer.To(state.Tags)
677+
parameter.Tags = pointer.To(state.Tags)
655678
}
656679

657-
if err := client.UpdateThenPoll(ctx, *id, update); err != nil {
680+
// Platform workload identity updates require PUT so a workload identity can be updated in place.
681+
if err := client.CreateOrUpdateThenPoll(ctx, *id, parameter); err != nil {
658682
return fmt.Errorf("updating %s: %+v", id, err)
659683
}
660684

internal/services/redhatopenshift/redhat_openshift_cluster_resource_identity_gen_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ func TestAccRedhatOpenshiftCluster_resourceIdentity(t *testing.T) {
3333
statecheck.ExpectIdentityValueMatchesStateAtPath("azurerm_redhat_openshift_cluster.test", tfjsonpath.New("resource_group_name"), tfjsonpath.New("resource_group_name")),
3434
},
3535
},
36-
data.ImportBlockWithResourceIdentityStep(false),
37-
data.ImportBlockWithIDStep(false),
36+
data.ImportBlockWithResourceIdentityStep(true),
37+
data.ImportBlockWithIDStep(true),
3838
}, false)
3939
}

0 commit comments

Comments
 (0)