Skip to content

Commit

Permalink
feat: wal storage (#608)
Browse files Browse the repository at this point in the history
* feat: wal storage

* feat: data sources

* feat: read only connection bug

* fix: requested changes

* fix: azurepremiumstorage example comments
  • Loading branch information
wai-wong-edb authored Nov 28, 2024
1 parent c609e0f commit 6504d0e
Show file tree
Hide file tree
Showing 27 changed files with 223 additions and 6 deletions.
4 changes: 4 additions & 0 deletions examples/data-sources/biganimal_cluster/data-source.tf
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,10 @@ output "storage" {
value = data.biganimal_cluster.this.storage
}

output "wal_storage" {
value = data.biganimal_cluster.this.wal_storage
}

output "superuser_access" {
value = coalesce(data.biganimal_cluster.this.superuser_access, false)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,10 @@ output "storage" {
value = data.biganimal_faraway_replica.this.storage
}

output "wal_storage" {
value = data.biganimal_faraway_replica.this.wal_storage
}

output "volume_snapshot_backup" {
value = data.biganimal_faraway_replica.this.volume_snapshot_backup
}
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"
# 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 @@ -66,9 +66,15 @@ resource "biganimal_cluster" "single_node_cluster" {
storage = {
volume_type = "azurepremiumstorage"
volume_properties = "P1"
size = "4 Gi"
size = "4 Gi" # for azurepremiumstorage please check Premium storage disk sizes here: https://learn.microsoft.com/en-us/azure/virtual-machines/premium-storage-performance
}

# wal_storage = {
# volume_type = "azurepremiumstorage"
# volume_properties = "P1"
# size = "4 Gi" # for azurepremiumstorage please check Premium storage disk sizes here: https://learn.microsoft.com/en-us/azure/virtual-machines/premium-storage-performance
# }

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 @@ -64,8 +64,13 @@ resource "biganimal_faraway_replica" "faraway_replica" {
storage = {
volume_type = "azurepremiumstorage"
volume_properties = "P1"
size = "4 Gi"
size = "4 Gi" # for azurepremiumstorage please check Premium storage disk sizes here: https://learn.microsoft.com/en-us/azure/virtual-machines/premium-storage-performance
}
# wal_storage = {
# volume_type = "azurepremiumstorage"
# volume_properties = "P1"
# size = "4 Gi" # for azurepremiumstorage please check Premium storage disk sizes here: https://learn.microsoft.com/en-us/azure/virtual-machines/premium-storage-performance
# }
private_networking = false
region = "australiaeast"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,15 @@ resource "biganimal_cluster" "single_node_cluster" {
storage = {
volume_type = "azurepremiumstorage"
volume_properties = "P1"
size = "4 Gi"
size = "4 Gi" # for azurepremiumstorage please check Premium storage disk sizes here: https://learn.microsoft.com/en-us/azure/virtual-machines/premium-storage-performance
}

# wal_storage = {
# volume_type = "azurepremiumstorage"
# volume_properties = "P1"
# size = "4 Gi" # for azurepremiumstorage please check Premium storage disk sizes here: https://learn.microsoft.com/en-us/azure/virtual-machines/premium-storage-performance
# }

pg_type = "epas" #valid values ["epas", "pgextended", "postgres]"
pg_version = "15"
cloud_provider = "azure"
Expand Down Expand Up @@ -100,8 +106,13 @@ resource "biganimal_faraway_replica" "faraway_replica" {
storage = {
volume_type = "azurepremiumstorage"
volume_properties = "P1"
size = "4 Gi"
size = "4 Gi" # for azurepremiumstorage please check Premium storage disk sizes here: https://learn.microsoft.com/en-us/azure/virtual-machines/premium-storage-performance
}
# wal_storage = {
# volume_type = "azurepremiumstorage"
# volume_properties = "P1"
# size = "4 Gi" # for azurepremiumstorage please check Premium storage disk sizes here: https://learn.microsoft.com/en-us/azure/virtual-machines/premium-storage-performance
# }
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: "Use a separate storage volume for Write-Ahead Logs (Recommended for high write workloads)",
Optional: true,
Attributes: map[string]schema.Attribute{
"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,
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\".",
Required: true,
},
},
}
1 change: 1 addition & 0 deletions pkg/provider/data_source_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,7 @@ func (c *clusterDataSource) Schema(ctx context.Context, req datasource.SchemaReq
MarkdownDescription: "Cluster connection service name.",
Computed: true,
},
"wal_storage": resourceWal,
},
}
}
Expand Down
1 change: 1 addition & 0 deletions pkg/provider/data_source_fareplica.go
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,7 @@ func (c *FAReplicaData) Schema(ctx context.Context, req datasource.SchemaRequest
},
},
},
"wal_storage": resourceWal,
},
}
}
Expand Down
1 change: 1 addition & 0 deletions pkg/provider/data_source_pgd.go
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,7 @@ func (p pgdDataSource) Schema(ctx context.Context, req datasource.SchemaRequest,
Description: "Is read-only connections enabled.",
Computed: true,
},
"wal_storage": resourceWal,
},
},
},
Expand Down
Loading

0 comments on commit 6504d0e

Please sign in to comment.