Skip to content

Commit

Permalink
feat: Support volume snapshot in TF
Browse files Browse the repository at this point in the history
  • Loading branch information
vishalsawale9 committed Jul 23, 2024
1 parent 8b1322c commit 25ea238
Show file tree
Hide file tree
Showing 13 changed files with 105 additions and 71 deletions.
2 changes: 2 additions & 0 deletions docs/resources/cluster.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ resource "biganimal_cluster" "single_node_cluster" {
pgvector = false
post_gis = false
pg_bouncer = {
is_enabled = false
# settings = [ # If is_enabled is true, remove the comment and enter the settings. Should you prefer something different from the defaults.
Expand Down Expand Up @@ -275,6 +276,7 @@ output "faraway_replica_ids" {
- `storage` (Block, Optional) Storage. (see [below for nested schema](#nestedblock--storage))
- `superuser_access` (Boolean) Enable to grant superuser access to the edb_admin role.
- `timeouts` (Block, Optional) (see [below for nested schema](#nestedblock--timeouts))
- `volume_snapshot_backup`(Boolean) Enable to take a snapshot of the volume.

### Read-Only

Expand Down
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 @@ -120,3 +120,7 @@ output "pe_allowed_principal_ids" {
output "service_account_ids" {
value = data.biganimal_cluster.this.service_account_ids
}

output "volume_snapshot_backup" {
value = coalesce(data.biganimal_cluster.this.post_gis, false)
}
19 changes: 10 additions & 9 deletions examples/resources/biganimal_cluster/ha/resource.tf
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,16 @@ resource "biganimal_cluster" "ha_cluster" {
start_time = "03:00"
}

pg_type = "epas"
pg_version = "15"
private_networking = false
cloud_provider = "aws"
read_only_connections = true
region = "us-east-1"
superuser_access = true
pgvector = false
post_gis = false
pg_type = "epas"
pg_version = "15"
private_networking = false
cloud_provider = "aws"
read_only_connections = true
region = "us-east-1"
superuser_access = true
pgvector = false
post_gis = false
volume_snapshot_backup = false

pg_bouncer = {
is_enabled = false
Expand Down
19 changes: 10 additions & 9 deletions examples/resources/biganimal_cluster/single_node/aws/resource.tf
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,16 @@ resource "biganimal_cluster" "single_node_cluster" {
start_time = "03:00"
}

pg_type = "epas"
pg_version = "15"
private_networking = false
cloud_provider = "aws"
read_only_connections = false
region = "us-east-1"
superuser_access = true
pgvector = false
post_gis = false
pg_type = "epas"
pg_version = "15"
private_networking = false
cloud_provider = "aws"
read_only_connections = false
region = "us-east-1"
superuser_access = true
pgvector = false
post_gis = false
volume_snapshot_backup = false

pg_bouncer = {
is_enabled = false
Expand Down
20 changes: 11 additions & 9 deletions examples/resources/biganimal_cluster/single_node/azure/resource.tf
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,17 @@ resource "biganimal_cluster" "single_node_cluster" {
start_time = "03:00"
}

pg_type = "epas"
pg_version = "15"
private_networking = false
cloud_provider = "azure"
read_only_connections = false
region = "eastus2"
superuser_access = true
pgvector = false
post_gis = false
pg_type = "epas"
pg_version = "15"
private_networking = false
cloud_provider = "azure"
read_only_connections = false
region = "eastus2"
superuser_access = true
pgvector = false
post_gis = false
volume_snapshot_backup = false


pg_bouncer = {
is_enabled = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,15 @@ resource "biganimal_cluster" "single_node_cluster" {
# <example_value>
# ]

pg_type = "epas"
pg_version = "15"
private_networking = false
cloud_provider = "bah:aws"
read_only_connections = false
region = "us-east-1"
pgvector = false
post_gis = false
pg_type = "epas"
pg_version = "15"
private_networking = false
cloud_provider = "bah:aws"
read_only_connections = false
region = "us-east-1"
pgvector = false
post_gis = false
volume_snapshot_backup = false

pg_bouncer = {
is_enabled = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,16 @@ resource "biganimal_cluster" "single_node_cluster" {
start_time = "03:00"
}

pg_type = "epas"
pg_version = "15"
private_networking = false
cloud_provider = "bah:azure"
read_only_connections = false
region = "eastus2"
pgvector = false
post_gis = false
pg_type = "epas"
pg_version = "15"
private_networking = false
cloud_provider = "bah:azure"
read_only_connections = false
region = "eastus2"
pgvector = false
post_gis = false
volume_snapshot_backup = false


pg_bouncer = {
is_enabled = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,16 @@ resource "biganimal_cluster" "single_node_cluster" {
# <only_needed_for_bah:gcp_clusters>
# ]

pg_type = "epas"
pg_version = "15"
private_networking = true
cloud_provider = "bah:gcp"
read_only_connections = false
region = "europe-west1"
pgvector = false
post_gis = false
pg_type = "epas"
pg_version = "15"
private_networking = true
cloud_provider = "bah:gcp"
read_only_connections = false
region = "europe-west1"
pgvector = false
post_gis = false
volume_snapshot_backup = false


pg_bouncer = {
is_enabled = false
Expand Down
20 changes: 11 additions & 9 deletions examples/resources/biganimal_cluster/single_node/gcp/resource.tf
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,17 @@ resource "biganimal_cluster" "single_node_cluster" {
start_time = "03:00"
}

pg_type = "epas"
pg_version = "15"
private_networking = false
cloud_provider = "gcp"
read_only_connections = false
region = "us-east1"
superuser_access = true
pgvector = false
post_gis = false
pg_type = "epas"
pg_version = "15"
private_networking = false
cloud_provider = "gcp"
read_only_connections = false
region = "us-east1"
superuser_access = true
pgvector = false
post_gis = false
volume_snapshot_backup = false


pg_bouncer = {
is_enabled = false
Expand Down
20 changes: 11 additions & 9 deletions examples/resources/biganimal_cluster/single_node/resource.tf
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,17 @@ resource "biganimal_cluster" "single_node_cluster" {
start_time = "03:00"
}

pg_type = "epas"
pg_version = "15"
private_networking = false
cloud_provider = "azure"
read_only_connections = false
region = "eastus2"
superuser_access = true
pgvector = false
post_gis = false
pg_type = "epas"
pg_version = "15"
private_networking = false
cloud_provider = "azure"
read_only_connections = false
region = "eastus2"
superuser_access = true
pgvector = false
post_gis = false
volume_snapshot_backup = false


pg_bouncer = {
is_enabled = false
Expand Down
1 change: 1 addition & 0 deletions pkg/models/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ type Cluster struct {
SuperuserAccess *bool `json:"superuserAccess,omitempty"`
Extensions *[]ClusterExtension `json:"extensions,omitempty"`
PgBouncer *PgBouncer `json:"pgBouncer,omitempty"`
VolumeSnapshot *bool `json:"volumeSnapshotBackup,omitempty"`
}

// IsHealthy checks to see if the cluster has the right condition 'biganimal.com/deployed'
Expand Down
6 changes: 6 additions & 0 deletions pkg/provider/data_source_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ type clusterDatasourceModel struct {
ServiceAccountIds types.Set `tfsdk:"service_account_ids"`
PeAllowedPrincipalIds types.Set `tfsdk:"pe_allowed_principal_ids"`
SuperuserAccess types.Bool `tfsdk:"superuser_access"`
VolumeSnapshot types.Bool `tfsdk:"volume_snapshot_backup"`
}

type AllowedIpRangesDatasourceModel struct {
Expand Down Expand Up @@ -379,6 +380,10 @@ func (c *clusterDataSource) Schema(ctx context.Context, req datasource.SchemaReq
Description: "Pause cluster. If true it will put the cluster on pause and set the phase as paused, if false it will resume the cluster and set the phase as healthy",
Optional: true,
},
"volume_snapshot_backup": schema.BoolAttribute{
MarkdownDescription: "Volume snapshot.",
Optional: true,
},
},
}
}
Expand Down Expand Up @@ -442,6 +447,7 @@ func (c *clusterDataSource) Read(ctx context.Context, req datasource.ReadRequest
data.PgType = types.StringValue(cluster.PgType.PgTypeId)
data.PrivateNetworking = types.BoolPointerValue(cluster.PrivateNetworking)
data.SuperuserAccess = types.BoolPointerValue(cluster.SuperuserAccess)
data.VolumeSnapshot = types.BoolPointerValue(cluster.VolumeSnapshot)

if cluster.FarawayReplicaIds != nil {
data.FarawayReplicaIds = *cluster.FarawayReplicaIds
Expand Down
12 changes: 10 additions & 2 deletions pkg/provider/resource_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ type ClusterResourceModel struct {
PostGIS types.Bool `tfsdk:"post_gis"`
PgBouncer *PgBouncerModel `tfsdk:"pg_bouncer"`
Pause types.Bool `tfsdk:"pause"`

Timeouts timeouts.Value `tfsdk:"timeouts"`
Timeouts timeouts.Value `tfsdk:"timeouts"`
VolumeSnapshot types.Bool `tfsdk:"volume_snapshot_backup"`
}

type ClusterArchitectureResourceModel struct {
Expand Down Expand Up @@ -423,6 +423,12 @@ func (c *clusterResource) Schema(ctx context.Context, req resource.SchemaRequest
Optional: true,
Computed: true,
},
"volume_snapshot_backup": schema.BoolAttribute{
MarkdownDescription: "Enable to take a snapshot of the volume.",
Optional: true,
Computed: true,
PlanModifiers: []planmodifier.Bool{boolplanmodifier.UseStateForUnknown()},
},
"pgvector": schema.BoolAttribute{
MarkdownDescription: "Is pgvector extension enabled. Adds support for vector storage and vector similarity search to Postgres.",
Optional: true,
Expand Down Expand Up @@ -751,6 +757,7 @@ func (c *clusterResource) read(ctx context.Context, tfClusterResource *ClusterRe
tfClusterResource.FarawayReplicaIds = StringSliceToSet(apiCluster.FarawayReplicaIds)
tfClusterResource.PrivateNetworking = types.BoolPointerValue(apiCluster.PrivateNetworking)
tfClusterResource.SuperuserAccess = types.BoolPointerValue(apiCluster.SuperuserAccess)
tfClusterResource.VolumeSnapshot = types.BoolPointerValue(apiCluster.VolumeSnapshot)
if apiCluster.Extensions != nil {
for _, v := range *apiCluster.Extensions {
if v.Enabled && v.ExtensionId == "pgvector" {
Expand Down Expand Up @@ -970,6 +977,7 @@ func generateGenericClusterModel(clusterResource ClusterResourceModel) models.Cl
ReadOnlyConnections: clusterResource.ReadOnlyConnections.ValueBoolPointer(),
BackupRetentionPeriod: clusterResource.BackupRetentionPeriod.ValueStringPointer(),
SuperuserAccess: clusterResource.SuperuserAccess.ValueBoolPointer(),
VolumeSnapshot: clusterResource.VolumeSnapshot.ValueBoolPointer(),
}

cluster.Extensions = &[]models.ClusterExtension{}
Expand Down

0 comments on commit 25ea238

Please sign in to comment.