|
1 | 1 | // Copyright IBM Corp. 2014, 2025 |
2 | 2 | // SPDX-License-Identifier: MPL-2.0 |
3 | 3 |
|
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 |
5 | 5 |
|
6 | 6 | package redhatopenshift |
7 | 7 |
|
@@ -619,42 +619,66 @@ func (r RedHatOpenShiftCluster) Update() sdk.ResourceFunc { |
619 | 619 | return fmt.Errorf("decoding: %+v", err) |
620 | 620 | } |
621 | 621 |
|
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 | + } |
623 | 655 |
|
624 | 656 | if metadata.ResourceData.HasChange("identity") { |
625 | 657 | expandedIdentity, err := identity.ExpandUserAssignedMapFromModel(state.Identity) |
626 | 658 | if err != nil { |
627 | 659 | return fmt.Errorf("expanding `identity`: %+v", err) |
628 | 660 | } |
629 | | - update.Identity = expandedIdentity |
| 661 | + parameter.Identity = expandedIdentity |
630 | 662 | } |
631 | 663 |
|
632 | 664 | 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) |
637 | 666 | } |
638 | 667 |
|
639 | 668 | 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) |
644 | 670 | } |
645 | 671 |
|
646 | 672 | 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) |
651 | 674 | } |
652 | 675 |
|
653 | 676 | if metadata.ResourceData.HasChange("tags") { |
654 | | - update.Tags = pointer.To(state.Tags) |
| 677 | + parameter.Tags = pointer.To(state.Tags) |
655 | 678 | } |
656 | 679 |
|
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 { |
658 | 682 | return fmt.Errorf("updating %s: %+v", id, err) |
659 | 683 | } |
660 | 684 |
|
|
0 commit comments