Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: wal storage #608

Merged
merged 5 commits into from
Nov 28, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions examples/resources/biganimal_cluster/ha/resource.tf
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,12 @@ resource "biganimal_cluster" "ha_cluster" {
size = "4 Gi"
}

# wal_storage = {
# volume_type = "gp3"
# volume_properties = "gp3"
Copy link
Collaborator

@edbamolvyavahare edbamolvyavahare Nov 13, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we handle setting volume properties internally since it does not have properties like az
# volume_type = "azurepremiumstorage"
# volume_properties = "P1"

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh for AWS/GCP? Possibly it could work but maybe we can do it in another PR as an enhancement so that they can remove volume_properties for AWS/GCP. As of right now I think I recall in the API(for BA anyways) the volume_properties have to match the volume_type otherwise it will throw an error

# size = "4 Gi"
# }

maintenance_window = {
is_enabled = true
start_day = 6
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,12 @@ resource "biganimal_cluster" "single_node_cluster" {
size = "4 Gi"
}

# wal_storage = {
# volume_type = "gp3"
# volume_properties = "gp3"
# size = "4 Gi"
# }

maintenance_window = {
is_enabled = true
start_day = 6
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,12 @@ resource "biganimal_cluster" "single_node_cluster" {
size = "4 Gi"
}

# wal_storage = {
# volume_type = "azurepremiumstorage"
# volume_properties = "P1"
# size = "4 Gi"
# }

maintenance_window = {
is_enabled = true
start_day = 6
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,12 @@ resource "biganimal_cluster" "single_node_cluster" {
size = "10 Gi"
}

# wal_storage = {
# volume_type = "pd-ssd"
# volume_properties = "pd-ssd"
# size = "10 Gi"
# }

maintenance_window = {
is_enabled = true
start_day = 6
Expand Down
5 changes: 5 additions & 0 deletions examples/resources/biganimal_faraway_replica/aws/resource.tf
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ resource "biganimal_faraway_replica" "faraway_replica" {
volume_properties = "gp3"
size = "4 Gi"
}
# wal_storage = {
# volume_type = "gp3"
# volume_properties = "gp3"
# size = "4 Gi"
# }
private_networking = false
region = "ap-south-1"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ resource "biganimal_faraway_replica" "faraway_replica" {
volume_properties = "P1"
size = "4 Gi"
}
# wal_storage = {
# volume_type = "azurepremiumstorage"
# volume_properties = "P1"
# size = "4 Gi"
# }
private_networking = false
region = "australiaeast"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,11 @@ resource "biganimal_faraway_replica" "faraway_replica" {
volume_properties = "P1"
size = "4 Gi"
}
# wal_storage = {
# volume_type = "azurepremiumstorage"
# volume_properties = "P1"
# size = "4 Gi"
# }
private_networking = false
region = "centralindia"

Expand Down
5 changes: 5 additions & 0 deletions examples/resources/biganimal_faraway_replica/gcp/resource.tf
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ resource "biganimal_faraway_replica" "faraway_replica" {
volume_properties = "pd-ssd"
size = "4 Gi"
}
# wal_storage = {
# volume_type = "pd-ssd"
# volume_properties = "pd-ssd"
# size = "4 Gi"
# }
private_networking = false
region = "us-east1"

Expand Down
5 changes: 5 additions & 0 deletions examples/resources/biganimal_pgd/aws/data_group/resource.tf
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,11 @@ resource "biganimal_pgd" "pgd_cluster" {
volume_properties = "gp3"
size = "32 Gi"
}
# wal_storage = {
# volume_type = "gp3"
# volume_properties = "gp3"
# size = "32 Gi"
# }
pg_type = {
pg_type_id = "epas" #valid values ["epas", "pgextended", "postgres]"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,11 @@ resource "biganimal_pgd" "pgd_cluster" {
volume_properties = "gp3"
size = "32 Gi"
}
# wal_storage = {
# volume_type = "gp3"
# volume_properties = "gp3"
# size = "32 Gi"
# }
pg_type = {
pg_type_id = "epas" #valid values ["epas", "pgextended", "postgres]"
}
Expand Down Expand Up @@ -134,6 +139,11 @@ resource "biganimal_pgd" "pgd_cluster" {
volume_properties = "gp3"
size = "32 Gi"
}
# wal_storage = {
# volume_type = "gp3"
# volume_properties = "gp3"
# size = "32 Gi"
# }
pg_type = {
pg_type_id = "epas" #valid values ["epas", "pgextended", "postgres]"
}
Expand Down
10 changes: 10 additions & 0 deletions examples/resources/biganimal_pgd/azure/data_group/resource.tf
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,16 @@ resource "biganimal_pgd" "pgd_cluster" {
volume_properties = "P2"
size = "32 Gi"
}
storage = {
volume_type = "azurepremiumstorage"
volume_properties = "P2"
size = "32 Gi"
}
# wal_storage = {
# volume_type = "azurepremiumstorage"
# volume_properties = "P2"
# size = "32 Gi"
# }
pg_type = {
pg_type_id = "epas" #valid values ["epas", "pgextended", "postgres]"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,11 @@ resource "biganimal_pgd" "pgd_cluster" {
volume_properties = "P2"
size = "32 Gi"
}
# wal_storage = {
# volume_type = "azurepremiumstorage"
# volume_properties = "P2"
# size = "32 Gi"
# }
pg_type = {
pg_type_id = "epas" #valid values ["epas", "pgextended", "postgres]"
}
Expand Down Expand Up @@ -134,6 +139,11 @@ resource "biganimal_pgd" "pgd_cluster" {
volume_properties = "P2"
size = "32 Gi"
}
# wal_storage = {
# volume_type = "azurepremiumstorage"
# volume_properties = "P2"
# size = "32 Gi"
# }
pg_type = {
pg_type_id = "epas" #valid values ["epas", "pgextended", "postgres]"
}
Expand Down
5 changes: 5 additions & 0 deletions examples/resources/biganimal_pgd/gcp/data_group/resource.tf
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,11 @@ resource "biganimal_pgd" "pgd_cluster" {
volume_properties = "pd-ssd"
size = "32 Gi"
}
# wal_storage = {
# volume_type = "pd-ssd"
# volume_properties = "pd-ssd"
# size = "32 Gi"
# }
pg_type = {
pg_type_id = "epas" #valid values ["epas", "pgextended", "postgres]"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,11 @@ resource "biganimal_pgd" "pgd_cluster" {
volume_properties = "pd-ssd"
size = "32 Gi"
}
# wal_storage = {
# volume_type = "pd-ssd"
# volume_properties = "pd-ssd"
# size = "32 Gi"
# }
pg_type = {
pg_type_id = "epas" #valid values ["epas", "pgextended", "postgres]"
}
Expand Down Expand Up @@ -138,6 +143,11 @@ resource "biganimal_pgd" "pgd_cluster" {
volume_properties = "pd-ssd"
size = "32 Gi"
}
# wal_storage = {
# volume_type = "pd-ssd"
# volume_properties = "pd-ssd"
# size = "32 Gi"
# }
pg_type = {
pg_type_id = "epas" #valid values ["epas", "pgextended", "postgres]"
}
Expand Down
1 change: 1 addition & 0 deletions pkg/models/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ type Cluster struct {
EncryptionKeyIdReq *string `json:"keyId,omitempty"`
EncryptionKeyResp *EncryptionKey `json:"encryptionKey,omitempty"`
PgIdentity *string `json:"pgIdentity,omitempty"`
WalStorage *Storage `json:"walStorage,omitempty"`
}

// IsHealthy checks to see if the cluster has the right condition 'biganimal.com/deployed'
Expand Down
1 change: 1 addition & 0 deletions pkg/models/pgd/api/data_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,5 @@ type DataGroup struct {
PeAllowedPrincipalIds *[]string `json:"peAllowedPrincipalIds,omitempty"`
RoConnectionUri *string `json:"roConnectionUri,omitempty"`
ReadOnlyConnections *bool `json:"readOnlyConnections,omitempty"`
WalStorage *models.Storage `json:"walStorage,omitempty"`
}
1 change: 1 addition & 0 deletions pkg/models/pgd/terraform/data_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,5 @@ type DataGroup struct {
PeAllowedPrincipalIds types.Set `tfsdk:"pe_allowed_principal_ids"`
RoConnectionUri types.String `tfsdk:"ro_connection_uri"`
ReadOnlyConnections *bool `tfsdk:"read_only_connections"`
WalStorage *Storage `tfsdk:"wal_storage"`
}
5 changes: 5 additions & 0 deletions pkg/plan_modifier/data_group_custom_diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,11 @@ func (m CustomDataGroupDiffModifier) PlanModifyList(ctx context.Context, req pla
pDg.Storage.Iops = sDg.Storage.Iops
pDg.Storage.Throughput = sDg.Storage.Throughput

if sDg.WalStorage != nil {
pDg.WalStorage.Iops = sDg.WalStorage.Iops
pDg.WalStorage.Throughput = sDg.WalStorage.Throughput
}

// fix to set the correct allowed ip ranges to allow all if a PGD data group has private networking set as true
if pDg.PrivateNetworking != nil && *pDg.PrivateNetworking {
pDg.AllowedIpRanges = types.SetValueMust(pDg.AllowedIpRanges.ElementType(ctx), []attr.Value{
Expand Down
35 changes: 35 additions & 0 deletions pkg/provider/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ package provider
import (
commonApi "github.com/EnterpriseDB/terraform-provider-biganimal/pkg/models/common/api"
commonTerraform "github.com/EnterpriseDB/terraform-provider-biganimal/pkg/models/common/terraform"
"github.com/hashicorp/terraform-plugin-framework/resource/schema"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier"
"github.com/hashicorp/terraform-plugin-framework/types"
"github.com/hashicorp/terraform-plugin-framework/types/basetypes"
)
Expand Down Expand Up @@ -31,3 +34,35 @@ func buildAPIReqAssignTags(tfRsrcTags []commonTerraform.Tag) []commonApi.Tag {
}
return tags
}

var resourceWal = schema.SingleNestedAttribute{
Description: "Write-Ahead Logs (WAL) Storage.",
Optional: true,
Attributes: map[string]schema.Attribute{
wai-wong-edb marked this conversation as resolved.
Show resolved Hide resolved
"iops": schema.StringAttribute{
Description: "IOPS for the selected volume. It can be set to different values depending on your volume type and properties.",
Optional: true,
Computed: true,
PlanModifiers: []planmodifier.String{stringplanmodifier.UseStateForUnknown()},
},
"size": schema.StringAttribute{
Description: "Size of the volume. It can be set to different values depending on your volume type and properties.",
Required: true,
Copy link
Collaborator

@edbamolvyavahare edbamolvyavahare Nov 27, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cannot be require=true in case of azurepremiumstorage
since each volumeproperty has size, iops and throughput predefined and associated with it.

Screenshot 2024-11-27 at 4 44 10 PM

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

size is actually a mandatory field. In the request if I just put P1 and leave size as nil it will return with this:

biganimal_cluster.single_node_cluster: Creating...

│ Error: status: 400 - Bad Request

│ with biganimal_cluster.single_node_cluster,
│ on resource.tf line 21, in resource "biganimal_cluster" "single_node_cluster":
│ 21: resource "biganimal_cluster" "single_node_cluster" {

│ must have required property 'clusterType'
│ must NOT have additional properties
│ must NOT have additional properties
│ must NOT have additional properties
│ must NOT have additional properties
│ must NOT have additional properties
│ must NOT have additional properties
│ must NOT have additional properties
│ must NOT have additional properties

however if I put P1 and give a size of 7 Gi I get the error:

biganimal_cluster.single_node_cluster: Creating...
biganimal_pgd.pgd_cluster: Destruction complete after 5s

│ Error: status: 400 - Bad Request

│ with biganimal_cluster.single_node_cluster,
│ on resource.tf line 21, in resource "biganimal_cluster" "single_node_cluster":
│ 21: resource "biganimal_cluster" "single_node_cluster" {

│ Value of storage size must be between 4 Gi and 4 Gi

I guess a future improvement would be to fetch the list of azurepremiumstorage volume properties and their sizes so size can be optional if they select azurepremiumstorage. But I think we can have that as an enhancement

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

volume_properties: P1
volume_type: P1
size: 4 (exact size associated with each volume_property)

so user need to fill above details, for it to work

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let provide link to volume storage ref in examples

PlanModifiers: []planmodifier.String{stringplanmodifier.UseStateForUnknown()},
},
"throughput": schema.StringAttribute{
Description: "Throughput is automatically calculated by BigAnimal based on the IOPS input if it's not provided.",
Optional: true,
Computed: true,
PlanModifiers: []planmodifier.String{stringplanmodifier.UseStateForUnknown()},
},
"volume_properties": schema.StringAttribute{
Description: "Volume properties in accordance with the selected volume type.",
Required: true,
},
"volume_type": schema.StringAttribute{
Description: "Volume type. For Azure: \"azurepremiumstorage\" or \"ultradisk\". For AWS: \"gp3\", \"io2\", org s \"io2-block-express\". For Google Cloud: only \"pd-ssd\".",
wai-wong-edb marked this conversation as resolved.
Show resolved Hide resolved
Required: true,
},
},
}
19 changes: 19 additions & 0 deletions pkg/provider/resource_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ type ClusterResourceModel struct {
VolumeSnapshot types.Bool `tfsdk:"volume_snapshot_backup"`
Tags []commonTerraform.Tag `tfsdk:"tags"`
ServiceName types.String `tfsdk:"service_name"`
WalStorage *StorageResourceModel `tfsdk:"wal_storage"`

Timeouts timeouts.Value `tfsdk:"timeouts"`
}
Expand Down Expand Up @@ -575,6 +576,7 @@ func (c *clusterResource) Schema(ctx context.Context, req resource.SchemaRequest
Computed: true,
PlanModifiers: []planmodifier.String{stringplanmodifier.UseStateForUnknown()},
},
"wal_storage": resourceWal,
},
}
}
Expand Down Expand Up @@ -863,6 +865,13 @@ func readCluster(ctx context.Context, client *api.ClusterClient, tfClusterResour
tfClusterResource.SuperuserAccess = types.BoolPointerValue(responseCluster.SuperuserAccess)
tfClusterResource.PgIdentity = types.StringPointerValue(responseCluster.PgIdentity)
tfClusterResource.VolumeSnapshot = types.BoolPointerValue(responseCluster.VolumeSnapshot)
tfClusterResource.WalStorage = &StorageResourceModel{
VolumeType: types.StringPointerValue(responseCluster.WalStorage.VolumeTypeId),
VolumeProperties: types.StringPointerValue(responseCluster.WalStorage.VolumePropertiesId),
Size: types.StringPointerValue(responseCluster.WalStorage.Size),
Iops: types.StringPointerValue(responseCluster.WalStorage.Iops),
Throughput: types.StringPointerValue(responseCluster.WalStorage.Throughput),
}

if responseCluster.EncryptionKeyResp != nil && *responseCluster.Phase != constants.PHASE_HEALTHY {
if !tfClusterResource.PgIdentity.IsNull() && tfClusterResource.PgIdentity.ValueString() != "" {
Expand Down Expand Up @@ -1102,6 +1111,16 @@ func (c *clusterResource) generateGenericClusterModel(ctx context.Context, clust
VolumeSnapshot: clusterResource.VolumeSnapshot.ValueBoolPointer(),
}

if clusterResource.WalStorage != nil {
cluster.WalStorage = &models.Storage{
VolumePropertiesId: clusterResource.WalStorage.VolumeProperties.ValueStringPointer(),
VolumeTypeId: clusterResource.WalStorage.VolumeType.ValueStringPointer(),
Iops: clusterResource.WalStorage.Iops.ValueStringPointer(),
Size: clusterResource.WalStorage.Size.ValueStringPointer(),
Throughput: clusterResource.WalStorage.Throughput.ValueStringPointer(),
}
}

cluster.Extensions = &[]models.ClusterExtension{}
if clusterResource.Pgvector.ValueBool() {
*cluster.Extensions = append(*cluster.Extensions, models.ClusterExtension{Enabled: true, ExtensionId: "pgvector"})
Expand Down
19 changes: 19 additions & 0 deletions pkg/provider/resource_fareplica.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ type FAReplicaResourceModel struct {
TransparentDataEncryptionAction types.String `tfsdk:"transparent_data_encryption_action"`
VolumeSnapshot types.Bool `tfsdk:"volume_snapshot_backup"`
Tags []commonTerraform.Tag `tfsdk:"tags"`
WalStorage *StorageResourceModel `tfsdk:"wal_storage"`

Timeouts timeouts.Value `tfsdk:"timeouts"`
}
Expand Down Expand Up @@ -422,6 +423,7 @@ func (r *FAReplicaResource) Schema(ctx context.Context, req resource.SchemaReque
plan_modifier.CustomAssignTags(),
},
},
"wal_storage": resourceWal,
},
}
}
Expand Down Expand Up @@ -636,6 +638,13 @@ func readFAReplica(ctx context.Context, client *api.ClusterClient, fAReplicaReso
fAReplicaResourceModel.PgVersion = types.StringValue(responseCluster.PgVersion.PgVersionId)
fAReplicaResourceModel.PgType = types.StringValue(responseCluster.PgType.PgTypeId)
fAReplicaResourceModel.VolumeSnapshot = types.BoolPointerValue(responseCluster.VolumeSnapshot)
fAReplicaResourceModel.WalStorage = &StorageResourceModel{
VolumeType: types.StringPointerValue(responseCluster.WalStorage.VolumeTypeId),
VolumeProperties: types.StringPointerValue(responseCluster.WalStorage.VolumePropertiesId),
Size: types.StringPointerValue(responseCluster.WalStorage.Size),
Iops: types.StringPointerValue(responseCluster.WalStorage.Iops),
Throughput: types.StringPointerValue(responseCluster.WalStorage.Throughput),
}

// pgConfig. If tf resource pg config elem matches with api response pg config elem then add the elem to tf resource pg config
newPgConfig := []PgConfigResourceModel{}
Expand Down Expand Up @@ -770,6 +779,16 @@ func (r *FAReplicaResource) generateGenericFAReplicaModel(ctx context.Context, f
BackupRetentionPeriod: fAReplicaResourceModel.BackupRetentionPeriod.ValueStringPointer(),
}

if fAReplicaResourceModel.WalStorage != nil {
cluster.WalStorage = &models.Storage{
VolumePropertiesId: fAReplicaResourceModel.WalStorage.VolumeProperties.ValueStringPointer(),
VolumeTypeId: fAReplicaResourceModel.WalStorage.VolumeType.ValueStringPointer(),
Iops: fAReplicaResourceModel.WalStorage.Iops.ValueStringPointer(),
Size: fAReplicaResourceModel.WalStorage.Size.ValueStringPointer(),
Throughput: fAReplicaResourceModel.WalStorage.Throughput.ValueStringPointer(),
}
}

allowedIpRanges := []models.AllowedIpRange{}
for _, ipRange := range fAReplicaResourceModel.AllowedIpRanges {
allowedIpRanges = append(allowedIpRanges, models.AllowedIpRange{
Expand Down
Loading
Loading