From ab5be950bbf4976165cd474db4466d796a797068 Mon Sep 17 00:00:00 2001 From: "PC-2NR0VQ3\\wai.wong" Date: Tue, 6 Aug 2024 13:43:00 +0100 Subject: [PATCH] feat: snapshot volume backup for faraway replica --- .../biganimal_faraway_replica/data-source.tf | 4 +++ .../biganimal_faraway_replica/aws/resource.tf | 2 ++ .../azure/resource.tf | 2 ++ .../cluster_and_faraway_replica/resource.tf | 4 +++ .../biganimal_faraway_replica/gcp/resource.tf | 2 ++ pkg/provider/data_source_fareplica.go | 30 +++++++++++++++++++ pkg/provider/resource_fareplica.go | 7 +++++ 7 files changed, 51 insertions(+) diff --git a/examples/data-sources/biganimal_faraway_replica/data-source.tf b/examples/data-sources/biganimal_faraway_replica/data-source.tf index f5abf3be..f968e3f5 100644 --- a/examples/data-sources/biganimal_faraway_replica/data-source.tf +++ b/examples/data-sources/biganimal_faraway_replica/data-source.tf @@ -96,3 +96,7 @@ output "resizing_pvc" { output "storage" { value = data.biganimal_faraway_replica.this.storage } + +output "storage" { + value = data.biganimal_faraway_replica.this.volume_snapshot_backup +} diff --git a/examples/resources/biganimal_faraway_replica/aws/resource.tf b/examples/resources/biganimal_faraway_replica/aws/resource.tf index 65c061dd..d0c46064 100644 --- a/examples/resources/biganimal_faraway_replica/aws/resource.tf +++ b/examples/resources/biganimal_faraway_replica/aws/resource.tf @@ -75,4 +75,6 @@ resource "biganimal_faraway_replica" "faraway_replica" { # transparent_data_encryption = { # key_id = # } + + volume_snapshot_backup = false } diff --git a/examples/resources/biganimal_faraway_replica/azure/resource.tf b/examples/resources/biganimal_faraway_replica/azure/resource.tf index 0784a82a..5b0ff6a3 100644 --- a/examples/resources/biganimal_faraway_replica/azure/resource.tf +++ b/examples/resources/biganimal_faraway_replica/azure/resource.tf @@ -76,4 +76,6 @@ resource "biganimal_faraway_replica" "faraway_replica" { # transparent_data_encryption = { # key_id = # } + + volume_snapshot_backup = false } diff --git a/examples/resources/biganimal_faraway_replica/cluster_and_faraway_replica/resource.tf b/examples/resources/biganimal_faraway_replica/cluster_and_faraway_replica/resource.tf index 1583bf84..175e85b3 100644 --- a/examples/resources/biganimal_faraway_replica/cluster_and_faraway_replica/resource.tf +++ b/examples/resources/biganimal_faraway_replica/cluster_and_faraway_replica/resource.tf @@ -53,6 +53,8 @@ resource "biganimal_cluster" "single_node_cluster" { # transparent_data_encryption = { # key_id = # } + + volume_snapshot_backup = false } output "password" { @@ -107,4 +109,6 @@ resource "biganimal_faraway_replica" "faraway_replica" { # transparent_data_encryption = { # key_id = # } + + volume_snapshot_backup = false } diff --git a/examples/resources/biganimal_faraway_replica/gcp/resource.tf b/examples/resources/biganimal_faraway_replica/gcp/resource.tf index 4f070bad..72f2dba8 100644 --- a/examples/resources/biganimal_faraway_replica/gcp/resource.tf +++ b/examples/resources/biganimal_faraway_replica/gcp/resource.tf @@ -79,4 +79,6 @@ resource "biganimal_faraway_replica" "faraway_replica" { # transparent_data_encryption = { # key_id = # } + + volume_snapshot_backup = false } diff --git a/pkg/provider/data_source_fareplica.go b/pkg/provider/data_source_fareplica.go index 7aa222e7..e30bba77 100644 --- a/pkg/provider/data_source_fareplica.go +++ b/pkg/provider/data_source_fareplica.go @@ -224,6 +224,36 @@ func (c *FAReplicaData) Schema(ctx context.Context, req datasource.SchemaRequest Description: "Cloud provider. For example, \"aws\", \"azure\", \"gcp\" or \"bah:aws\", \"bah:gcp\".", Computed: true, }, + "volume_snapshot_backup": schema.BoolAttribute{ + MarkdownDescription: "Enable to take a snapshot of the volume.", + Computed: true, + }, + "transparent_data_encryption": schema.SingleNestedAttribute{ + MarkdownDescription: "Transparent Data Encryption (TDE) key", + Optional: true, + Attributes: map[string]schema.Attribute{ + "key_id": schema.StringAttribute{ + MarkdownDescription: "Transparent Data Encryption (TDE) key ID.", + Required: true, + }, + "key_name": schema.StringAttribute{ + MarkdownDescription: "Key name.", + Computed: true, + }, + "status": schema.StringAttribute{ + MarkdownDescription: "Status.", + Computed: true, + }, + }, + }, + "pg_identity": schema.StringAttribute{ + MarkdownDescription: "PG Identity required to grant key permissions to activate the cluster.", + Computed: true, + }, + "transparent_data_encryption_action": schema.StringAttribute{ + MarkdownDescription: "Transparent data encryption action.", + Computed: true, + }, }, } } diff --git a/pkg/provider/resource_fareplica.go b/pkg/provider/resource_fareplica.go index 0c272951..c416b42d 100644 --- a/pkg/provider/resource_fareplica.go +++ b/pkg/provider/resource_fareplica.go @@ -61,6 +61,7 @@ type FAReplicaResourceModel struct { TransparentDataEncryption *TransparentDataEncryptionModel `tfsdk:"transparent_data_encryption"` PgIdentity types.String `tfsdk:"pg_identity"` TransparentDataEncryptionAction types.String `tfsdk:"transparent_data_encryption_action"` + VolumeSnapshot types.Bool `tfsdk:"volume_snapshot_backup"` Timeouts timeouts.Value `tfsdk:"timeouts"` } @@ -381,6 +382,11 @@ func (r *FAReplicaResource) Schema(ctx context.Context, req resource.SchemaReque Computed: true, PlanModifiers: []planmodifier.String{plan_modifier.CustomTDEAction()}, }, + "volume_snapshot_backup": schema.BoolAttribute{ + MarkdownDescription: "Enable to take a snapshot of the volume.", + Optional: true, + PlanModifiers: []planmodifier.Bool{boolplanmodifier.UseStateForUnknown()}, + }, }, } } @@ -594,6 +600,7 @@ func readFAReplica(ctx context.Context, client *api.ClusterClient, fAReplicaReso fAReplicaResourceModel.CloudProvider = types.StringValue(responseCluster.Provider.CloudProviderId) fAReplicaResourceModel.PgVersion = types.StringValue(responseCluster.PgVersion.PgVersionId) fAReplicaResourceModel.PgType = types.StringValue(responseCluster.PgType.PgTypeId) + fAReplicaResourceModel.VolumeSnapshot = types.BoolPointerValue(responseCluster.VolumeSnapshot) // 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{}