From 0b6e72551ed7de71e07a029ab2155dab76a5f472 Mon Sep 17 00:00:00 2001 From: Vishal Sawale Date: Mon, 5 Aug 2024 17:50:56 +0530 Subject: [PATCH] feat: Read-only connection string for PGD --- docs/data-sources/pgd.md | 6 ++++++ docs/resources/pgd.md | 1 + .../biganimal_pgd/aws/data_group/resource.tf | 2 ++ .../biganimal_pgd/azure/data_group/resource.tf | 2 ++ .../biganimal_pgd/gcp/data_group/resource.tf | 2 ++ pkg/models/pgd/api/data_group.go | 2 ++ pkg/models/pgd/terraform/data_group.go | 2 ++ pkg/provider/data_source_pgd.go | 9 +++++++++ pkg/provider/resource_pgd.go | 13 +++++++++++++ 9 files changed, 39 insertions(+) diff --git a/docs/data-sources/pgd.md b/docs/data-sources/pgd.md index c977bd3f..44df7cc9 100644 --- a/docs/data-sources/pgd.md +++ b/docs/data-sources/pgd.md @@ -33,6 +33,10 @@ output "data_groups" { output "witness_groups" { value = data.biganimal_pgd.this.witness_groups } + +output "ro_connection_uri" { + value = data.biganimal_cluster.this.ro_connection_uri +} ``` ## PGD Data Source Example @@ -98,6 +102,7 @@ terraform { - `data_groups` (Attributes Set) Cluster data groups. (see [below for nested schema](#nestedatt--data_groups)) - `id` (String) The ID of this resource. - `witness_groups` (Attributes Set) (see [below for nested schema](#nestedatt--witness_groups)) +- `ro_connection_uri` (String) PGD Cluster read-only connection URI. Only available for high availability clusters. ### Nested Schema for `data_groups` @@ -128,6 +133,7 @@ Read-Only: - `resizing_pvc` (Set of String) Resizing PVC. - `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` (Attributes) Storage. (see [below for nested schema](#nestedatt--data_groups--storage)) +- `read_only_connections` (Boolean) Is Read-only Connections/workloads enabled. ### Nested Schema for `data_groups.allowed_ip_ranges` diff --git a/docs/resources/pgd.md b/docs/resources/pgd.md index 927e343a..e12b9e58 100644 --- a/docs/resources/pgd.md +++ b/docs/resources/pgd.md @@ -907,6 +907,7 @@ Read-Only: - `metrics_url` (String) The URL to find the metrics of this cluster. - `phase` (String) Current phase of the data group. - `resizing_pvc` (Set of String) Resizing PVC. +- `ro_connection_uri` (String) Cluster read-only connection URI. Only available for high availability clusters. ### Nested Schema for `data_groups.cloud_provider` diff --git a/examples/resources/biganimal_pgd/aws/data_group/resource.tf b/examples/resources/biganimal_pgd/aws/data_group/resource.tf index bcd8bc39..26f75ac0 100644 --- a/examples/resources/biganimal_pgd/aws/data_group/resource.tf +++ b/examples/resources/biganimal_pgd/aws/data_group/resource.tf @@ -86,6 +86,8 @@ resource "biganimal_pgd" "pgd_cluster" { start_day = 6 start_time = "13:00" } + read_only_connections = false + # pe_allowed_principal_ids = [ # # ex: 123456789012 # ] diff --git a/examples/resources/biganimal_pgd/azure/data_group/resource.tf b/examples/resources/biganimal_pgd/azure/data_group/resource.tf index eb8950f2..0c1eae94 100644 --- a/examples/resources/biganimal_pgd/azure/data_group/resource.tf +++ b/examples/resources/biganimal_pgd/azure/data_group/resource.tf @@ -86,6 +86,8 @@ resource "biganimal_pgd" "pgd_cluster" { start_day = 1 start_time = "13:00" } + read_only_connections = false + # pe_allowed_principal_ids = [ # # ex: "9334e5e6-7f47-aE61-5A4F-ee067daeEf4A" # ] diff --git a/examples/resources/biganimal_pgd/gcp/data_group/resource.tf b/examples/resources/biganimal_pgd/gcp/data_group/resource.tf index fb8f76bf..29c7361a 100644 --- a/examples/resources/biganimal_pgd/gcp/data_group/resource.tf +++ b/examples/resources/biganimal_pgd/gcp/data_group/resource.tf @@ -86,6 +86,8 @@ resource "biganimal_pgd" "pgd_cluster" { start_day = 6 start_time = "13:00" } + read_only_connections = false + # pe_allowed_principal_ids = [ # # ex: "development-data-123456" # ] diff --git a/pkg/models/pgd/api/data_group.go b/pkg/models/pgd/api/data_group.go index 2eddca0f..8821c892 100644 --- a/pkg/models/pgd/api/data_group.go +++ b/pkg/models/pgd/api/data_group.go @@ -28,4 +28,6 @@ type DataGroup struct { MaintenanceWindow *models.MaintenanceWindow `json:"maintenanceWindow,omitempty"` ServiceAccountIds *[]string `json:"serviceAccountIds,omitempty"` PeAllowedPrincipalIds *[]string `json:"peAllowedPrincipalIds,omitempty"` + RoConnectionUri *string `json:"roConnectionUri,omitempty"` + ReadOnlyConnections *bool `json:"readOnlyConnections,omitempty"` } diff --git a/pkg/models/pgd/terraform/data_group.go b/pkg/models/pgd/terraform/data_group.go index 52acdfc9..4756d334 100644 --- a/pkg/models/pgd/terraform/data_group.go +++ b/pkg/models/pgd/terraform/data_group.go @@ -31,4 +31,6 @@ type DataGroup struct { MaintenanceWindow *models.MaintenanceWindow `tfsdk:"maintenance_window"` ServiceAccountIds types.Set `tfsdk:"service_account_ids"` PeAllowedPrincipalIds types.Set `tfsdk:"pe_allowed_principal_ids"` + RoConnectionUri types.String `tfsdk:"ro_connection_uri"` + ReadOnlyConnections *bool `tfsdk:"read_only_connections"` } diff --git a/pkg/provider/data_source_pgd.go b/pkg/provider/data_source_pgd.go index a14d83b8..fb6a5abe 100644 --- a/pkg/provider/data_source_pgd.go +++ b/pkg/provider/data_source_pgd.go @@ -275,6 +275,15 @@ func (p pgdDataSource) Schema(ctx context.Context, req datasource.SchemaRequest, Computed: true, ElementType: types.StringType, }, + "ro_connection_uri": schema.SetAttribute{ + Description: "Read-only connection URI.", + Computed: true, + ElementType: types.StringType, + }, + "read_only_connections": schema.BoolAttribute{ + Description: "Is read-only connections enabled.", + Computed: true, + }, }, }, }, diff --git a/pkg/provider/resource_pgd.go b/pkg/provider/resource_pgd.go index 156d7403..2199343a 100644 --- a/pkg/provider/resource_pgd.go +++ b/pkg/provider/resource_pgd.go @@ -331,6 +331,11 @@ func PgdSchema(ctx context.Context) schema.Schema { }, }, }, + "ro_connection_uri": schema.StringAttribute{ + MarkdownDescription: "Cluster read-only connection URI.", + Computed: true, + PlanModifiers: []planmodifier.String{plan_modifier.CustomConnection()}, + }, "instance_type": schema.SingleNestedAttribute{ Description: "Instance type.", Required: true, @@ -376,6 +381,11 @@ func PgdSchema(ctx context.Context) schema.Schema { ElementType: types.StringType, PlanModifiers: []planmodifier.Set{setplanmodifier.UseStateForUnknown()}, }, + "read_only_connections": schema.BoolAttribute{ + Description: "Is read-only connections enabled.", + Optional: true, + Computed: true, + }, }, }, }, @@ -659,6 +669,7 @@ func (p pgdResource) Create(ctx context.Context, req resource.CreateRequest, res Storage: storage, ServiceAccountIds: svAccIds, PeAllowedPrincipalIds: principalIds, + ReadOnlyConnections: v.ReadOnlyConnections, } *clusterReqBody.Groups = append(*clusterReqBody.Groups, apiDGModel) } @@ -1368,6 +1379,8 @@ func buildTFGroupsAs(ctx context.Context, diags *diag.Diagnostics, state tfsdk.S MaintenanceWindow: apiDgModel.MaintenanceWindow, ServiceAccountIds: types.SetValueMust(types.StringType, serviceAccIds), PeAllowedPrincipalIds: types.SetValueMust(types.StringType, principalIds), + RoConnectionUri: types.StringPointerValue(apiDgModel.RoConnectionUri), + ReadOnlyConnections: apiDgModel.ReadOnlyConnections, } outPgdTFResource.DataGroups = append(outPgdTFResource.DataGroups, tfDGModel)