Skip to content

Commit

Permalink
Merge branch 'main' into ww-scheduled-backup-time
Browse files Browse the repository at this point in the history
# Conflicts:
#	pkg/models/cluster.go
#	pkg/models/pgd/api/data_group.go
#	pkg/models/pgd/terraform/data_group.go
#	pkg/provider/common.go
#	pkg/provider/data_source_cluster.go
#	pkg/provider/data_source_fareplica.go
#	pkg/provider/data_source_pgd.go
#	pkg/provider/resource_cluster.go
#	pkg/provider/resource_fareplica.go
#	pkg/provider/resource_pgd.go
  • Loading branch information
wai-wong-edb committed Nov 28, 2024
2 parents 2d8b635 + 4a868a5 commit 980ded5
Show file tree
Hide file tree
Showing 29 changed files with 327 additions and 25 deletions.
4 changes: 4 additions & 0 deletions examples/data-sources/biganimal_cluster/data-source.tf
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,10 @@ output "storage" {
value = data.biganimal_cluster.this.storage
}

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

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

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

output "volume_snapshot_backup" {
value = data.biganimal_faraway_replica.this.volume_snapshot_backup
}
6 changes: 6 additions & 0 deletions examples/resources/biganimal_cluster/ha/resource.tf
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,12 @@ resource "biganimal_cluster" "ha_cluster" {
size = "4 Gi"
}

# wal_storage = {
# volume_type = "gp3"
# volume_properties = "gp3"
# size = "4 Gi"
# }

