From 4bb809d75a06a3c7629f420d88eef4195adb5743 Mon Sep 17 00:00:00 2001 From: "PC-2NR0VQ3\\wai.wong" Date: Wed, 29 Nov 2023 11:07:55 +0000 Subject: [PATCH 01/16] feat: restore pg cluster implementation --- docs/data-sources/cluster.md | 5 + docs/resources/cluster.md | 16 +++- .../biganimal_cluster/ha/resource.tf | 3 + .../single_node/aws/resource.tf | 3 + .../single_node/azure/resource.tf | 3 + .../single_node/bah_aws/resource.tf | 3 + .../single_node/bah_azure/resource.tf | 4 + .../single_node/bah_gcp/resource.tf | 3 + .../single_node/gcp/resource.tf | 3 + .../biganimal_cluster/single_node/resource.tf | 3 + pkg/api/cluster_client.go | 67 +++++++++++++- pkg/models/restore_cluster.go | 27 ++++++ pkg/plan_modifier/restore_cluster_id.go | 42 +++++++++ pkg/provider/resource_cluster.go | 91 ++++++++++++++++--- 14 files changed, 257 insertions(+), 16 deletions(-) create mode 100644 pkg/models/restore_cluster.go create mode 100644 pkg/plan_modifier/restore_cluster_id.go diff --git a/docs/data-sources/cluster.md b/docs/data-sources/cluster.md index 5b756e5b..31a2804e 100644 --- a/docs/data-sources/cluster.md +++ b/docs/data-sources/cluster.md @@ -106,6 +106,10 @@ output "superuser_access" { value = coalesce(data.biganimal_cluster.this.superuser_access, false) } +output "pgvector" { + value = coalesce(data.biganimal_cluster.this.pgvector, false) +} + output "faraway_replica_ids" { value = data.biganimal_cluster.this.faraway_replica_ids } @@ -156,6 +160,7 @@ output "service_account_ids" { - `pg_config` (Attributes Set) Database configuration parameters. (see [below for nested schema](#nestedatt--pg_config)) - `pg_type` (String) Postgres type. - `pg_version` (String) Postgres version. +- `pgvector` (Boolean) Is pgvector extension enabled. Adds support for vector storage and vector similarity search to Postgres. - `phase` (String) Current phase of the cluster. - `private_networking` (Boolean) Is private networking enabled. - `read_only_connections` (Boolean) Is read only connection enabled. diff --git a/docs/resources/cluster.md b/docs/resources/cluster.md index 754b07c4..e34988ec 100644 --- a/docs/resources/cluster.md +++ b/docs/resources/cluster.md @@ -90,6 +90,10 @@ resource "biganimal_cluster" "single_node_cluster" { read_only_connections = false region = "eastus2" superuser_access = true + pgvector = true + # restore_cluster_id = "p-123456789" # uncomment to restore cluster + # restore_from_deleted = true + # restore_point = "2006-01-02T15:04:05-0700" } output "password" { @@ -184,6 +188,10 @@ resource "biganimal_cluster" "ha_cluster" { read_only_connections = true region = "us-east-1" superuser_access = true + pgvector = true + # restore_cluster_id = "p-123456789" # uncomment to restore cluster + # restore_from_deleted = true + # restore_point = "2006-01-02T15:04:05-0700" } output "password" { @@ -224,11 +232,17 @@ output "faraway_replica_ids" { - `backup_retention_period` (String) Backup retention period. For example, "7d", "2w", or "3m". - `cluster_architecture` (Block, Optional) Cluster architecture. See [Supported cluster types](https://www.enterprisedb.com/docs/biganimal/latest/overview/02_high_availability/) for details. (see [below for nested schema](#nestedblock--cluster_architecture)) - `csp_auth` (Boolean) Is authentication handled by the cloud service provider. Available for AWS only, See [Authentication](https://www.enterprisedb.com/docs/biganimal/latest/getting_started/creating_a_cluster/#authentication) for details. +- `import_from_deleted` (Boolean) Used by import function only to import a deleted cluster - `maintenance_window` (Attributes) Custom maintenance window. (see [below for nested schema](#nestedatt--maintenance_window)) +- `most_recent` (Boolean) Show the most recent cluster when there are multiple clusters with the same name. - `pe_allowed_principal_ids` (Set of String) Cloud provider subscription/account ID, need to be specified when cluster is deployed on BigAnimal's cloud account. - `pg_config` (Block Set) 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. (see [below for nested schema](#nestedblock--pg_config)) +- `pgvector` (Boolean) Is pgvector extension enabled. Adds support for vector storage and vector similarity search to Postgres. - `private_networking` (Boolean) Is private networking enabled. - `read_only_connections` (Boolean) Is read only connection enabled. +- `restore_cluster_id` (String) For restoring a cluster. Specifies the cluster id to restore +- `restore_from_deleted` (Boolean) For restoring a cluster. Specifies if the cluster you want to restore is deleted +- `restore_point` (String) For restoring a cluster. Specifies restore point e.g. 2006-01-02T15:04:05-0700. Leave empty to restore from latest point - `service_account_ids` (Set of String) A Google Cloud Service Account is used for logs. If you leave this blank, then you will be unable to access log details for this cluster. Required when cluster is deployed on BigAnimal's cloud account. - `storage` (Block, Optional) Storage. (see [below for nested schema](#nestedblock--storage)) - `superuser_access` (Boolean) Enable to grant superuser access to the edb_admin role. @@ -269,7 +283,7 @@ Required: - `id` (String) Cluster architecture ID. For example, "single" or "ha".For Extreme High Availability clusters, please use the [biganimal_pgd](https://registry.terraform.io/providers/EnterpriseDB/biganimal/latest/docs/resources/pgd) resource. - `nodes` (Number) Node count. -Read-Only: +Optional: - `name` (String) Name. diff --git a/examples/resources/biganimal_cluster/ha/resource.tf b/examples/resources/biganimal_cluster/ha/resource.tf index d70137e4..c9a01e0f 100644 --- a/examples/resources/biganimal_cluster/ha/resource.tf +++ b/examples/resources/biganimal_cluster/ha/resource.tf @@ -79,6 +79,9 @@ resource "biganimal_cluster" "ha_cluster" { region = "us-east-1" superuser_access = true pgvector = true + # restore_cluster_id = "p-123456789" # uncomment to restore cluster + # restore_from_deleted = true + # restore_point = "2006-01-02T15:04:05-0700" } output "password" { diff --git a/examples/resources/biganimal_cluster/single_node/aws/resource.tf b/examples/resources/biganimal_cluster/single_node/aws/resource.tf index cb251fa5..afd7943e 100644 --- a/examples/resources/biganimal_cluster/single_node/aws/resource.tf +++ b/examples/resources/biganimal_cluster/single_node/aws/resource.tf @@ -80,6 +80,9 @@ resource "biganimal_cluster" "single_node_cluster" { region = "us-east-1" superuser_access = true pgvector = true + # restore_cluster_id = "p-123456789" # uncomment to restore cluster + # restore_from_deleted = true + # restore_point = "2006-01-02T15:04:05-0700" } output "password" { diff --git a/examples/resources/biganimal_cluster/single_node/azure/resource.tf b/examples/resources/biganimal_cluster/single_node/azure/resource.tf index 7254ac99..378d2da9 100644 --- a/examples/resources/biganimal_cluster/single_node/azure/resource.tf +++ b/examples/resources/biganimal_cluster/single_node/azure/resource.tf @@ -80,6 +80,9 @@ resource "biganimal_cluster" "single_node_cluster" { region = "eastus2" superuser_access = true pgvector = true + # restore_cluster_id = "p-123456789" # uncomment to restore cluster + # restore_from_deleted = true + # restore_point = "2006-01-02T15:04:05-0700" } output "password" { diff --git a/examples/resources/biganimal_cluster/single_node/bah_aws/resource.tf b/examples/resources/biganimal_cluster/single_node/bah_aws/resource.tf index 52bf3b4b..cc718560 100644 --- a/examples/resources/biganimal_cluster/single_node/bah_aws/resource.tf +++ b/examples/resources/biganimal_cluster/single_node/bah_aws/resource.tf @@ -78,6 +78,9 @@ resource "biganimal_cluster" "single_node_cluster" { read_only_connections = false region = "us-east-1" pgvector = true + # restore_cluster_id = "p-123456789" # uncomment to restore cluster + # restore_from_deleted = true + # restore_point = "2006-01-02T15:04:05-0700" } output "password" { diff --git a/examples/resources/biganimal_cluster/single_node/bah_azure/resource.tf b/examples/resources/biganimal_cluster/single_node/bah_azure/resource.tf index de8e18d1..0ef3af1b 100644 --- a/examples/resources/biganimal_cluster/single_node/bah_azure/resource.tf +++ b/examples/resources/biganimal_cluster/single_node/bah_azure/resource.tf @@ -79,6 +79,10 @@ resource "biganimal_cluster" "single_node_cluster" { read_only_connections = false region = "eastus2" pgvector = true + # restore_cluster_id = "p-123456789" # uncomment to restore cluster + # restore_from_deleted = true + # restore_point = "2006-01-02T15:04:05-0700" + # pe_allowed_principal_ids = [ # # ex: "9334e5e6-7f47-aE61-5A4F-ee067daeEf4A" # ] diff --git a/examples/resources/biganimal_cluster/single_node/bah_gcp/resource.tf b/examples/resources/biganimal_cluster/single_node/bah_gcp/resource.tf index f4a45453..42de8549 100644 --- a/examples/resources/biganimal_cluster/single_node/bah_gcp/resource.tf +++ b/examples/resources/biganimal_cluster/single_node/bah_gcp/resource.tf @@ -72,6 +72,9 @@ resource "biganimal_cluster" "single_node_cluster" { read_only_connections = false region = "europe-west1" pgvector = true + # restore_cluster_id = "p-123456789" # uncomment to restore cluster + # restore_from_deleted = true + # restore_point = "2006-01-02T15:04:05-0700" } output "password" { diff --git a/examples/resources/biganimal_cluster/single_node/gcp/resource.tf b/examples/resources/biganimal_cluster/single_node/gcp/resource.tf index a25db34a..5f215a93 100644 --- a/examples/resources/biganimal_cluster/single_node/gcp/resource.tf +++ b/examples/resources/biganimal_cluster/single_node/gcp/resource.tf @@ -80,6 +80,9 @@ resource "biganimal_cluster" "single_node_cluster" { region = "us-east1" superuser_access = true pgvector = true + # restore_cluster_id = "p-123456789" # uncomment to restore cluster + # restore_from_deleted = true + # restore_point = "2006-01-02T15:04:05-0700" } output "password" { diff --git a/examples/resources/biganimal_cluster/single_node/resource.tf b/examples/resources/biganimal_cluster/single_node/resource.tf index 7254ac99..378d2da9 100644 --- a/examples/resources/biganimal_cluster/single_node/resource.tf +++ b/examples/resources/biganimal_cluster/single_node/resource.tf @@ -80,6 +80,9 @@ resource "biganimal_cluster" "single_node_cluster" { region = "eastus2" superuser_access = true pgvector = true + # restore_cluster_id = "p-123456789" # uncomment to restore cluster + # restore_from_deleted = true + # restore_point = "2006-01-02T15:04:05-0700" } output "password" { diff --git a/pkg/api/cluster_client.go b/pkg/api/cluster_client.go index bd688a7b..1ace84fb 100644 --- a/pkg/api/cluster_client.go +++ b/pkg/api/cluster_client.go @@ -40,7 +40,6 @@ func (c ClusterClient) Create(ctx context.Context, projectId string, model any) url := fmt.Sprintf("projects/%s/clusters", projectId) body, err := c.doRequest(ctx, http.MethodPost, url, bytes.NewBuffer(b)) - if err != nil { return "", err } @@ -49,6 +48,22 @@ func (c ClusterClient) Create(ctx context.Context, projectId string, model any) return response.Data.ClusterId, err } +func (c ClusterClient) ReadDeletedCluster(ctx context.Context, projectId, id string) (*models.Cluster, error) { + response := struct { + Data models.Cluster `json:"data"` + }{} + + url := fmt.Sprintf("projects/%s/deleted-clusters/%s", projectId, id) + body, err := c.doRequest(ctx, http.MethodGet, url, nil) + if err != nil { + return &response.Data, err + } + + err = json.Unmarshal(body, &response) + + return &response.Data, err +} + func (c ClusterClient) Read(ctx context.Context, projectId, id string) (*models.Cluster, error) { response := struct { Data models.Cluster `json:"data"` @@ -73,18 +88,18 @@ func (c ClusterClient) ReadByName(ctx context.Context, projectId, name string, m url := fmt.Sprintf("projects/%s/clusters?name=%s", projectId, name) body, err := c.doRequest(ctx, http.MethodGet, url, nil) if err != nil { - return &models.Cluster{}, err + return nil, err } if err := json.Unmarshal(body, &clusters); err != nil { - return &models.Cluster{}, err + return nil, err } if len(clusters.Data) != 1 { if most_recent { sort.Slice(clusters.Data, func(i, j int) bool { return clusters.Data[i].CreatedAt.Seconds > clusters.Data[j].CreatedAt.Seconds }) } else { - return &models.Cluster{}, ErrorClustersSameName + return nil, ErrorClustersSameName } } @@ -175,3 +190,47 @@ func (c ClusterClient) GetPeAllowedPrincipalIds(ctx context.Context, projectID s } return &response.Data, nil } + +func (c ClusterClient) RestoreCluster(ctx context.Context, projectId, clusterId string, model models.RestoreCluster) (string, error) { + response := struct { + Data struct { + ClusterId string `json:"clusterId"` + } `json:"data"` + }{} + + b, err := json.Marshal(model) + if err != nil { + return "", err + } + + url := fmt.Sprintf("projects/%s/clusters/%s/restore", projectId, clusterId) + body, err := c.doRequest(ctx, http.MethodPost, url, bytes.NewBuffer(b)) + if err != nil { + return "", err + } + + err = json.Unmarshal(body, &response) + return response.Data.ClusterId, err +} + +func (c ClusterClient) RestoreClusterFromDeleted(ctx context.Context, projectId, clusterId string, model models.RestoreCluster) (string, error) { + response := struct { + Data struct { + ClusterId string `json:"clusterId"` + } `json:"data"` + }{} + + b, err := json.Marshal(model) + if err != nil { + return "", err + } + + url := fmt.Sprintf("projects/%s/deleted-clusters/%s/restore", projectId, clusterId) + body, err := c.doRequest(ctx, http.MethodPost, url, bytes.NewBuffer(b)) + if err != nil { + return "", err + } + + err = json.Unmarshal(body, &response) + return response.Data.ClusterId, err +} diff --git a/pkg/models/restore_cluster.go b/pkg/models/restore_cluster.go new file mode 100644 index 00000000..8dc0f476 --- /dev/null +++ b/pkg/models/restore_cluster.go @@ -0,0 +1,27 @@ +package models + +import ( + commonApi "github.com/EnterpriseDB/terraform-provider-biganimal/pkg/models/common/api" +) + +type RestoreCluster struct { + AllowedIpRanges *[]AllowedIpRange `json:"allowedIpRanges,omitempty"` + BackupRetentionPeriod *string `json:"backupRetentionPeriod,omitempty"` + ClusterArchitecture *Architecture `json:"clusterArchitecture,omitempty" mapstructure:"cluster_architecture"` + ClusterName *string `json:"clusterName,omitempty"` + ClusterType *string `json:"clusterType,omitempty"` + CSPAuth *bool `json:"cspAuth,omitempty"` + InstanceType *InstanceType `json:"instanceType,omitempty"` + Password *string `json:"password,omitempty"` + PgConfig *[]KeyValue `json:"pgConfig,omitempty"` + Phase *string `json:"phase,omitempty"` + ReadOnlyConnections *bool `json:"readOnlyConnections,omitempty"` + Region *Region `json:"region,omitempty"` + ResizingPvc []string `json:"resizingPvc,omitempty"` + Storage *Storage `json:"storage,omitempty"` + MaintenanceWindow *commonApi.MaintenanceWindow `json:"maintenanceWindow,omitempty"` + ServiceAccountIds *[]string `json:"serviceAccountIds,omitempty"` + PeAllowedPrincipalIds *[]string `json:"peAllowedPrincipalIds,omitempty"` + SuperuserAccess *bool `json:"superuserAccess,omitempty"` + RestorePoint *string `json:"selectedRestorePointInTime,omitempty"` +} diff --git a/pkg/plan_modifier/restore_cluster_id.go b/pkg/plan_modifier/restore_cluster_id.go new file mode 100644 index 00000000..b5e8d0a4 --- /dev/null +++ b/pkg/plan_modifier/restore_cluster_id.go @@ -0,0 +1,42 @@ +package plan_modifier + +import ( + "context" + + "github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier" +) + +// CustomRestoreClusterId returns a plan modifier that copies a known prior state +// value into the planned value. Use this when it is known that an unconfigured +// value will remain the same after a resource update. +// +// To prevent Terraform errors, the framework automatically sets unconfigured +// and Computed attributes to an unknown value "(known after apply)" on update. +// Using this plan modifier will instead display the prior state value in the +// plan, unless a prior plan modifier adjusts the value. +func CustomRestoreClusterId() planmodifier.String { + return customRestoreClusterIdModifier{} +} + +// customRestoreClusterIdModifier implements the plan modifier. +type customRestoreClusterIdModifier struct{} + +// Description returns a human-readable description of the plan modifier. +func (m customRestoreClusterIdModifier) Description(_ context.Context) string { + return "Once set, the value of this attribute in state will not change." +} + +// MarkdownDescription returns a markdown description of the plan modifier. +func (m customRestoreClusterIdModifier) MarkdownDescription(_ context.Context) string { + return "Once set, the value of this attribute in state will not change." +} + +// PlanModifyString implements the plan modification logic. +func (m customRestoreClusterIdModifier) PlanModifyString(ctx context.Context, req planmodifier.StringRequest, resp *planmodifier.StringResponse) { + if !req.PlanValue.IsNull() { + resp.Diagnostics.AddWarning( + "You are restoring a cluster", + "You are restoring a cluster. After restoring the cluster, please remove field 'restore_cluster_id' and optionally remove fields 'restore_from_deleted' and 'restore_point' from the config", + ) + } +} diff --git a/pkg/provider/resource_cluster.go b/pkg/provider/resource_cluster.go index d6b4cee4..826b9e15 100644 --- a/pkg/provider/resource_cluster.go +++ b/pkg/provider/resource_cluster.go @@ -69,8 +69,12 @@ type ClusterResourceModel struct { ServiceAccountIds types.Set `tfsdk:"service_account_ids"` PeAllowedPrincipalIds types.Set `tfsdk:"pe_allowed_principal_ids"` SuperuserAccess types.Bool `tfsdk:"superuser_access"` - FromDeleted *bool `tfsdk:"from_deleted"` + ImportFromDeleted types.Bool `tfsdk:"import_from_deleted"` + RestoreFromDeleted *bool `tfsdk:"restore_from_deleted"` + RestoreClusterId *string `tfsdk:"restore_cluster_id"` + RestorePoint types.String `tfsdk:"restore_point"` Pgvector types.Bool `tfsdk:"pgvector"` + MostRecent types.Bool `tfsdk:"most_recent"` Timeouts timeouts.Value `tfsdk:"timeouts"` } @@ -238,6 +242,10 @@ func (c *clusterResource) Schema(ctx context.Context, req resource.SchemaRequest MarkdownDescription: "Name of the cluster.", Required: true, }, + "most_recent": schema.BoolAttribute{ + MarkdownDescription: "Show the most recent cluster when there are multiple clusters with the same name.", + Optional: true, + }, "phase": schema.StringAttribute{ MarkdownDescription: "Current phase of the cluster.", Computed: true, @@ -393,10 +401,23 @@ func (c *clusterResource) Schema(ctx context.Context, req resource.SchemaRequest Optional: true, Computed: true, }, - "from_deleted": schema.BoolAttribute{ + "import_from_deleted": schema.BoolAttribute{ + Description: "Used by import function only to import a deleted cluster", + Optional: true, + }, + "restore_from_deleted": schema.BoolAttribute{ Description: "For restoring a cluster. Specifies if the cluster you want to restore is deleted", Optional: true, }, + "restore_cluster_id": schema.StringAttribute{ + Description: "For restoring a cluster. Specifies the cluster id to restore", + Optional: true, + PlanModifiers: []planmodifier.String{plan_modifier.CustomRestoreClusterId()}, + }, + "restore_point": schema.StringAttribute{ + Description: "For restoring a cluster. Specifies restore point e.g. 2006-01-02T15:04:05-0700. Leave empty to restore from latest point", + Optional: true, + }, "pgvector": schema.BoolAttribute{ MarkdownDescription: "Is pgvector extension enabled. Adds support for vector storage and vector similarity search to Postgres.", Optional: true, @@ -424,12 +445,45 @@ func (c *clusterResource) Create(ctx context.Context, req resource.CreateRequest return } - clusterId, err := c.client.Create(ctx, config.ProjectId, clusterModel) - if err != nil { - if !appendDiagFromBAErr(err, &resp.Diagnostics) { - resp.Diagnostics.AddError("Error creating cluster API request", err.Error()) + var clusterId string + + if config.RestoreClusterId != nil { + var restoreModel models.RestoreCluster + err := utils.CopyObjectJson(clusterModel, &restoreModel) + if err != nil { + if !appendDiagFromBAErr(err, &resp.Diagnostics) { + resp.Diagnostics.AddError("Error copy object json in restore cluster API request", err.Error()) + } + return } - return + + if config.RestoreFromDeleted != nil && *config.RestoreFromDeleted { + clusterId, err = c.client.RestoreClusterFromDeleted(ctx, config.ProjectId, *config.RestoreClusterId, restoreModel) + if err != nil { + if !appendDiagFromBAErr(err, &resp.Diagnostics) { + resp.Diagnostics.AddError("Error restore cluster API request", err.Error()) + } + return + } + } else { + clusterId, err = c.client.RestoreCluster(ctx, config.ProjectId, *config.RestoreClusterId, restoreModel) + if err != nil { + if !appendDiagFromBAErr(err, &resp.Diagnostics) { + resp.Diagnostics.AddError("Error restore cluster API request", err.Error()) + } + return + } + } + + } else { + clusterId, err = c.client.Create(ctx, config.ProjectId, clusterModel) + if err != nil { + if !appendDiagFromBAErr(err, &resp.Diagnostics) { + resp.Diagnostics.AddError("Error creating cluster API request", err.Error()) + } + return + } + } config.ClusterId = &clusterId @@ -537,7 +591,7 @@ func (c *clusterResource) Delete(ctx context.Context, req resource.DeleteRequest func (c *clusterResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { idParts := strings.Split(req.ID, "/") - if len(idParts) != 2 || idParts[0] == "" || idParts[1] == "" { + if len(idParts) < 2 || idParts[0] == "" || idParts[1] == "" { resp.Diagnostics.AddError( "Unexpected Import Identifier", fmt.Sprintf("Expected import identifier with format: project_id/cluster_id. Got: %q", req.ID), @@ -547,12 +601,27 @@ func (c *clusterResource) ImportState(ctx context.Context, req resource.ImportSt resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("project_id"), idParts[0])...) resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("cluster_id"), idParts[1])...) + + if len(idParts) > 2 && idParts[2] == "import-from-deleted" { + resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("import_from_deleted"), true)...) + } } func (c *clusterResource) read(ctx context.Context, clusterResource *ClusterResourceModel) error { - cluster, err := c.client.Read(ctx, clusterResource.ProjectId, *clusterResource.ClusterId) - if err != nil { - return err + var cluster *models.Cluster + + if clusterResource.ImportFromDeleted.ValueBool() { + deletedCluster, err := c.client.ReadDeletedCluster(ctx, clusterResource.ProjectId, *clusterResource.ClusterId) + if err != nil { + return err + } + cluster = deletedCluster + } else { + existingCluster, err := c.client.Read(ctx, clusterResource.ProjectId, *clusterResource.ClusterId) + if err != nil { + return err + } + cluster = existingCluster } connection, err := c.client.ConnectionString(ctx, clusterResource.ProjectId, *clusterResource.ClusterId) From 5985e491a668adf0ed00991786a870f9a18fbe76 Mon Sep 17 00:00:00 2001 From: "PC-2NR0VQ3\\wai.wong" Date: Mon, 4 Dec 2023 13:55:31 +0000 Subject: [PATCH 02/16] fix: remove from_deleted field from pgd --- pkg/provider/resource_pgd.go | 4 ---- 1 file changed, 4 deletions(-) diff --git a/pkg/provider/resource_pgd.go b/pkg/provider/resource_pgd.go index fd441757..5fb7b84a 100644 --- a/pkg/provider/resource_pgd.go +++ b/pkg/provider/resource_pgd.go @@ -82,10 +82,6 @@ func PgdSchema(ctx context.Context) schema.Schema { Description: "Show the most recent cluster when there are multiple clusters with the same name", Optional: true, }, - "from_deleted": schema.BoolAttribute{ - Description: "For restoring a cluster. Specifies if the cluster you want to restore is deleted", - Optional: true, - }, "password": schema.StringAttribute{ Description: "Password for the user edb_admin. It must be 12 characters or more.", Required: true, From 015c9eacc27da8c06047112ea422b7ccc1367947 Mon Sep 17 00:00:00 2001 From: "PC-2NR0VQ3\\wai.wong" Date: Mon, 4 Dec 2023 15:06:53 +0000 Subject: [PATCH 03/16] fix: spell check fix --- .wordlist-en-custom.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/.wordlist-en-custom.txt b/.wordlist-en-custom.txt index ce8d6750..01e263ea 100644 --- a/.wordlist-en-custom.txt +++ b/.wordlist-en-custom.txt @@ -8,6 +8,7 @@ IAM IOPS InstanceType MPL +pgvector PGD Postgres aws From 62d07c25ee5f6164527b0cb1c03af9b2399d7adb Mon Sep 17 00:00:00 2001 From: "PC-2NR0VQ3\\wai.wong" Date: Mon, 4 Dec 2023 15:47:25 +0000 Subject: [PATCH 04/16] fix: update hashicorp/random to 3.6.0 --- docs/resources/cluster.md | 4 ++-- docs/resources/faraway_replica.md | 4 ++-- docs/resources/pgd.md | 24 +++++++++---------- docs/resources/project.md | 2 +- .../biganimal_cluster/ha/resource.tf | 2 +- .../single_node/aws/resource.tf | 2 +- .../single_node/azure/resource.tf | 2 +- .../single_node/bah_aws/resource.tf | 2 +- .../single_node/bah_azure/resource.tf | 2 +- .../single_node/gcp/resource.tf | 2 +- .../biganimal_cluster/single_node/resource.tf | 2 +- .../biganimal_faraway_replica/aws/resource.tf | 2 +- .../azure/resource.tf | 2 +- .../cluster_and_faraway_replica/resource.tf | 2 +- .../biganimal_faraway_replica/gcp/resource.tf | 2 +- .../biganimal_faraway_replica/resource.tf | 2 +- .../aws/bah_data_group/resource.tf | 2 +- .../resource.tf | 2 +- .../biganimal_pgd/aws/data_group/resource.tf | 2 +- .../resource.tf | 2 +- .../azure/bah_data_group/resource.tf | 2 +- .../resource.tf | 2 +- .../azure/data_group/resource.tf | 2 +- .../resource.tf | 2 +- .../gcp/bah_data_group/resource.tf | 2 +- .../resource.tf | 2 +- .../biganimal_pgd/gcp/data_group/resource.tf | 2 +- .../resource.tf | 2 +- .../resources/biganimal_project/resource.tf | 2 +- 29 files changed, 42 insertions(+), 42 deletions(-) diff --git a/docs/resources/cluster.md b/docs/resources/cluster.md index e34988ec..59a01bfa 100644 --- a/docs/resources/cluster.md +++ b/docs/resources/cluster.md @@ -17,7 +17,7 @@ terraform { } random = { source = "hashicorp/random" - version = "3.5.1" + version = "3.6.0" } } } @@ -116,7 +116,7 @@ terraform { } random = { source = "hashicorp/random" - version = "3.5.1" + version = "3.6.0" } } } diff --git a/docs/resources/faraway_replica.md b/docs/resources/faraway_replica.md index 5a472161..63022389 100644 --- a/docs/resources/faraway_replica.md +++ b/docs/resources/faraway_replica.md @@ -13,7 +13,7 @@ terraform { } random = { source = "hashicorp/random" - version = "3.5.1" + version = "3.6.0" } } } @@ -106,7 +106,7 @@ terraform { } random = { source = "hashicorp/random" - version = "3.5.1" + version = "3.6.0" } } } diff --git a/docs/resources/pgd.md b/docs/resources/pgd.md index 8ee6b31d..b15b8e1e 100644 --- a/docs/resources/pgd.md +++ b/docs/resources/pgd.md @@ -14,7 +14,7 @@ terraform { } random = { source = "hashicorp/random" - version = "3.5.1" + version = "3.6.0" } } } @@ -113,7 +113,7 @@ terraform { } random = { source = "hashicorp/random" - version = "3.5.1" + version = "3.6.0" } } } @@ -281,7 +281,7 @@ terraform { } random = { source = "hashicorp/random" - version = "3.5.1" + version = "3.6.0" } } } @@ -383,7 +383,7 @@ terraform { } random = { source = "hashicorp/random" - version = "3.5.1" + version = "3.6.0" } } } @@ -557,7 +557,7 @@ terraform { } random = { source = "hashicorp/random" - version = "3.5.1" + version = "3.6.0" } } } @@ -656,7 +656,7 @@ terraform { } random = { source = "hashicorp/random" - version = "3.5.1" + version = "3.6.0" } } } @@ -824,7 +824,7 @@ terraform { } random = { source = "hashicorp/random" - version = "3.5.1" + version = "3.6.0" } } } @@ -926,7 +926,7 @@ terraform { } random = { source = "hashicorp/random" - version = "3.5.1" + version = "3.6.0" } } } @@ -1100,7 +1100,7 @@ terraform { } random = { source = "hashicorp/random" - version = "3.5.1" + version = "3.6.0" } } } @@ -1199,7 +1199,7 @@ terraform { } random = { source = "hashicorp/random" - version = "3.5.1" + version = "3.6.0" } } } @@ -1367,7 +1367,7 @@ terraform { } random = { source = "hashicorp/random" - version = "3.5.1" + version = "3.6.0" } } } @@ -1473,7 +1473,7 @@ terraform { } random = { source = "hashicorp/random" - version = "3.5.1" + version = "3.6.0" } } } diff --git a/docs/resources/project.md b/docs/resources/project.md index 3273d4a8..20d2d1b5 100644 --- a/docs/resources/project.md +++ b/docs/resources/project.md @@ -24,7 +24,7 @@ terraform { } random = { source = "hashicorp/random" - version = "3.5.1" + version = "3.6.0" } } } diff --git a/examples/resources/biganimal_cluster/ha/resource.tf b/examples/resources/biganimal_cluster/ha/resource.tf index c9a01e0f..4f58279f 100644 --- a/examples/resources/biganimal_cluster/ha/resource.tf +++ b/examples/resources/biganimal_cluster/ha/resource.tf @@ -6,7 +6,7 @@ terraform { } random = { source = "hashicorp/random" - version = "3.5.1" + version = "3.6.0" } } } diff --git a/examples/resources/biganimal_cluster/single_node/aws/resource.tf b/examples/resources/biganimal_cluster/single_node/aws/resource.tf index afd7943e..124f3b32 100644 --- a/examples/resources/biganimal_cluster/single_node/aws/resource.tf +++ b/examples/resources/biganimal_cluster/single_node/aws/resource.tf @@ -6,7 +6,7 @@ terraform { } random = { source = "hashicorp/random" - version = "3.5.1" + version = "3.6.0" } } } diff --git a/examples/resources/biganimal_cluster/single_node/azure/resource.tf b/examples/resources/biganimal_cluster/single_node/azure/resource.tf index 378d2da9..ad1240da 100644 --- a/examples/resources/biganimal_cluster/single_node/azure/resource.tf +++ b/examples/resources/biganimal_cluster/single_node/azure/resource.tf @@ -6,7 +6,7 @@ terraform { } random = { source = "hashicorp/random" - version = "3.5.1" + version = "3.6.0" } } } diff --git a/examples/resources/biganimal_cluster/single_node/bah_aws/resource.tf b/examples/resources/biganimal_cluster/single_node/bah_aws/resource.tf index cc718560..69ae0640 100644 --- a/examples/resources/biganimal_cluster/single_node/bah_aws/resource.tf +++ b/examples/resources/biganimal_cluster/single_node/bah_aws/resource.tf @@ -6,7 +6,7 @@ terraform { } random = { source = "hashicorp/random" - version = "3.5.1" + version = "3.6.0" } } } diff --git a/examples/resources/biganimal_cluster/single_node/bah_azure/resource.tf b/examples/resources/biganimal_cluster/single_node/bah_azure/resource.tf index 0ef3af1b..ee206d4f 100644 --- a/examples/resources/biganimal_cluster/single_node/bah_azure/resource.tf +++ b/examples/resources/biganimal_cluster/single_node/bah_azure/resource.tf @@ -6,7 +6,7 @@ terraform { } random = { source = "hashicorp/random" - version = "3.5.1" + version = "3.6.0" } } } diff --git a/examples/resources/biganimal_cluster/single_node/gcp/resource.tf b/examples/resources/biganimal_cluster/single_node/gcp/resource.tf index 5f215a93..5dfe8fbc 100644 --- a/examples/resources/biganimal_cluster/single_node/gcp/resource.tf +++ b/examples/resources/biganimal_cluster/single_node/gcp/resource.tf @@ -6,7 +6,7 @@ terraform { } random = { source = "hashicorp/random" - version = "3.5.1" + version = "3.6.0" } } } diff --git a/examples/resources/biganimal_cluster/single_node/resource.tf b/examples/resources/biganimal_cluster/single_node/resource.tf index 378d2da9..ad1240da 100644 --- a/examples/resources/biganimal_cluster/single_node/resource.tf +++ b/examples/resources/biganimal_cluster/single_node/resource.tf @@ -6,7 +6,7 @@ terraform { } random = { source = "hashicorp/random" - version = "3.5.1" + version = "3.6.0" } } } diff --git a/examples/resources/biganimal_faraway_replica/aws/resource.tf b/examples/resources/biganimal_faraway_replica/aws/resource.tf index d6e5a914..de113ae0 100644 --- a/examples/resources/biganimal_faraway_replica/aws/resource.tf +++ b/examples/resources/biganimal_faraway_replica/aws/resource.tf @@ -6,7 +6,7 @@ terraform { } random = { source = "hashicorp/random" - version = "3.5.1" + version = "3.6.0" } } } diff --git a/examples/resources/biganimal_faraway_replica/azure/resource.tf b/examples/resources/biganimal_faraway_replica/azure/resource.tf index fd8ed2d8..9ade8439 100644 --- a/examples/resources/biganimal_faraway_replica/azure/resource.tf +++ b/examples/resources/biganimal_faraway_replica/azure/resource.tf @@ -6,7 +6,7 @@ terraform { } random = { source = "hashicorp/random" - version = "3.5.1" + version = "3.6.0" } } } 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 ea8dd554..5645c00c 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 @@ -6,7 +6,7 @@ terraform { } random = { source = "hashicorp/random" - version = "3.5.1" + version = "3.6.0" } } } diff --git a/examples/resources/biganimal_faraway_replica/gcp/resource.tf b/examples/resources/biganimal_faraway_replica/gcp/resource.tf index a93c0983..2b52952a 100644 --- a/examples/resources/biganimal_faraway_replica/gcp/resource.tf +++ b/examples/resources/biganimal_faraway_replica/gcp/resource.tf @@ -6,7 +6,7 @@ terraform { } random = { source = "hashicorp/random" - version = "3.5.1" + version = "3.6.0" } } } diff --git a/examples/resources/biganimal_faraway_replica/resource.tf b/examples/resources/biganimal_faraway_replica/resource.tf index d6e5a914..de113ae0 100644 --- a/examples/resources/biganimal_faraway_replica/resource.tf +++ b/examples/resources/biganimal_faraway_replica/resource.tf @@ -6,7 +6,7 @@ terraform { } random = { source = "hashicorp/random" - version = "3.5.1" + version = "3.6.0" } } } diff --git a/examples/resources/biganimal_pgd/aws/bah_data_group/resource.tf b/examples/resources/biganimal_pgd/aws/bah_data_group/resource.tf index 906deb69..002dfe42 100644 --- a/examples/resources/biganimal_pgd/aws/bah_data_group/resource.tf +++ b/examples/resources/biganimal_pgd/aws/bah_data_group/resource.tf @@ -6,7 +6,7 @@ terraform { } random = { source = "hashicorp/random" - version = "3.5.1" + version = "3.6.0" } } } diff --git a/examples/resources/biganimal_pgd/aws/bah_data_groups_with_witness_group/resource.tf b/examples/resources/biganimal_pgd/aws/bah_data_groups_with_witness_group/resource.tf index caeb2cca..7fcf8505 100644 --- a/examples/resources/biganimal_pgd/aws/bah_data_groups_with_witness_group/resource.tf +++ b/examples/resources/biganimal_pgd/aws/bah_data_groups_with_witness_group/resource.tf @@ -6,7 +6,7 @@ terraform { } random = { source = "hashicorp/random" - version = "3.5.1" + version = "3.6.0" } } } diff --git a/examples/resources/biganimal_pgd/aws/data_group/resource.tf b/examples/resources/biganimal_pgd/aws/data_group/resource.tf index d4a14764..b17a977f 100644 --- a/examples/resources/biganimal_pgd/aws/data_group/resource.tf +++ b/examples/resources/biganimal_pgd/aws/data_group/resource.tf @@ -6,7 +6,7 @@ terraform { } random = { source = "hashicorp/random" - version = "3.5.1" + version = "3.6.0" } } } diff --git a/examples/resources/biganimal_pgd/aws/data_groups_with_witness_group/resource.tf b/examples/resources/biganimal_pgd/aws/data_groups_with_witness_group/resource.tf index 70e8f649..ba9a1c6a 100644 --- a/examples/resources/biganimal_pgd/aws/data_groups_with_witness_group/resource.tf +++ b/examples/resources/biganimal_pgd/aws/data_groups_with_witness_group/resource.tf @@ -6,7 +6,7 @@ terraform { } random = { source = "hashicorp/random" - version = "3.5.1" + version = "3.6.0" } } } diff --git a/examples/resources/biganimal_pgd/azure/bah_data_group/resource.tf b/examples/resources/biganimal_pgd/azure/bah_data_group/resource.tf index 5ba63a5d..6a429905 100644 --- a/examples/resources/biganimal_pgd/azure/bah_data_group/resource.tf +++ b/examples/resources/biganimal_pgd/azure/bah_data_group/resource.tf @@ -6,7 +6,7 @@ terraform { } random = { source = "hashicorp/random" - version = "3.5.1" + version = "3.6.0" } } } diff --git a/examples/resources/biganimal_pgd/azure/bah_data_groups_with_witness_group/resource.tf b/examples/resources/biganimal_pgd/azure/bah_data_groups_with_witness_group/resource.tf index 89897c64..4ef46028 100644 --- a/examples/resources/biganimal_pgd/azure/bah_data_groups_with_witness_group/resource.tf +++ b/examples/resources/biganimal_pgd/azure/bah_data_groups_with_witness_group/resource.tf @@ -6,7 +6,7 @@ terraform { } random = { source = "hashicorp/random" - version = "3.5.1" + version = "3.6.0" } } } diff --git a/examples/resources/biganimal_pgd/azure/data_group/resource.tf b/examples/resources/biganimal_pgd/azure/data_group/resource.tf index d67e51e4..d29a01b1 100644 --- a/examples/resources/biganimal_pgd/azure/data_group/resource.tf +++ b/examples/resources/biganimal_pgd/azure/data_group/resource.tf @@ -6,7 +6,7 @@ terraform { } random = { source = "hashicorp/random" - version = "3.5.1" + version = "3.6.0" } } } diff --git a/examples/resources/biganimal_pgd/azure/data_groups_with_witness_group/resource.tf b/examples/resources/biganimal_pgd/azure/data_groups_with_witness_group/resource.tf index 2d8bcb21..234c4edb 100644 --- a/examples/resources/biganimal_pgd/azure/data_groups_with_witness_group/resource.tf +++ b/examples/resources/biganimal_pgd/azure/data_groups_with_witness_group/resource.tf @@ -6,7 +6,7 @@ terraform { } random = { source = "hashicorp/random" - version = "3.5.1" + version = "3.6.0" } } } diff --git a/examples/resources/biganimal_pgd/gcp/bah_data_group/resource.tf b/examples/resources/biganimal_pgd/gcp/bah_data_group/resource.tf index 9b8c3e3d..5fa2d050 100644 --- a/examples/resources/biganimal_pgd/gcp/bah_data_group/resource.tf +++ b/examples/resources/biganimal_pgd/gcp/bah_data_group/resource.tf @@ -6,7 +6,7 @@ terraform { } random = { source = "hashicorp/random" - version = "3.5.1" + version = "3.6.0" } } } diff --git a/examples/resources/biganimal_pgd/gcp/bah_data_groups_with_witness_group/resource.tf b/examples/resources/biganimal_pgd/gcp/bah_data_groups_with_witness_group/resource.tf index 4ca6671c..120a3cc4 100644 --- a/examples/resources/biganimal_pgd/gcp/bah_data_groups_with_witness_group/resource.tf +++ b/examples/resources/biganimal_pgd/gcp/bah_data_groups_with_witness_group/resource.tf @@ -6,7 +6,7 @@ terraform { } random = { source = "hashicorp/random" - version = "3.5.1" + version = "3.6.0" } } } diff --git a/examples/resources/biganimal_pgd/gcp/data_group/resource.tf b/examples/resources/biganimal_pgd/gcp/data_group/resource.tf index 3756e1c7..47c70072 100644 --- a/examples/resources/biganimal_pgd/gcp/data_group/resource.tf +++ b/examples/resources/biganimal_pgd/gcp/data_group/resource.tf @@ -6,7 +6,7 @@ terraform { } random = { source = "hashicorp/random" - version = "3.5.1" + version = "3.6.0" } } } diff --git a/examples/resources/biganimal_pgd/gcp/data_groups_with_witness_group/resource.tf b/examples/resources/biganimal_pgd/gcp/data_groups_with_witness_group/resource.tf index 8f956df4..dd78ad6c 100644 --- a/examples/resources/biganimal_pgd/gcp/data_groups_with_witness_group/resource.tf +++ b/examples/resources/biganimal_pgd/gcp/data_groups_with_witness_group/resource.tf @@ -6,7 +6,7 @@ terraform { } random = { source = "hashicorp/random" - version = "3.5.1" + version = "3.6.0" } } } diff --git a/examples/resources/biganimal_project/resource.tf b/examples/resources/biganimal_project/resource.tf index 212a8f5c..e76e156e 100644 --- a/examples/resources/biganimal_project/resource.tf +++ b/examples/resources/biganimal_project/resource.tf @@ -6,7 +6,7 @@ terraform { } random = { source = "hashicorp/random" - version = "3.5.1" + version = "3.6.0" } } } From db0ef3fc266540c36293489e6cdcc4feccb3efed Mon Sep 17 00:00:00 2001 From: "PC-2NR0VQ3\\wai.wong" Date: Tue, 5 Dec 2023 03:06:21 +0000 Subject: [PATCH 05/16] docs: update docs --- docs/resources/cluster.md | 10 ++++++++++ templates/resources/cluster.md.tmpl | 10 ++++++++++ 2 files changed, 20 insertions(+) diff --git a/docs/resources/cluster.md b/docs/resources/cluster.md index 59a01bfa..7efac711 100644 --- a/docs/resources/cluster.md +++ b/docs/resources/cluster.md @@ -212,6 +212,16 @@ output "faraway_replica_ids" { -> Please use the `biganimal_pgd` resource to manage the Distributed High Availability clusters. +## Restoring a cluster + +Here are the steps to restore a cluster: +1. Use an example config in the examples folder, uncomment the following fields restore_cluster_id=p-123456789, restore_from_deleted=true and enter your cluster id you want to restore and set to true respectively(for restoring an existing cluster, set false) +2. Use commands terraform init and terraform import biganimal_cluster.single_node_cluster prj_123456789/p-123456789/import-from-deleted to import a deleted cluster into terraform(use import biganimal_cluster.single_node_cluster prj_123456789/p-123456789 to import an existing cluster) +3. Use command terraform plan to compare and diff your config with the imported cluster(source cluster) and edit config where appropriate. You can also use terraform show to see the source cluster which you can copy and paste the field values into your config +4. Remove state by deleting the file terraform.tfstate or use the commands terraform state rm 'biganimal_cluster.single_node_cluster' and terraform state rm 'random_password.password' +5. Use command terraform init and terraform apply to restore the cluster, it will show a warning saying you are trying to restore a cluster +6. Remove or comment the field restore_cluster_id=p-123456789 in the config after the restore has completed + ## Schema diff --git a/templates/resources/cluster.md.tmpl b/templates/resources/cluster.md.tmpl index 1af44e05..c83091eb 100644 --- a/templates/resources/cluster.md.tmpl +++ b/templates/resources/cluster.md.tmpl @@ -21,6 +21,16 @@ Please visit the [examples page](https://github.com/EnterpriseDB/terraform-provi -> Please use the `biganimal_pgd` resource to manage the Distributed High Availability clusters. +## Restoring a cluster + +Here are the steps to restore a cluster: +1. Use an example config in the examples folder, uncomment the following fields restore_cluster_id=p-123456789, restore_from_deleted=true and enter your cluster id you want to restore and set to true respectively(for restoring an existing cluster, set false) +2. Use commands terraform init and terraform import biganimal_cluster.single_node_cluster prj_123456789/p-123456789/import-from-deleted to import a deleted cluster into terraform(use import biganimal_cluster.single_node_cluster prj_123456789/p-123456789 to import an existing cluster) +3. Use command terraform plan to compare and diff your config with the imported cluster(source cluster) and edit config where appropriate. You can also use terraform show to see the source cluster which you can copy and paste the field values into your config +4. Remove state by deleting the file terraform.tfstate or use the commands terraform state rm 'biganimal_cluster.single_node_cluster' and terraform state rm 'random_password.password' +5. Use command terraform init and terraform apply to restore the cluster, it will show a warning saying you are trying to restore a cluster +6. Remove or comment the field restore_cluster_id=p-123456789 in the config after the restore has completed + {{ .SchemaMarkdown | trimspace }} {{- if .HasImport }} From 74118c8e4b71eefca3d0d3322d791498915a50e1 Mon Sep 17 00:00:00 2001 From: "PC-2NR0VQ3\\wai.wong" Date: Tue, 5 Dec 2023 03:08:30 +0000 Subject: [PATCH 06/16] fix: spell check --- .wordlist-en-custom.txt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.wordlist-en-custom.txt b/.wordlist-en-custom.txt index 01e263ea..4091ffce 100644 --- a/.wordlist-en-custom.txt +++ b/.wordlist-en-custom.txt @@ -28,6 +28,7 @@ gp hh highcpu iam +init io ip nestedatt @@ -36,7 +37,10 @@ nestedobjatt pgd pgextended postgres +prj ssd terraform +tfstate ultradisk +uncomment uri From 49d439b9abe714d3afaf01b35469af3953378b22 Mon Sep 17 00:00:00 2001 From: "PC-2NR0VQ3\\wai.wong" Date: Mon, 11 Dec 2023 15:51:42 +0000 Subject: [PATCH 07/16] fix: schema descriptions fix for restore cluster --- pkg/provider/resource_cluster.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/provider/resource_cluster.go b/pkg/provider/resource_cluster.go index 826b9e15..d34fcfd4 100644 --- a/pkg/provider/resource_cluster.go +++ b/pkg/provider/resource_cluster.go @@ -402,11 +402,11 @@ func (c *clusterResource) Schema(ctx context.Context, req resource.SchemaRequest Computed: true, }, "import_from_deleted": schema.BoolAttribute{ - Description: "Used by import function only to import a deleted cluster", + Description: "Used by the import function only to import a deleted cluster", Optional: true, }, "restore_from_deleted": schema.BoolAttribute{ - Description: "For restoring a cluster. Specifies if the cluster you want to restore is deleted", + Description: "For restoring a cluster. Specifies if the cluster you want to restore is from deleted", Optional: true, }, "restore_cluster_id": schema.StringAttribute{ From b7dbad723e8fd82a6fdb2d99532ed6fcd0f9a245 Mon Sep 17 00:00:00 2001 From: "PC-2NR0VQ3\\wai.wong" Date: Mon, 11 Dec 2023 15:52:12 +0000 Subject: [PATCH 08/16] docs: docs and template update --- docs/resources/cluster.md | 8 ++++---- templates/resources/cluster.md.tmpl | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/docs/resources/cluster.md b/docs/resources/cluster.md index 7efac711..1f3f2351 100644 --- a/docs/resources/cluster.md +++ b/docs/resources/cluster.md @@ -215,8 +215,8 @@ output "faraway_replica_ids" { ## Restoring a cluster Here are the steps to restore a cluster: -1. Use an example config in the examples folder, uncomment the following fields restore_cluster_id=p-123456789, restore_from_deleted=true and enter your cluster id you want to restore and set to true respectively(for restoring an existing cluster, set false) -2. Use commands terraform init and terraform import biganimal_cluster.single_node_cluster prj_123456789/p-123456789/import-from-deleted to import a deleted cluster into terraform(use import biganimal_cluster.single_node_cluster prj_123456789/p-123456789 to import an existing cluster) +1. Use an example config in the examples folder, uncomment the following fields restore_cluster_id=p-123456789, restore_from_deleted=true and enter your cluster id you want to restore and set to true respectively(for restoring an active cluster, set to false) +2. Use commands terraform init and terraform import biganimal_cluster.single_node_cluster prj_123456789/p-123456789/import-from-deleted to import a deleted cluster into terraform(use import biganimal_cluster.single_node_cluster prj_123456789/p-123456789 to import an active cluster) 3. Use command terraform plan to compare and diff your config with the imported cluster(source cluster) and edit config where appropriate. You can also use terraform show to see the source cluster which you can copy and paste the field values into your config 4. Remove state by deleting the file terraform.tfstate or use the commands terraform state rm 'biganimal_cluster.single_node_cluster' and terraform state rm 'random_password.password' 5. Use command terraform init and terraform apply to restore the cluster, it will show a warning saying you are trying to restore a cluster @@ -242,7 +242,7 @@ Here are the steps to restore a cluster: - `backup_retention_period` (String) Backup retention period. For example, "7d", "2w", or "3m". - `cluster_architecture` (Block, Optional) Cluster architecture. See [Supported cluster types](https://www.enterprisedb.com/docs/biganimal/latest/overview/02_high_availability/) for details. (see [below for nested schema](#nestedblock--cluster_architecture)) - `csp_auth` (Boolean) Is authentication handled by the cloud service provider. Available for AWS only, See [Authentication](https://www.enterprisedb.com/docs/biganimal/latest/getting_started/creating_a_cluster/#authentication) for details. -- `import_from_deleted` (Boolean) Used by import function only to import a deleted cluster +- `import_from_deleted` (Boolean) Used by the import function only to import a deleted cluster - `maintenance_window` (Attributes) Custom maintenance window. (see [below for nested schema](#nestedatt--maintenance_window)) - `most_recent` (Boolean) Show the most recent cluster when there are multiple clusters with the same name. - `pe_allowed_principal_ids` (Set of String) Cloud provider subscription/account ID, need to be specified when cluster is deployed on BigAnimal's cloud account. @@ -251,7 +251,7 @@ Here are the steps to restore a cluster: - `private_networking` (Boolean) Is private networking enabled. - `read_only_connections` (Boolean) Is read only connection enabled. - `restore_cluster_id` (String) For restoring a cluster. Specifies the cluster id to restore -- `restore_from_deleted` (Boolean) For restoring a cluster. Specifies if the cluster you want to restore is deleted +- `restore_from_deleted` (Boolean) For restoring a cluster. Specifies if the cluster you want to restore is from deleted - `restore_point` (String) For restoring a cluster. Specifies restore point e.g. 2006-01-02T15:04:05-0700. Leave empty to restore from latest point - `service_account_ids` (Set of String) A Google Cloud Service Account is used for logs. If you leave this blank, then you will be unable to access log details for this cluster. Required when cluster is deployed on BigAnimal's cloud account. - `storage` (Block, Optional) Storage. (see [below for nested schema](#nestedblock--storage)) diff --git a/templates/resources/cluster.md.tmpl b/templates/resources/cluster.md.tmpl index c83091eb..668f1946 100644 --- a/templates/resources/cluster.md.tmpl +++ b/templates/resources/cluster.md.tmpl @@ -24,8 +24,8 @@ Please visit the [examples page](https://github.com/EnterpriseDB/terraform-provi ## Restoring a cluster Here are the steps to restore a cluster: -1. Use an example config in the examples folder, uncomment the following fields restore_cluster_id=p-123456789, restore_from_deleted=true and enter your cluster id you want to restore and set to true respectively(for restoring an existing cluster, set false) -2. Use commands terraform init and terraform import biganimal_cluster.single_node_cluster prj_123456789/p-123456789/import-from-deleted to import a deleted cluster into terraform(use import biganimal_cluster.single_node_cluster prj_123456789/p-123456789 to import an existing cluster) +1. Use an example config in the examples folder, uncomment the following fields restore_cluster_id=p-123456789, restore_from_deleted=true and enter your cluster id you want to restore and set to true respectively(for restoring an active cluster, set to false) +2. Use commands terraform init and terraform import biganimal_cluster.single_node_cluster prj_123456789/p-123456789/import-from-deleted to import a deleted cluster into terraform(use import biganimal_cluster.single_node_cluster prj_123456789/p-123456789 to import an active cluster) 3. Use command terraform plan to compare and diff your config with the imported cluster(source cluster) and edit config where appropriate. You can also use terraform show to see the source cluster which you can copy and paste the field values into your config 4. Remove state by deleting the file terraform.tfstate or use the commands terraform state rm 'biganimal_cluster.single_node_cluster' and terraform state rm 'random_password.password' 5. Use command terraform init and terraform apply to restore the cluster, it will show a warning saying you are trying to restore a cluster From bfef0839eb87f6d571d059e9ac5316e9aec0b154 Mon Sep 17 00:00:00 2001 From: "PC-2NR0VQ3\\wai.wong" Date: Wed, 10 Jan 2024 12:15:04 +0000 Subject: [PATCH 09/16] fix: tf files --- .../resources/biganimal_cluster/ha/resource.tf | 7 ++++--- .../biganimal_cluster/single_node/aws/resource.tf | 9 +++++---- .../single_node/azure/resource.tf | 7 ++++--- .../single_node/bah_aws/resource.tf | 7 ++++--- .../single_node/bah_azure/resource.tf | 15 ++++++++------- .../single_node/bah_gcp/resource.tf | 7 ++++--- .../biganimal_cluster/single_node/gcp/resource.tf | 7 ++++--- .../biganimal_cluster/single_node/resource.tf | 7 ++++--- 8 files changed, 37 insertions(+), 29 deletions(-) diff --git a/examples/resources/biganimal_cluster/ha/resource.tf b/examples/resources/biganimal_cluster/ha/resource.tf index af513256..222daf29 100644 --- a/examples/resources/biganimal_cluster/ha/resource.tf +++ b/examples/resources/biganimal_cluster/ha/resource.tf @@ -79,9 +79,6 @@ resource "biganimal_cluster" "ha_cluster" { region = "us-east-1" superuser_access = true pgvector = false - # restore_cluster_id = "p-123456789" # uncomment to restore cluster - # restore_from_deleted = true - # restore_point = "2006-01-02T15:04:05-0700" pg_bouncer = { is_enabled = false @@ -98,6 +95,10 @@ resource "biganimal_cluster" "ha_cluster" { # }, # ] } + + # restore_cluster_id = "p-123456789" # uncomment to restore cluster + # restore_from_deleted = true + # restore_point = "2006-01-02T15:04:05-0700" } output "password" { diff --git a/examples/resources/biganimal_cluster/single_node/aws/resource.tf b/examples/resources/biganimal_cluster/single_node/aws/resource.tf index 31f7d9a6..3d0b19c6 100644 --- a/examples/resources/biganimal_cluster/single_node/aws/resource.tf +++ b/examples/resources/biganimal_cluster/single_node/aws/resource.tf @@ -80,10 +80,7 @@ resource "biganimal_cluster" "single_node_cluster" { region = "us-east-1" superuser_access = true pgvector = false - # restore_cluster_id = "p-123456789" # uncomment to restore cluster - # restore_from_deleted = true - # restore_point = "2006-01-02T15:04:05-0700" - + 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. @@ -99,6 +96,10 @@ resource "biganimal_cluster" "single_node_cluster" { # }, # ] } + + # restore_cluster_id = "p-123456789" # uncomment to restore cluster + # restore_from_deleted = true + # restore_point = "2006-01-02T15:04:05-0700" } output "password" { diff --git a/examples/resources/biganimal_cluster/single_node/azure/resource.tf b/examples/resources/biganimal_cluster/single_node/azure/resource.tf index d18bc886..479c554b 100644 --- a/examples/resources/biganimal_cluster/single_node/azure/resource.tf +++ b/examples/resources/biganimal_cluster/single_node/azure/resource.tf @@ -80,9 +80,6 @@ resource "biganimal_cluster" "single_node_cluster" { region = "eastus2" superuser_access = true pgvector = false - # restore_cluster_id = "p-123456789" # uncomment to restore cluster - # restore_from_deleted = true - # restore_point = "2006-01-02T15:04:05-0700" pg_bouncer = { is_enabled = false @@ -99,6 +96,10 @@ resource "biganimal_cluster" "single_node_cluster" { # }, # ] } + + # restore_cluster_id = "p-123456789" # uncomment to restore cluster + # restore_from_deleted = true + # restore_point = "2006-01-02T15:04:05-0700" } output "password" { diff --git a/examples/resources/biganimal_cluster/single_node/bah_aws/resource.tf b/examples/resources/biganimal_cluster/single_node/bah_aws/resource.tf index a6a6cc3e..7fcb80f1 100644 --- a/examples/resources/biganimal_cluster/single_node/bah_aws/resource.tf +++ b/examples/resources/biganimal_cluster/single_node/bah_aws/resource.tf @@ -78,9 +78,6 @@ resource "biganimal_cluster" "single_node_cluster" { read_only_connections = false region = "us-east-1" pgvector = false - # restore_cluster_id = "p-123456789" # uncomment to restore cluster - # restore_from_deleted = true - # restore_point = "2006-01-02T15:04:05-0700" pg_bouncer = { is_enabled = false @@ -97,6 +94,10 @@ resource "biganimal_cluster" "single_node_cluster" { # }, # ] } + + # restore_cluster_id = "p-123456789" # uncomment to restore cluster + # restore_from_deleted = true + # restore_point = "2006-01-02T15:04:05-0700" } output "password" { diff --git a/examples/resources/biganimal_cluster/single_node/bah_azure/resource.tf b/examples/resources/biganimal_cluster/single_node/bah_azure/resource.tf index 31fb75d1..a89a7aeb 100644 --- a/examples/resources/biganimal_cluster/single_node/bah_azure/resource.tf +++ b/examples/resources/biganimal_cluster/single_node/bah_azure/resource.tf @@ -72,6 +72,10 @@ resource "biganimal_cluster" "single_node_cluster" { start_time = "03:00" } + # pe_allowed_principal_ids = [ + # # ex: "9334e5e6-7f47-aE61-5A4F-ee067daeEf4A" + # ] + pg_type = "epas" pg_version = "15" private_networking = false @@ -79,10 +83,7 @@ resource "biganimal_cluster" "single_node_cluster" { read_only_connections = false region = "eastus2" pgvector = false - # restore_cluster_id = "p-123456789" # uncomment to restore cluster - # restore_from_deleted = true - # restore_point = "2006-01-02T15:04:05-0700" - + 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. @@ -99,9 +100,9 @@ resource "biganimal_cluster" "single_node_cluster" { # ] } - # pe_allowed_principal_ids = [ - # # ex: "9334e5e6-7f47-aE61-5A4F-ee067daeEf4A" - # ] + # restore_cluster_id = "p-123456789" # uncomment to restore cluster + # restore_from_deleted = true + # restore_point = "2006-01-02T15:04:05-0700" } output "password" { diff --git a/examples/resources/biganimal_cluster/single_node/bah_gcp/resource.tf b/examples/resources/biganimal_cluster/single_node/bah_gcp/resource.tf index 6a1413c6..10aaf433 100644 --- a/examples/resources/biganimal_cluster/single_node/bah_gcp/resource.tf +++ b/examples/resources/biganimal_cluster/single_node/bah_gcp/resource.tf @@ -72,9 +72,6 @@ resource "biganimal_cluster" "single_node_cluster" { read_only_connections = false region = "europe-west1" pgvector = false - # restore_cluster_id = "p-123456789" # uncomment to restore cluster - # restore_from_deleted = true - # restore_point = "2006-01-02T15:04:05-0700" pg_bouncer = { is_enabled = false @@ -91,6 +88,10 @@ resource "biganimal_cluster" "single_node_cluster" { # }, # ] } + + # restore_cluster_id = "p-123456789" # uncomment to restore cluster + # restore_from_deleted = true + # restore_point = "2006-01-02T15:04:05-0700" } output "password" { diff --git a/examples/resources/biganimal_cluster/single_node/gcp/resource.tf b/examples/resources/biganimal_cluster/single_node/gcp/resource.tf index ce058d49..29273d16 100644 --- a/examples/resources/biganimal_cluster/single_node/gcp/resource.tf +++ b/examples/resources/biganimal_cluster/single_node/gcp/resource.tf @@ -80,9 +80,6 @@ resource "biganimal_cluster" "single_node_cluster" { region = "us-east1" superuser_access = true pgvector = false - # restore_cluster_id = "p-123456789" # uncomment to restore cluster - # restore_from_deleted = true - # restore_point = "2006-01-02T15:04:05-0700" pg_bouncer = { is_enabled = false @@ -99,6 +96,10 @@ resource "biganimal_cluster" "single_node_cluster" { # }, # ] } + + # restore_cluster_id = "p-123456789" # uncomment to restore cluster + # restore_from_deleted = true + # restore_point = "2006-01-02T15:04:05-0700" } output "password" { diff --git a/examples/resources/biganimal_cluster/single_node/resource.tf b/examples/resources/biganimal_cluster/single_node/resource.tf index d18bc886..479c554b 100644 --- a/examples/resources/biganimal_cluster/single_node/resource.tf +++ b/examples/resources/biganimal_cluster/single_node/resource.tf @@ -80,9 +80,6 @@ resource "biganimal_cluster" "single_node_cluster" { region = "eastus2" superuser_access = true pgvector = false - # restore_cluster_id = "p-123456789" # uncomment to restore cluster - # restore_from_deleted = true - # restore_point = "2006-01-02T15:04:05-0700" pg_bouncer = { is_enabled = false @@ -99,6 +96,10 @@ resource "biganimal_cluster" "single_node_cluster" { # }, # ] } + + # restore_cluster_id = "p-123456789" # uncomment to restore cluster + # restore_from_deleted = true + # restore_point = "2006-01-02T15:04:05-0700" } output "password" { From 65db70d24128e02c7590484984210e5cb2f2c1d6 Mon Sep 17 00:00:00 2001 From: "PC-2NR0VQ3\\wai.wong" Date: Wed, 10 Jan 2024 14:49:00 +0000 Subject: [PATCH 10/16] docs: update docs --- docs/resources/cluster.md | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/docs/resources/cluster.md b/docs/resources/cluster.md index e9c8b9c7..11e8f02d 100644 --- a/docs/resources/cluster.md +++ b/docs/resources/cluster.md @@ -90,10 +90,6 @@ resource "biganimal_cluster" "single_node_cluster" { read_only_connections = false region = "eastus2" superuser_access = true - pgvector = true - # restore_cluster_id = "p-123456789" # uncomment to restore cluster - # restore_from_deleted = true - # restore_point = "2006-01-02T15:04:05-0700" pgvector = false pg_bouncer = { @@ -111,6 +107,10 @@ resource "biganimal_cluster" "single_node_cluster" { # }, # ] } + + # restore_cluster_id = "p-123456789" # uncomment to restore cluster + # restore_from_deleted = true + # restore_point = "2006-01-02T15:04:05-0700" } output "password" { @@ -205,10 +205,6 @@ resource "biganimal_cluster" "ha_cluster" { read_only_connections = true region = "us-east-1" superuser_access = true - pgvector = true - # restore_cluster_id = "p-123456789" # uncomment to restore cluster - # restore_from_deleted = true - # restore_point = "2006-01-02T15:04:05-0700" pgvector = false pg_bouncer = { @@ -226,6 +222,10 @@ resource "biganimal_cluster" "ha_cluster" { # }, # ] } + + # restore_cluster_id = "p-123456789" # uncomment to restore cluster + # restore_from_deleted = true + # restore_point = "2006-01-02T15:04:05-0700" } output "password" { From c29b20cbacbf9c4d81090b2516a462c73fdbd7e9 Mon Sep 17 00:00:00 2001 From: "PC-2NR0VQ3\\wai.wong" Date: Wed, 10 Jan 2024 15:33:17 +0000 Subject: [PATCH 11/16] fix: improved error message for import --- pkg/provider/resource_cluster.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/provider/resource_cluster.go b/pkg/provider/resource_cluster.go index b04b492d..e0b4baec 100644 --- a/pkg/provider/resource_cluster.go +++ b/pkg/provider/resource_cluster.go @@ -642,7 +642,7 @@ func (c *clusterResource) ImportState(ctx context.Context, req resource.ImportSt if len(idParts) < 2 || idParts[0] == "" || idParts[1] == "" { resp.Diagnostics.AddError( "Unexpected Import Identifier", - fmt.Sprintf("Expected import identifier with format: project_id/cluster_id. Got: %q", req.ID), + fmt.Sprintf("Expected import identifier with format: project_id/cluster_id/. Got: %q", req.ID), ) return } From 5bcd6be644a5fd13298866978f27210b1aea2e99 Mon Sep 17 00:00:00 2001 From: "PC-2NR0VQ3\\wai.wong" Date: Wed, 10 Jan 2024 17:03:56 +0000 Subject: [PATCH 12/16] fix: remove unused most_recent field --- pkg/provider/resource_cluster.go | 4 ---- 1 file changed, 4 deletions(-) diff --git a/pkg/provider/resource_cluster.go b/pkg/provider/resource_cluster.go index e0b4baec..fedcbf6c 100644 --- a/pkg/provider/resource_cluster.go +++ b/pkg/provider/resource_cluster.go @@ -253,10 +253,6 @@ func (c *clusterResource) Schema(ctx context.Context, req resource.SchemaRequest MarkdownDescription: "Name of the cluster.", Required: true, }, - "most_recent": schema.BoolAttribute{ - MarkdownDescription: "Show the most recent cluster when there are multiple clusters with the same name.", - Optional: true, - }, "phase": schema.StringAttribute{ MarkdownDescription: "Current phase of the cluster.", Computed: true, From c4ee6404b6b14cdb4e80ecc563d19f2b1e686bc1 Mon Sep 17 00:00:00 2001 From: "PC-2NR0VQ3\\wai.wong" Date: Thu, 11 Jan 2024 08:35:05 +0000 Subject: [PATCH 13/16] docs: update docs --- docs/resources/cluster.md | 3 +-- pkg/plan_modifier/restore_cluster_id.go | 2 +- templates/resources/cluster.md.tmpl | 2 +- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/docs/resources/cluster.md b/docs/resources/cluster.md index 11e8f02d..1951a777 100644 --- a/docs/resources/cluster.md +++ b/docs/resources/cluster.md @@ -251,7 +251,7 @@ output "faraway_replica_ids" { Here are the steps to restore a cluster: 1. Use an example config in the examples folder, uncomment the following fields restore_cluster_id=p-123456789, restore_from_deleted=true and enter your cluster id you want to restore and set to true respectively(for restoring an active cluster, set to false) 2. Use commands terraform init and terraform import biganimal_cluster.single_node_cluster prj_123456789/p-123456789/import-from-deleted to import a deleted cluster into terraform(use import biganimal_cluster.single_node_cluster prj_123456789/p-123456789 to import an active cluster) -3. Use command terraform plan to compare and diff your config with the imported cluster(source cluster) and edit config where appropriate. You can also use terraform show to see the source cluster which you can copy and paste the field values into your config +3. Use command terraform plan to compare and diff your config with the imported cluster(source cluster) and edit config where appropriate. You can also use terraform show to see the source cluster which you can copy and paste the field values into your config. The config fields 'cloud_provider', 'pg_type', 'pg_version' and 'private_networking' are unmodifiable and have to match the source cluster 4. Remove state by deleting the file terraform.tfstate or use the commands terraform state rm 'biganimal_cluster.single_node_cluster' and terraform state rm 'random_password.password' 5. Use command terraform init and terraform apply to restore the cluster, it will show a warning saying you are trying to restore a cluster 6. Remove or comment the field restore_cluster_id=p-123456789 in the config after the restore has completed @@ -278,7 +278,6 @@ Here are the steps to restore a cluster: - `csp_auth` (Boolean) Is authentication handled by the cloud service provider. Available for AWS only, See [Authentication](https://www.enterprisedb.com/docs/biganimal/latest/getting_started/creating_a_cluster/#authentication) for details. - `import_from_deleted` (Boolean) Used by the import function only to import a deleted cluster - `maintenance_window` (Attributes) Custom maintenance window. (see [below for nested schema](#nestedatt--maintenance_window)) -- `most_recent` (Boolean) Show the most recent cluster when there are multiple clusters with the same name. - `pe_allowed_principal_ids` (Set of String) Cloud provider subscription/account ID, need to be specified when cluster is deployed on BigAnimal's cloud account. - `pg_bouncer` (Attributes) Pg bouncer. (see [below for nested schema](#nestedatt--pg_bouncer)) - `pg_config` (Block Set) 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. (see [below for nested schema](#nestedblock--pg_config)) diff --git a/pkg/plan_modifier/restore_cluster_id.go b/pkg/plan_modifier/restore_cluster_id.go index b5e8d0a4..8f246a12 100644 --- a/pkg/plan_modifier/restore_cluster_id.go +++ b/pkg/plan_modifier/restore_cluster_id.go @@ -36,7 +36,7 @@ func (m customRestoreClusterIdModifier) PlanModifyString(ctx context.Context, re if !req.PlanValue.IsNull() { resp.Diagnostics.AddWarning( "You are restoring a cluster", - "You are restoring a cluster. After restoring the cluster, please remove field 'restore_cluster_id' and optionally remove fields 'restore_from_deleted' and 'restore_point' from the config", + "You are restoring a cluster. The config fields 'cloud_provider', 'pg_type', 'pg_version' and 'private_networking' are unmodifiable and have to match the source cluster. After restoring the cluster, please remove fields 'restore_cluster_id','restore_from_deleted' and 'restore_point' from the config", ) } } diff --git a/templates/resources/cluster.md.tmpl b/templates/resources/cluster.md.tmpl index 668f1946..6ab74dc7 100644 --- a/templates/resources/cluster.md.tmpl +++ b/templates/resources/cluster.md.tmpl @@ -26,7 +26,7 @@ Please visit the [examples page](https://github.com/EnterpriseDB/terraform-provi Here are the steps to restore a cluster: 1. Use an example config in the examples folder, uncomment the following fields restore_cluster_id=p-123456789, restore_from_deleted=true and enter your cluster id you want to restore and set to true respectively(for restoring an active cluster, set to false) 2. Use commands terraform init and terraform import biganimal_cluster.single_node_cluster prj_123456789/p-123456789/import-from-deleted to import a deleted cluster into terraform(use import biganimal_cluster.single_node_cluster prj_123456789/p-123456789 to import an active cluster) -3. Use command terraform plan to compare and diff your config with the imported cluster(source cluster) and edit config where appropriate. You can also use terraform show to see the source cluster which you can copy and paste the field values into your config +3. Use command terraform plan to compare and diff your config with the imported cluster(source cluster) and edit config where appropriate. You can also use terraform show to see the source cluster which you can copy and paste the field values into your config. The config fields 'cloud_provider', 'pg_type', 'pg_version' and 'private_networking' are unmodifiable and have to match the source cluster 4. Remove state by deleting the file terraform.tfstate or use the commands terraform state rm 'biganimal_cluster.single_node_cluster' and terraform state rm 'random_password.password' 5. Use command terraform init and terraform apply to restore the cluster, it will show a warning saying you are trying to restore a cluster 6. Remove or comment the field restore_cluster_id=p-123456789 in the config after the restore has completed From 8e1c6b9c4e5178b72473096e134937d11a3fd60c Mon Sep 17 00:00:00 2001 From: "PC-2NR0VQ3\\wai.wong" Date: Thu, 11 Jan 2024 08:54:47 +0000 Subject: [PATCH 14/16] docs: update docs --- docs/resources/cluster.md | 2 +- pkg/plan_modifier/restore_cluster_id.go | 2 +- templates/resources/cluster.md.tmpl | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/resources/cluster.md b/docs/resources/cluster.md index 1951a777..f66146ae 100644 --- a/docs/resources/cluster.md +++ b/docs/resources/cluster.md @@ -251,7 +251,7 @@ output "faraway_replica_ids" { Here are the steps to restore a cluster: 1. Use an example config in the examples folder, uncomment the following fields restore_cluster_id=p-123456789, restore_from_deleted=true and enter your cluster id you want to restore and set to true respectively(for restoring an active cluster, set to false) 2. Use commands terraform init and terraform import biganimal_cluster.single_node_cluster prj_123456789/p-123456789/import-from-deleted to import a deleted cluster into terraform(use import biganimal_cluster.single_node_cluster prj_123456789/p-123456789 to import an active cluster) -3. Use command terraform plan to compare and diff your config with the imported cluster(source cluster) and edit config where appropriate. You can also use terraform show to see the source cluster which you can copy and paste the field values into your config. The config fields 'cloud_provider', 'pg_type', 'pg_version' and 'private_networking' are unmodifiable and have to match the source cluster +3. Use command terraform plan to compare and diff your config with the imported cluster(source cluster) and edit config where appropriate. You can also use terraform show to see the source cluster which you can copy and paste the field values into your config. The config fields 'cloud_provider', 'pg_type', 'pg_version' and 'private_networking' cannot be changed and have to match the source cluster 4. Remove state by deleting the file terraform.tfstate or use the commands terraform state rm 'biganimal_cluster.single_node_cluster' and terraform state rm 'random_password.password' 5. Use command terraform init and terraform apply to restore the cluster, it will show a warning saying you are trying to restore a cluster 6. Remove or comment the field restore_cluster_id=p-123456789 in the config after the restore has completed diff --git a/pkg/plan_modifier/restore_cluster_id.go b/pkg/plan_modifier/restore_cluster_id.go index 8f246a12..f9d47970 100644 --- a/pkg/plan_modifier/restore_cluster_id.go +++ b/pkg/plan_modifier/restore_cluster_id.go @@ -36,7 +36,7 @@ func (m customRestoreClusterIdModifier) PlanModifyString(ctx context.Context, re if !req.PlanValue.IsNull() { resp.Diagnostics.AddWarning( "You are restoring a cluster", - "You are restoring a cluster. The config fields 'cloud_provider', 'pg_type', 'pg_version' and 'private_networking' are unmodifiable and have to match the source cluster. After restoring the cluster, please remove fields 'restore_cluster_id','restore_from_deleted' and 'restore_point' from the config", + "You are restoring a cluster. The config fields 'cloud_provider', 'pg_type', 'pg_version' and 'private_networking' cannot be changed and have to match the source cluster. After restoring the cluster, please remove fields 'restore_cluster_id','restore_from_deleted' and 'restore_point' from the config", ) } } diff --git a/templates/resources/cluster.md.tmpl b/templates/resources/cluster.md.tmpl index 6ab74dc7..027afdf7 100644 --- a/templates/resources/cluster.md.tmpl +++ b/templates/resources/cluster.md.tmpl @@ -26,7 +26,7 @@ Please visit the [examples page](https://github.com/EnterpriseDB/terraform-provi Here are the steps to restore a cluster: 1. Use an example config in the examples folder, uncomment the following fields restore_cluster_id=p-123456789, restore_from_deleted=true and enter your cluster id you want to restore and set to true respectively(for restoring an active cluster, set to false) 2. Use commands terraform init and terraform import biganimal_cluster.single_node_cluster prj_123456789/p-123456789/import-from-deleted to import a deleted cluster into terraform(use import biganimal_cluster.single_node_cluster prj_123456789/p-123456789 to import an active cluster) -3. Use command terraform plan to compare and diff your config with the imported cluster(source cluster) and edit config where appropriate. You can also use terraform show to see the source cluster which you can copy and paste the field values into your config. The config fields 'cloud_provider', 'pg_type', 'pg_version' and 'private_networking' are unmodifiable and have to match the source cluster +3. Use command terraform plan to compare and diff your config with the imported cluster(source cluster) and edit config where appropriate. You can also use terraform show to see the source cluster which you can copy and paste the field values into your config. The config fields 'cloud_provider', 'pg_type', 'pg_version' and 'private_networking' cannot be changed and have to match the source cluster 4. Remove state by deleting the file terraform.tfstate or use the commands terraform state rm 'biganimal_cluster.single_node_cluster' and terraform state rm 'random_password.password' 5. Use command terraform init and terraform apply to restore the cluster, it will show a warning saying you are trying to restore a cluster 6. Remove or comment the field restore_cluster_id=p-123456789 in the config after the restore has completed From 8aef25bcc6670b322194b632a9b06ee204570c2a Mon Sep 17 00:00:00 2001 From: "PC-2NR0VQ3\\wai.wong" Date: Thu, 11 Jan 2024 09:10:03 +0000 Subject: [PATCH 15/16] docs: update docs --- docs/resources/cluster.md | 2 +- pkg/plan_modifier/restore_cluster_id.go | 2 +- templates/resources/cluster.md.tmpl | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/resources/cluster.md b/docs/resources/cluster.md index f66146ae..15991bd9 100644 --- a/docs/resources/cluster.md +++ b/docs/resources/cluster.md @@ -251,7 +251,7 @@ output "faraway_replica_ids" { Here are the steps to restore a cluster: 1. Use an example config in the examples folder, uncomment the following fields restore_cluster_id=p-123456789, restore_from_deleted=true and enter your cluster id you want to restore and set to true respectively(for restoring an active cluster, set to false) 2. Use commands terraform init and terraform import biganimal_cluster.single_node_cluster prj_123456789/p-123456789/import-from-deleted to import a deleted cluster into terraform(use import biganimal_cluster.single_node_cluster prj_123456789/p-123456789 to import an active cluster) -3. Use command terraform plan to compare and diff your config with the imported cluster(source cluster) and edit config where appropriate. You can also use terraform show to see the source cluster which you can copy and paste the field values into your config. The config fields 'cloud_provider', 'pg_type', 'pg_version' and 'private_networking' cannot be changed and have to match the source cluster +3. Use command terraform plan to compare and diff your config with the imported cluster(source cluster) and edit config where appropriate. You can also use terraform show to see the source cluster which you can copy and paste the field values into your config. The config fields 'cloud_provider', 'pg_type', 'pg_version', 'pg_config' and 'private_networking' cannot be changed and have to match the source cluster 4. Remove state by deleting the file terraform.tfstate or use the commands terraform state rm 'biganimal_cluster.single_node_cluster' and terraform state rm 'random_password.password' 5. Use command terraform init and terraform apply to restore the cluster, it will show a warning saying you are trying to restore a cluster 6. Remove or comment the field restore_cluster_id=p-123456789 in the config after the restore has completed diff --git a/pkg/plan_modifier/restore_cluster_id.go b/pkg/plan_modifier/restore_cluster_id.go index f9d47970..bcec70f1 100644 --- a/pkg/plan_modifier/restore_cluster_id.go +++ b/pkg/plan_modifier/restore_cluster_id.go @@ -36,7 +36,7 @@ func (m customRestoreClusterIdModifier) PlanModifyString(ctx context.Context, re if !req.PlanValue.IsNull() { resp.Diagnostics.AddWarning( "You are restoring a cluster", - "You are restoring a cluster. The config fields 'cloud_provider', 'pg_type', 'pg_version' and 'private_networking' cannot be changed and have to match the source cluster. After restoring the cluster, please remove fields 'restore_cluster_id','restore_from_deleted' and 'restore_point' from the config", + "You are restoring a cluster. The config fields 'cloud_provider', 'pg_type', 'pg_version', 'pg_config' and 'private_networking' cannot be changed and have to match the source cluster. After restoring the cluster, please remove fields 'restore_cluster_id','restore_from_deleted' and 'restore_point' from the config", ) } } diff --git a/templates/resources/cluster.md.tmpl b/templates/resources/cluster.md.tmpl index 027afdf7..6f472e20 100644 --- a/templates/resources/cluster.md.tmpl +++ b/templates/resources/cluster.md.tmpl @@ -26,7 +26,7 @@ Please visit the [examples page](https://github.com/EnterpriseDB/terraform-provi Here are the steps to restore a cluster: 1. Use an example config in the examples folder, uncomment the following fields restore_cluster_id=p-123456789, restore_from_deleted=true and enter your cluster id you want to restore and set to true respectively(for restoring an active cluster, set to false) 2. Use commands terraform init and terraform import biganimal_cluster.single_node_cluster prj_123456789/p-123456789/import-from-deleted to import a deleted cluster into terraform(use import biganimal_cluster.single_node_cluster prj_123456789/p-123456789 to import an active cluster) -3. Use command terraform plan to compare and diff your config with the imported cluster(source cluster) and edit config where appropriate. You can also use terraform show to see the source cluster which you can copy and paste the field values into your config. The config fields 'cloud_provider', 'pg_type', 'pg_version' and 'private_networking' cannot be changed and have to match the source cluster +3. Use command terraform plan to compare and diff your config with the imported cluster(source cluster) and edit config where appropriate. You can also use terraform show to see the source cluster which you can copy and paste the field values into your config. The config fields 'cloud_provider', 'pg_type', 'pg_version', 'pg_config' and 'private_networking' cannot be changed and have to match the source cluster 4. Remove state by deleting the file terraform.tfstate or use the commands terraform state rm 'biganimal_cluster.single_node_cluster' and terraform state rm 'random_password.password' 5. Use command terraform init and terraform apply to restore the cluster, it will show a warning saying you are trying to restore a cluster 6. Remove or comment the field restore_cluster_id=p-123456789 in the config after the restore has completed From 19616a443b692534e02d822f6f8b4a43055739aa Mon Sep 17 00:00:00 2001 From: "PC-2NR0VQ3\\wai.wong" Date: Thu, 11 Jan 2024 09:26:40 +0000 Subject: [PATCH 16/16] docs: update docs --- docs/resources/cluster.md | 8 ++++---- templates/resources/cluster.md.tmpl | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/docs/resources/cluster.md b/docs/resources/cluster.md index 15991bd9..78255f63 100644 --- a/docs/resources/cluster.md +++ b/docs/resources/cluster.md @@ -250,11 +250,11 @@ output "faraway_replica_ids" { Here are the steps to restore a cluster: 1. Use an example config in the examples folder, uncomment the following fields restore_cluster_id=p-123456789, restore_from_deleted=true and enter your cluster id you want to restore and set to true respectively(for restoring an active cluster, set to false) -2. Use commands terraform init and terraform import biganimal_cluster.single_node_cluster prj_123456789/p-123456789/import-from-deleted to import a deleted cluster into terraform(use import biganimal_cluster.single_node_cluster prj_123456789/p-123456789 to import an active cluster) -3. Use command terraform plan to compare and diff your config with the imported cluster(source cluster) and edit config where appropriate. You can also use terraform show to see the source cluster which you can copy and paste the field values into your config. The config fields 'cloud_provider', 'pg_type', 'pg_version', 'pg_config' and 'private_networking' cannot be changed and have to match the source cluster +2. Use commands "terraform init" and "terraform import biganimal_cluster.single_node_cluster prj_123456789/p-123456789/import-from-deleted" to import a deleted cluster into terraform(use "terraform import biganimal_cluster.single_node_cluster prj_123456789/p-123456789" to import an active cluster) +3. Use command "terraform plan" to compare and diff your config with the imported cluster(source cluster) and edit config where appropriate. You can also use "terraform show" to see the source cluster which you can copy and paste the field values into your config. The config fields "cloud_provider", "pg_type", "pg_version", "pg_config" and "private_networking" cannot be changed and have to match the source cluster 4. Remove state by deleting the file terraform.tfstate or use the commands terraform state rm 'biganimal_cluster.single_node_cluster' and terraform state rm 'random_password.password' -5. Use command terraform init and terraform apply to restore the cluster, it will show a warning saying you are trying to restore a cluster -6. Remove or comment the field restore_cluster_id=p-123456789 in the config after the restore has completed +5. Use command "terraform init" and "terraform apply" to restore the cluster, it will show a warning saying you are trying to restore a cluster +6. Remove or comment the fields "restore_cluster_id", "restore_from_deleted" and restore_point in the config after the restore has completed ## Schema diff --git a/templates/resources/cluster.md.tmpl b/templates/resources/cluster.md.tmpl index 6f472e20..e79a6c4e 100644 --- a/templates/resources/cluster.md.tmpl +++ b/templates/resources/cluster.md.tmpl @@ -25,11 +25,11 @@ Please visit the [examples page](https://github.com/EnterpriseDB/terraform-provi Here are the steps to restore a cluster: 1. Use an example config in the examples folder, uncomment the following fields restore_cluster_id=p-123456789, restore_from_deleted=true and enter your cluster id you want to restore and set to true respectively(for restoring an active cluster, set to false) -2. Use commands terraform init and terraform import biganimal_cluster.single_node_cluster prj_123456789/p-123456789/import-from-deleted to import a deleted cluster into terraform(use import biganimal_cluster.single_node_cluster prj_123456789/p-123456789 to import an active cluster) -3. Use command terraform plan to compare and diff your config with the imported cluster(source cluster) and edit config where appropriate. You can also use terraform show to see the source cluster which you can copy and paste the field values into your config. The config fields 'cloud_provider', 'pg_type', 'pg_version', 'pg_config' and 'private_networking' cannot be changed and have to match the source cluster +2. Use commands "terraform init" and "terraform import biganimal_cluster.single_node_cluster prj_123456789/p-123456789/import-from-deleted" to import a deleted cluster into terraform(use "terraform import biganimal_cluster.single_node_cluster prj_123456789/p-123456789" to import an active cluster) +3. Use command "terraform plan" to compare and diff your config with the imported cluster(source cluster) and edit config where appropriate. You can also use "terraform show" to see the source cluster which you can copy and paste the field values into your config. The config fields "cloud_provider", "pg_type", "pg_version", "pg_config" and "private_networking" cannot be changed and have to match the source cluster 4. Remove state by deleting the file terraform.tfstate or use the commands terraform state rm 'biganimal_cluster.single_node_cluster' and terraform state rm 'random_password.password' -5. Use command terraform init and terraform apply to restore the cluster, it will show a warning saying you are trying to restore a cluster -6. Remove or comment the field restore_cluster_id=p-123456789 in the config after the restore has completed +5. Use command "terraform init" and "terraform apply" to restore the cluster, it will show a warning saying you are trying to restore a cluster +6. Remove or comment the fields "restore_cluster_id", "restore_from_deleted" and restore_point in the config after the restore has completed {{ .SchemaMarkdown | trimspace }} {{- if .HasImport }}