@@ -189,7 +189,9 @@ func (c *clusterResource) Schema(ctx context.Context, req resource.SchemaRequest
189
189
190
190
"pg_config" : schema.SetNestedBlock {
191
191
MarkdownDescription : "Database configuration parameters. See [Modifying database configuration parameters](https://www.enterprisedb.com/docs/biganimal/latest/using_cluster/03_modifying_your_cluster/05_db_configuration_parameters/) for details." ,
192
- PlanModifiers : []planmodifier.Set {plan_modifier .CustomPGConfig ()},
192
+ PlanModifiers : []planmodifier.Set {
193
+ setplanmodifier .UseStateForUnknown (),
194
+ },
193
195
NestedObject : schema.NestedBlockObject {
194
196
Attributes : map [string ]schema.Attribute {
195
197
"name" : schema.StringAttribute {
@@ -595,108 +597,117 @@ func (c *clusterResource) ImportState(ctx context.Context, req resource.ImportSt
595
597
resp .Diagnostics .Append (resp .State .SetAttribute (ctx , path .Root ("cluster_id" ), idParts [1 ])... )
596
598
}
597
599
598
- func (c * clusterResource ) read (ctx context.Context , clusterResource * ClusterResourceModel ) error {
599
- cluster , err := c .client .Read (ctx , clusterResource .ProjectId , * clusterResource .ClusterId )
600
+ func (c * clusterResource ) read (ctx context.Context , tfClusterResource * ClusterResourceModel ) error {
601
+ apiCluster , err := c .client .Read (ctx , tfClusterResource .ProjectId , * tfClusterResource .ClusterId )
600
602
if err != nil {
601
603
return err
602
604
}
603
605
604
- connection , err := c .client .ConnectionString (ctx , clusterResource .ProjectId , * clusterResource .ClusterId )
606
+ connection , err := c .client .ConnectionString (ctx , tfClusterResource .ProjectId , * tfClusterResource .ClusterId )
605
607
if err != nil {
606
608
return err
607
609
}
608
610
609
- clusterResource .ID = types .StringValue (fmt .Sprintf ("%s/%s" , clusterResource .ProjectId , * clusterResource .ClusterId ))
610
- clusterResource .ClusterId = cluster .ClusterId
611
- clusterResource .ClusterName = types .StringPointerValue (cluster .ClusterName )
612
- clusterResource .ClusterType = cluster .ClusterType
613
- clusterResource .Phase = cluster .Phase
614
- clusterResource .CloudProvider = types .StringValue (cluster .Provider .CloudProviderId )
615
- clusterResource .ClusterArchitecture = & ClusterArchitectureResourceModel {
616
- Id : cluster .ClusterArchitecture .ClusterArchitectureId ,
617
- Nodes : cluster .ClusterArchitecture .Nodes ,
618
- Name : types .StringValue (cluster .ClusterArchitecture .ClusterArchitectureName ),
619
- }
620
- clusterResource .Region = types .StringValue (cluster .Region .Id )
621
- clusterResource .InstanceType = types .StringValue (cluster .InstanceType .InstanceTypeId )
622
- clusterResource .Storage = & StorageResourceModel {
623
- VolumeType : types .StringPointerValue (cluster .Storage .VolumeTypeId ),
624
- VolumeProperties : types .StringPointerValue (cluster .Storage .VolumePropertiesId ),
625
- Size : types .StringPointerValue (cluster .Storage .Size ),
626
- Iops : types .StringPointerValue (cluster .Storage .Iops ),
627
- Throughput : types .StringPointerValue (cluster .Storage .Throughput ),
628
- }
629
- clusterResource .ResizingPvc = StringSliceToList (cluster .ResizingPvc )
630
- clusterResource .ReadOnlyConnections = types .BoolPointerValue (cluster .ReadOnlyConnections )
631
- clusterResource .ConnectionUri = & connection .PgUri
632
- clusterResource .RoConnectionUri = & connection .ReadOnlyPgUri
633
- clusterResource .CspAuth = types .BoolPointerValue (cluster .CSPAuth )
634
- clusterResource .LogsUrl = cluster .LogsUrl
635
- clusterResource .MetricsUrl = cluster .MetricsUrl
636
- clusterResource .BackupRetentionPeriod = types .StringPointerValue (cluster .BackupRetentionPeriod )
637
- clusterResource .PgVersion = types .StringValue (cluster .PgVersion .PgVersionId )
638
- clusterResource .PgType = types .StringValue (cluster .PgType .PgTypeId )
639
- clusterResource .FarawayReplicaIds = StringSliceToSet (cluster .FarawayReplicaIds )
640
- clusterResource .PrivateNetworking = types .BoolPointerValue (cluster .PrivateNetworking )
641
- clusterResource .SuperuserAccess = types .BoolPointerValue (cluster .SuperuserAccess )
642
- if cluster .Extensions != nil {
643
- for _ , v := range * cluster .Extensions {
611
+ tfClusterResource .ID = types .StringValue (fmt .Sprintf ("%s/%s" , tfClusterResource .ProjectId , * tfClusterResource .ClusterId ))
612
+ tfClusterResource .ClusterId = apiCluster .ClusterId
613
+ tfClusterResource .ClusterName = types .StringPointerValue (apiCluster .ClusterName )
614
+ tfClusterResource .ClusterType = apiCluster .ClusterType
615
+ tfClusterResource .Phase = apiCluster .Phase
616
+ tfClusterResource .CloudProvider = types .StringValue (apiCluster .Provider .CloudProviderId )
617
+ tfClusterResource .ClusterArchitecture = & ClusterArchitectureResourceModel {
618
+ Id : apiCluster .ClusterArchitecture .ClusterArchitectureId ,
619
+ Nodes : apiCluster .ClusterArchitecture .Nodes ,
620
+ Name : types .StringValue (apiCluster .ClusterArchitecture .ClusterArchitectureName ),
621
+ }
622
+ tfClusterResource .Region = types .StringValue (apiCluster .Region .Id )
623
+ tfClusterResource .InstanceType = types .StringValue (apiCluster .InstanceType .InstanceTypeId )
624
+ tfClusterResource .Storage = & StorageResourceModel {
625
+ VolumeType : types .StringPointerValue (apiCluster .Storage .VolumeTypeId ),
626
+ VolumeProperties : types .StringPointerValue (apiCluster .Storage .VolumePropertiesId ),
627
+ Size : types .StringPointerValue (apiCluster .Storage .Size ),
628
+ Iops : types .StringPointerValue (apiCluster .Storage .Iops ),
629
+ Throughput : types .StringPointerValue (apiCluster .Storage .Throughput ),
630
+ }
631
+ tfClusterResource .ResizingPvc = StringSliceToList (apiCluster .ResizingPvc )
632
+ tfClusterResource .ReadOnlyConnections = types .BoolPointerValue (apiCluster .ReadOnlyConnections )
633
+ tfClusterResource .ConnectionUri = & connection .PgUri
634
+ tfClusterResource .RoConnectionUri = & connection .ReadOnlyPgUri
635
+ tfClusterResource .CspAuth = types .BoolPointerValue (apiCluster .CSPAuth )
636
+ tfClusterResource .LogsUrl = apiCluster .LogsUrl
637
+ tfClusterResource .MetricsUrl = apiCluster .MetricsUrl
638
+ tfClusterResource .BackupRetentionPeriod = types .StringPointerValue (apiCluster .BackupRetentionPeriod )
639
+ tfClusterResource .PgVersion = types .StringValue (apiCluster .PgVersion .PgVersionId )
640
+ tfClusterResource .PgType = types .StringValue (apiCluster .PgType .PgTypeId )
641
+ tfClusterResource .FarawayReplicaIds = StringSliceToSet (apiCluster .FarawayReplicaIds )
642
+ tfClusterResource .PrivateNetworking = types .BoolPointerValue (apiCluster .PrivateNetworking )
643
+ tfClusterResource .SuperuserAccess = types .BoolPointerValue (apiCluster .SuperuserAccess )
644
+ if apiCluster .Extensions != nil {
645
+ for _ , v := range * apiCluster .Extensions {
644
646
if v .Enabled && v .ExtensionId == "pgvector" {
645
- clusterResource .Pgvector = types .BoolValue (true )
647
+ tfClusterResource .Pgvector = types .BoolValue (true )
646
648
break
647
649
}
648
650
}
649
651
}
650
652
651
- if cluster .FirstRecoverabilityPointAt != nil {
652
- firstPointAt := cluster .FirstRecoverabilityPointAt .String ()
653
- clusterResource .FirstRecoverabilityPointAt = & firstPointAt
653
+ if apiCluster .FirstRecoverabilityPointAt != nil {
654
+ firstPointAt := apiCluster .FirstRecoverabilityPointAt .String ()
655
+ tfClusterResource .FirstRecoverabilityPointAt = & firstPointAt
654
656
}
655
657
656
- clusterResource .PgConfig = []PgConfigResourceModel {}
657
- if configs := cluster .PgConfig ; configs != nil {
658
- for _ , kv := range * configs {
659
- clusterResource .PgConfig = append (clusterResource .PgConfig , PgConfigResourceModel {
660
- Name : kv .Name ,
661
- Value : kv .Value ,
662
- })
658
+ // pgConfig. If tf resource pg config elem matches with api response pg config elem then add the elem to tf resource pg config
659
+ newPgConfig := []PgConfigResourceModel {}
660
+ if configs := apiCluster .PgConfig ; configs != nil {
661
+ for _ , tfCRPgConfig := range tfClusterResource .PgConfig {
662
+ for _ , apiConfig := range * configs {
663
+ if tfCRPgConfig .Name == apiConfig .Name {
664
+ newPgConfig = append (newPgConfig , PgConfigResourceModel {
665
+ Name : apiConfig .Name ,
666
+ Value : apiConfig .Value ,
667
+ })
668
+ }
669
+ }
663
670
}
664
671
}
665
672
666
- clusterResource .AllowedIpRanges = []AllowedIpRangesResourceModel {}
667
- if allowedIpRanges := cluster .AllowedIpRanges ; allowedIpRanges != nil {
673
+ if len (newPgConfig ) > 0 {
674
+ tfClusterResource .PgConfig = newPgConfig
675
+ }
676
+
677
+ tfClusterResource .AllowedIpRanges = []AllowedIpRangesResourceModel {}
678
+ if allowedIpRanges := apiCluster .AllowedIpRanges ; allowedIpRanges != nil {
668
679
for _ , ipRange := range * allowedIpRanges {
669
- clusterResource .AllowedIpRanges = append (clusterResource .AllowedIpRanges , AllowedIpRangesResourceModel {
680
+ tfClusterResource .AllowedIpRanges = append (tfClusterResource .AllowedIpRanges , AllowedIpRangesResourceModel {
670
681
CidrBlock : ipRange .CidrBlock ,
671
682
Description : types .StringValue (ipRange .Description ),
672
683
})
673
684
}
674
685
}
675
686
676
- if pt := cluster .CreatedAt ; pt != nil {
677
- clusterResource .CreatedAt = types .StringValue (pt .String ())
687
+ if pt := apiCluster .CreatedAt ; pt != nil {
688
+ tfClusterResource .CreatedAt = types .StringValue (pt .String ())
678
689
}
679
690
680
- if cluster .MaintenanceWindow != nil {
681
- clusterResource .MaintenanceWindow = & commonTerraform.MaintenanceWindow {
682
- IsEnabled : cluster .MaintenanceWindow .IsEnabled ,
683
- StartDay : types .Int64PointerValue (utils .ToPointer (int64 (* cluster .MaintenanceWindow .StartDay ))),
684
- StartTime : types .StringPointerValue (cluster .MaintenanceWindow .StartTime ),
691
+ if apiCluster .MaintenanceWindow != nil {
692
+ tfClusterResource .MaintenanceWindow = & commonTerraform.MaintenanceWindow {
693
+ IsEnabled : apiCluster .MaintenanceWindow .IsEnabled ,
694
+ StartDay : types .Int64PointerValue (utils .ToPointer (int64 (* apiCluster .MaintenanceWindow .StartDay ))),
695
+ StartTime : types .StringPointerValue (apiCluster .MaintenanceWindow .StartTime ),
685
696
}
686
697
}
687
698
688
- if cluster .PeAllowedPrincipalIds != nil {
689
- clusterResource .PeAllowedPrincipalIds = StringSliceToSet (utils .ToValue (& cluster .PeAllowedPrincipalIds ))
699
+ if apiCluster .PeAllowedPrincipalIds != nil {
700
+ tfClusterResource .PeAllowedPrincipalIds = StringSliceToSet (utils .ToValue (& apiCluster .PeAllowedPrincipalIds ))
690
701
}
691
702
692
- if cluster .ServiceAccountIds != nil {
693
- clusterResource .ServiceAccountIds = StringSliceToSet (utils .ToValue (& cluster .ServiceAccountIds ))
703
+ if apiCluster .ServiceAccountIds != nil {
704
+ tfClusterResource .ServiceAccountIds = StringSliceToSet (utils .ToValue (& apiCluster .ServiceAccountIds ))
694
705
}
695
706
696
- if cluster .PgBouncer != nil {
697
- clusterResource .PgBouncer = & PgBouncerModel {}
698
- * clusterResource .PgBouncer = PgBouncerModel {
699
- IsEnabled : cluster .PgBouncer .IsEnabled ,
707
+ if apiCluster .PgBouncer != nil {
708
+ tfClusterResource .PgBouncer = & PgBouncerModel {}
709
+ * tfClusterResource .PgBouncer = PgBouncerModel {
710
+ IsEnabled : apiCluster .PgBouncer .IsEnabled ,
700
711
}
701
712
702
713
settingsElemType := map [string ]attr.Type {"name" : types .StringType , "operation" : types .StringType , "value" : types .StringType }
@@ -706,24 +717,24 @@ func (c *clusterResource) read(ctx context.Context, clusterResource *ClusterReso
706
717
"value" : basetypes .NewStringValue ("" ),
707
718
})
708
719
709
- if ! cluster .PgBouncer .IsEnabled {
710
- clusterResource .PgBouncer .Settings = basetypes .NewSetNull (elem .Type (ctx ))
711
- } else if cluster .PgBouncer .IsEnabled &&
712
- cluster .PgBouncer .Settings != nil &&
713
- len (* cluster .PgBouncer .Settings ) == 0 {
714
- clusterResource .PgBouncer .Settings = basetypes .NewSetNull (elem .Type (ctx ))
715
- } else if cluster .PgBouncer .Settings != nil && len (* cluster .PgBouncer .Settings ) > 0 {
720
+ if ! apiCluster .PgBouncer .IsEnabled {
721
+ tfClusterResource .PgBouncer .Settings = basetypes .NewSetNull (elem .Type (ctx ))
722
+ } else if apiCluster .PgBouncer .IsEnabled &&
723
+ apiCluster .PgBouncer .Settings != nil &&
724
+ len (* apiCluster .PgBouncer .Settings ) == 0 {
725
+ tfClusterResource .PgBouncer .Settings = basetypes .NewSetNull (elem .Type (ctx ))
726
+ } else if apiCluster .PgBouncer .Settings != nil && len (* apiCluster .PgBouncer .Settings ) > 0 {
716
727
settings := []attr.Value {}
717
728
718
- for _ , v := range * cluster .PgBouncer .Settings {
729
+ for _ , v := range * apiCluster .PgBouncer .Settings {
719
730
object := basetypes .NewObjectValueMust (settingsElemType , map [string ]attr.Value {
720
731
"name" : basetypes .NewStringValue (* v .Name ),
721
732
"operation" : basetypes .NewStringValue (* v .Operation ),
722
733
"value" : basetypes .NewStringValue (* v .Value ),
723
734
})
724
735
settings = append (settings , object )
725
736
}
726
- clusterResource .PgBouncer .Settings = basetypes .NewSetValueMust (elem .Type (ctx ), settings )
737
+ tfClusterResource .PgBouncer .Settings = basetypes .NewSetValueMust (elem .Type (ctx ), settings )
727
738
}
728
739
}
729
740
0 commit comments