maintenance_window = {
is_enabled = true
start_day = 6
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,12 @@ resource "biganimal_cluster" "single_node_cluster" {
size = "4 Gi"
}

# wal_storage = {
# volume_type = "gp3"
# volume_properties = "gp3"
# size = "4 Gi"
# }

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

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

maintenance_window = {
is_enabled = true
start_day = 6
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,12 @@ resource "biganimal_cluster" "single_node_cluster" {
size = "10 Gi"
}

# wal_storage = {
# volume_type = "pd-ssd"
# volume_properties = "pd-ssd"
# size = "10 Gi"
# }

maintenance_window = {
is_enabled = true
start_day = 6
Expand Down
5 changes: 5 additions & 0 deletions examples/resources/biganimal_faraway_replica/aws/resource.tf
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ resource "biganimal_faraway_replica" "faraway_replica" {
volume_properties = "gp3"
size = "4 Gi"
}
# wal_storage = {
# volume_type = "gp3"
# volume_properties = "gp3"
# size = "4 Gi"
# }
private_networking = false
region = "ap-south-1"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,13 @@ resource "biganimal_faraway_replica" "faraway_replica" {
storage = {
volume_type = "azurepremiumstorage"
volume_properties = "P1"
size = "4 Gi"
size = "4 Gi" # for azurepremiumstorage please check Premium storage disk sizes here: https://learn.microsoft.com/en-us/azure/virtual-machines/premium-storage-performance
}
# wal_storage = {
# volume_type = "azurepremiumstorage"
# volume_properties = "P1"
# size = "4 Gi" # for azurepremiumstorage please check Premium storage disk sizes here: https://learn.microsoft.com/en-us/azure/virtual-machines/premium-storage-performance
# }
private_networking = false
region = "australiaeast"

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

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

pg_type = "epas" #valid values ["epas", "pgextended", "postgres]"
pg_version = "15"
cloud_provider = "azure"
Expand Down Expand Up @@ -101,8 +107,13 @@ resource "biganimal_faraway_replica" "faraway_replica" {
storage = {
volume_type = "azurepremiumstorage"
volume_properties = "P1"
size = "4 Gi"
size = "4 Gi" # for azurepremiumstorage please check Premium storage disk sizes here: https://learn.microsoft.com/en-us/azure/virtual-machines/premium-storage-performance
}
# wal_storage = {
# volume_type = "azurepremiumstorage"
# volume_properties = "P1"
# size = "4 Gi" # for azurepremiumstorage please check Premium storage disk sizes here: https://learn.microsoft.com/en-us/azure/virtual-machines/premium-storage-performance
# }
private_networking = false
region = "centralindia"

Expand Down
5 changes: 5 additions & 0 deletions examples/resources/biganimal_faraway_replica/gcp/resource.tf
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ resource "biganimal_faraway_replica" "faraway_replica" {
volume_properties = "pd-ssd"
size = "4 Gi"
}
# wal_storage = {
# volume_type = "pd-ssd"
# volume_properties = "pd-ssd"
# size = "4 Gi"
# }
private_networking = false
region = "us-east1"

Expand Down
5 changes: 5 additions & 0 deletions examples/resources/biganimal_pgd/aws/data_group/resource.tf
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,11 @@ resource "biganimal_pgd" "pgd_cluster" {
volume_properties = "gp3"
size = "32 Gi"
}
# wal_storage = {
# volume_type = "gp3"
# volume_properties = "gp3"
# size = "32 Gi"
# }
pg_type = {
pg_type_id = "epas" #valid values ["epas", "pgextended", "postgres]"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,11 @@ resource "biganimal_pgd" "pgd_cluster" {
volume_properties = "gp3"
size = "32 Gi"
}
# wal_storage = {
# volume_type = "gp3"
# volume_properties = "gp3"
# size = "32 Gi"
# }
pg_type = {
pg_type_id = "epas" #valid values ["epas", "pgextended", "postgres]"
}
Expand Down Expand Up @@ -136,6 +141,11 @@ resource "biganimal_pgd" "pgd_cluster" {
volume_properties = "gp3"
size = "32 Gi"
}
# wal_storage = {
# volume_type = "gp3"
# volume_properties = "gp3"
# size = "32 Gi"
# }
pg_type = {
pg_type_id = "epas" #valid values ["epas", "pgextended", "postgres]"
}
Expand Down
10 changes: 10 additions & 0 deletions examples/resources/biganimal_pgd/azure/data_group/resource.tf
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,16 @@ resource "biganimal_pgd" "pgd_cluster" {
volume_properties = "P2"
size = "32 Gi"
}
storage = {
volume_type = "azurepremiumstorage"
volume_properties = "P2"
size = "32 Gi"
}
# wal_storage = {
# volume_type = "azurepremiumstorage"
# volume_properties = "P2"
# size = "32 Gi"
# }
pg_type = {
pg_type_id = "epas" #valid values ["epas", "pgextended", "postgres]"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,11 @@ resource "biganimal_pgd" "pgd_cluster" {
volume_properties = "P2"
size = "32 Gi"
}
# wal_storage = {
# volume_type = "azurepremiumstorage"
# volume_properties = "P2"
# size = "32 Gi"
# }
pg_type = {
pg_type_id = "epas" #valid values ["epas", "pgextended", "postgres]"
}
Expand Down Expand Up @@ -136,6 +141,11 @@ resource "biganimal_pgd" "pgd_cluster" {
volume_properties = "P2"
size = "32 Gi"
}
# wal_storage = {
# volume_type = "azurepremiumstorage"
# volume_properties = "P2"
# size = "32 Gi"
# }
pg_type = {
pg_type_id = "epas" #valid values ["epas", "pgextended", "postgres]"
}
Expand Down
5 changes: 5 additions & 0 deletions examples/resources/biganimal_pgd/gcp/data_group/resource.tf
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,11 @@ resource "biganimal_pgd" "pgd_cluster" {
volume_properties = "pd-ssd"
size = "32 Gi"
}
# wal_storage = {
# volume_type = "pd-ssd"
# volume_properties = "pd-ssd"
# size = "32 Gi"
# }
pg_type = {
pg_type_id = "epas" #valid values ["epas", "pgextended", "postgres]"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,11 @@ resource "biganimal_pgd" "pgd_cluster" {
volume_properties = "pd-ssd"
size = "32 Gi"
}
# wal_storage = {
# volume_type = "pd-ssd"
# volume_properties = "pd-ssd"
# size = "32 Gi"
# }
pg_type = {
pg_type_id = "epas" #valid values ["epas", "pgextended", "postgres]"
}
Expand Down Expand Up @@ -140,6 +145,11 @@ resource "biganimal_pgd" "pgd_cluster" {
volume_properties = "pd-ssd"
size = "32 Gi"
}
# wal_storage = {
# volume_type = "pd-ssd"
# volume_properties = "pd-ssd"
# size = "32 Gi"
# }
pg_type = {
pg_type_id = "epas" #valid values ["epas", "pgextended", "postgres]"
}
Expand Down
1 change: 1 addition & 0 deletions pkg/models/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ type Cluster struct {
EncryptionKeyResp *EncryptionKey `json:"encryptionKey,omitempty"`
PgIdentity *string `json:"pgIdentity,omitempty"`
BackupScheduleTime *string `json:"scheduleBackup,omitempty"`
WalStorage *Storage `json:"walStorage,omitempty"`
}

// IsHealthy checks to see if the cluster has the right condition 'biganimal.com/deployed'
Expand Down
1 change: 1 addition & 0 deletions pkg/models/pgd/api/data_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,5 @@ type DataGroup struct {
RoConnectionUri *string `json:"roConnectionUri,omitempty"`
ReadOnlyConnections *bool `json:"readOnlyConnections,omitempty"`
BackupScheduleTime *string `json:"scheduleBackup,omitempty"`
WalStorage *models.Storage `json:"walStorage,omitempty"`
}
1 change: 1 addition & 0 deletions pkg/models/pgd/terraform/data_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,5 @@ type DataGroup struct {
RoConnectionUri types.String `tfsdk:"ro_connection_uri"`
ReadOnlyConnections *bool `tfsdk:"read_only_connections"`
BackupScheduleTime types.String `tfsdk:"backup_schedule_time"`
WalStorage *Storage `tfsdk:"wal_storage"`
}
59 changes: 59 additions & 0 deletions pkg/plan_modifier/cloud_provider.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package plan_modifier

import (
"context"
"strings"

"github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier"
"github.com/hashicorp/terraform-plugin-go/tftypes"
)

func CustomClusterCloudProvider() planmodifier.String {
return customCloudProviderModifier{}
}

type customCloudProviderModifier struct{}

func (m customCloudProviderModifier) Description(_ context.Context) string {
return "Once set, the value of this attribute in state will not change."
}

func (m customCloudProviderModifier) MarkdownDescription(_ context.Context) string {
return "Once set, the value of this attribute in state will not change."
}

func (m customCloudProviderModifier) PlanModifyString(ctx context.Context, req planmodifier.StringRequest, resp *planmodifier.StringResponse) {
cloudProviderConfig := req.ConfigValue.ValueString()
var configObject map[string]tftypes.Value

err := req.Config.Raw.As(&configObject)
if err != nil {
resp.Diagnostics.AddError("Mapping config object in custom cloud provider modifier error", err.Error())
return
}

if !strings.Contains(cloudProviderConfig, "bah") {
peIds, ok := configObject["pe_allowed_principal_ids"]
if ok && !peIds.IsNull() {
resp.Diagnostics.AddError("your cloud account 'pe_allowed_principal_ids' field not allowed error",
"field 'pe_allowed_principal_ids' should only be set if you are using BigAnimal's cloud account e.g. 'bah:aws', please remove 'pe_allowed_principal_ids'")
return
}

saIds, ok := configObject["service_account_ids"]
if ok && !saIds.IsNull() {
resp.Diagnostics.AddError("your cloud account 'service_account_ids' field not allowed error",
"field 'service_account_ids' should only be set if you are using BigAnimal's cloud account 'bah:gcp', please remove 'service_account_ids'")
return
}
}

if strings.Contains(cloudProviderConfig, "bah") && !strings.Contains(cloudProviderConfig, "bah:gcp") {
saIds, ok := configObject["service_account_ids"]
if ok && !saIds.IsNull() {
resp.Diagnostics.AddError("your cloud account 'service_account_ids' field not allowed error",
"you are not using cloud provider 'bah:gcp', field 'service_account_ids' should only be set if you are using cloud provider 'bah:gcp', please remove 'service_account_ids'")
return
}
}
}
Loading

0 comments on commit 980ded5

Please sign in to comment.