@@ -624,16 +624,16 @@ func (r *ClusterRosaHcpResource) Create(ctx context.Context, request resource.Cr
624
624
tflog .Debug (ctx , "begin create()" )
625
625
626
626
// Get the plan:
627
- state := & ClusterRosaHcpState {}
628
- diags := request .Plan .Get (ctx , state )
627
+ plan := & ClusterRosaHcpState {}
628
+ diags := request .Plan .Get (ctx , plan )
629
629
response .Diagnostics .Append (diags ... )
630
630
if response .Diagnostics .HasError () {
631
631
return
632
632
}
633
633
summary := "Can't build cluster"
634
634
635
- shouldWaitCreationComplete := common .BoolWithFalseDefault (state .WaitForCreateComplete )
636
- shouldWaitComputeNodesComplete := common .BoolWithFalseDefault (state .WaitForStdComputeNodesComplete )
635
+ shouldWaitCreationComplete := common .BoolWithFalseDefault (plan .WaitForCreateComplete )
636
+ shouldWaitComputeNodesComplete := common .BoolWithFalseDefault (plan .WaitForStdComputeNodesComplete )
637
637
if shouldWaitComputeNodesComplete && ! shouldWaitCreationComplete {
638
638
response .Diagnostics .AddError (
639
639
summary ,
@@ -642,8 +642,8 @@ func (r *ClusterRosaHcpResource) Create(ctx context.Context, request resource.Cr
642
642
return
643
643
}
644
644
645
- hasEtcdEncrpytion := common .BoolWithFalseDefault (state .EtcdEncryption )
646
- hasEtcdKmsKeyArn := common .HasValue (state .EtcdKmsKeyArn ) && state .EtcdKmsKeyArn .ValueString () != ""
645
+ hasEtcdEncrpytion := common .BoolWithFalseDefault (plan .EtcdEncryption )
646
+ hasEtcdKmsKeyArn := common .HasValue (plan .EtcdKmsKeyArn ) && plan .EtcdKmsKeyArn .ValueString () != ""
647
647
if (! hasEtcdEncrpytion && hasEtcdKmsKeyArn ) || (hasEtcdEncrpytion && ! hasEtcdKmsKeyArn ) {
648
648
response .Diagnostics .AddError (
649
649
summary ,
@@ -654,7 +654,7 @@ func (r *ClusterRosaHcpResource) Create(ctx context.Context, request resource.Cr
654
654
655
655
// In case version with "openshift-v" prefix was used here,
656
656
// Give a meaningful message to inform the user that it not supported any more
657
- if common .HasValue (state .Version ) && strings .HasPrefix (state .Version .ValueString (), rosa .VersionPrefix ) {
657
+ if common .HasValue (plan .Version ) && strings .HasPrefix (plan .Version .ValueString (), rosa .VersionPrefix ) {
658
658
response .Diagnostics .AddError (
659
659
summary ,
660
660
"Openshift version must be provided without the \" openshift-v\" prefix" ,
@@ -663,32 +663,32 @@ func (r *ClusterRosaHcpResource) Create(ctx context.Context, request resource.Cr
663
663
}
664
664
665
665
channelGroup := consts .DefaultChannelGroup
666
- if common .HasValue (state .ChannelGroup ) {
667
- channelGroup = state .ChannelGroup .ValueString ()
666
+ if common .HasValue (plan .ChannelGroup ) {
667
+ channelGroup = plan .ChannelGroup .ValueString ()
668
668
}
669
669
desiredVersion := ""
670
- if common .HasValue (state .Version ) {
671
- desiredVersion = state .Version .ValueString ()
670
+ if common .HasValue (plan .Version ) {
671
+ desiredVersion = plan .Version .ValueString ()
672
672
}
673
673
_ , err := r .GetAndValidateVersionInChannelGroup (ctx , rosaTypes .Hcp , channelGroup , desiredVersion )
674
674
if err != nil {
675
675
response .Diagnostics .AddError (
676
676
summary ,
677
677
fmt .Sprintf (
678
678
"Can't build cluster with name '%s': %v" ,
679
- state .Name .ValueString (), err ,
679
+ plan .Name .ValueString (), err ,
680
680
),
681
681
)
682
682
return
683
683
}
684
684
685
- object , err := createHcpClusterObject (ctx , state , diags )
685
+ object , err := createHcpClusterObject (ctx , plan , diags )
686
686
if err != nil {
687
687
response .Diagnostics .AddError (
688
688
summary ,
689
689
fmt .Sprintf (
690
690
"Can't build cluster with name '%s': %v" ,
691
- state .Name .ValueString (), err ,
691
+ plan .Name .ValueString (), err ,
692
692
),
693
693
)
694
694
return
@@ -700,15 +700,15 @@ func (r *ClusterRosaHcpResource) Create(ctx context.Context, request resource.Cr
700
700
summary ,
701
701
fmt .Sprintf (
702
702
"Can't create cluster with name '%s': %v" ,
703
- state .Name .ValueString (), err ,
703
+ plan .Name .ValueString (), err ,
704
704
),
705
705
)
706
706
return
707
707
}
708
708
object = add .Body ()
709
709
710
710
// Save initial state:
711
- err = populateRosaHcpClusterState (ctx , object , state , common. DefaultHttpClient {} )
711
+ err = populateRosaHcpClusterState (ctx , object , plan )
712
712
if err != nil {
713
713
response .Diagnostics .AddError (
714
714
"Can't populate cluster state" ,
@@ -718,6 +718,7 @@ func (r *ClusterRosaHcpResource) Create(ctx context.Context, request resource.Cr
718
718
)
719
719
return
720
720
}
721
+ response .Diagnostics .Append (response .State .Set (ctx , plan )... )
721
722
722
723
if shouldWaitCreationComplete {
723
724
tflog .Info (ctx , "Waiting for cluster to get ready" )
@@ -728,8 +729,7 @@ func (r *ClusterRosaHcpResource) Create(ctx context.Context, request resource.Cr
728
729
fmt .Sprintf ("Waiting for cluster creation finished with the error %v" , err ),
729
730
)
730
731
if object == nil {
731
- diags = response .State .Set (ctx , state )
732
- response .Diagnostics .Append (diags ... )
732
+ response .Diagnostics .Append (response .State .Set (ctx , plan )... )
733
733
return
734
734
}
735
735
}
@@ -742,16 +742,15 @@ func (r *ClusterRosaHcpResource) Create(ctx context.Context, request resource.Cr
742
742
fmt .Sprintf ("Waiting for std compute nodes completion finished with the error %v" , err ),
743
743
)
744
744
if object == nil {
745
- diags = response .State .Set (ctx , state )
746
- response .Diagnostics .Append (diags ... )
745
+ response .Diagnostics .Append (response .State .Set (ctx , plan )... )
747
746
return
748
747
}
749
748
}
750
749
}
751
750
}
752
751
753
752
// Save the state post wait completion:
754
- err = populateRosaHcpClusterState (ctx , object , state , common. DefaultHttpClient {} )
753
+ err = populateRosaHcpClusterState (ctx , object , plan )
755
754
if err != nil {
756
755
response .Diagnostics .AddError (
757
756
"Can't populate cluster state" ,
@@ -761,9 +760,7 @@ func (r *ClusterRosaHcpResource) Create(ctx context.Context, request resource.Cr
761
760
)
762
761
return
763
762
}
764
-
765
- diags = response .State .Set (ctx , state )
766
- response .Diagnostics .Append (diags ... )
763
+ response .Diagnostics .Append (response .State .Set (ctx , plan )... )
767
764
}
768
765
769
766
func (r * ClusterRosaHcpResource ) Read (ctx context.Context , request resource.ReadRequest ,
@@ -800,7 +797,7 @@ func (r *ClusterRosaHcpResource) Read(ctx context.Context, request resource.Read
800
797
object := get .Body ()
801
798
802
799
// Save the state:
803
- err = populateRosaHcpClusterState (ctx , object , state , common. DefaultHttpClient {} )
800
+ err = populateRosaHcpClusterState (ctx , object , state )
804
801
if err != nil {
805
802
response .Diagnostics .AddError (
806
803
"Can't populate cluster state" ,
@@ -978,7 +975,7 @@ func (r *ClusterRosaHcpResource) Update(ctx context.Context, request resource.Up
978
975
object := update .Body ()
979
976
980
977
// Update the state:
981
- err = populateRosaHcpClusterState (ctx , object , plan , common. DefaultHttpClient {} )
978
+ err = populateRosaHcpClusterState (ctx , object , plan )
982
979
if err != nil {
983
980
response .Diagnostics .AddError (
984
981
"Can't populate cluster state" ,
@@ -1242,7 +1239,7 @@ func (r *ClusterRosaHcpResource) ImportState(ctx context.Context, request resour
1242
1239
}
1243
1240
1244
1241
// populateRosaHcpClusterState copies the data from the API object to the Terraform state.
1245
- func populateRosaHcpClusterState (ctx context.Context , object * cmv1.Cluster , state * ClusterRosaHcpState , httpClient common. HttpClient ) error {
1242
+ func populateRosaHcpClusterState (ctx context.Context , object * cmv1.Cluster , state * ClusterRosaHcpState ) error {
1246
1243
state .ID = types .StringValue (object .ID ())
1247
1244
state .ExternalID = types .StringValue (object .ExternalID ())
1248
1245
object .API ()
0 commit comments