diff --git a/CHANGELOG.md b/CHANGELOG.md index d2a9086a2..5aa4303e8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,64 @@ +## 2024-09-17 + +### Enhanced + +- Updated `duplocloud_gcp_sql_database_instance` to handle `ip_address` as a list of strings. +- Improved formatting and corrected typos in the `database_version` field description. + +## 2024-09-16 + +### Enhanced + +- Improved handling of Performance Insights configuration for RDS read replicas, particularly for Aurora clusters. +- Enhanced RDS instance and read replica schemas by adding `DiffSuppressFunc` to suppress changes when Performance Insights is disabled. + +### Documentation + +- Updated documentation and examples to reflect changes in Performance Insights configuration, providing clearer guidance on referencing from primary resources. + +## 2024-09-13 + +### Enhanced + +- Added `DiffSuppressFunc` to suppress diffs for `performance_insights` when disabled in RDS instance and read replica schemas. +- Modified logic to always set `performance_insights` state, regardless of enablement status. +- Implemented validation to prevent Aurora read replicas from having performance insights configurations, as these are managed at the cluster level. + +### Documentation + +- Updated documentation to specify that the retention period for DocumentDB is 7 days. + +## 2024-09-12 + +### Enhanced + +- Added `ForceNew` property to the `availability_zone` attribute in RDS instances to ensure replacement on change. +- Improved handling of performance insights attributes by setting them only when enabled, preventing unnecessary diffs. + +## 2024-09-11 + +### Enhanced + +- Added performance insights configuration to RDS read replica resources, allowing for improved database performance monitoring and tuning. +- Implemented logic to handle performance insights for both primary and read replica RDS instances, including waiting for insights to be enabled. +- Updated validation and update processes to support performance insights for read replicas, ensuring consistent application of settings. + +## 2024-09-10 + +### Documentation + +- Updated RDS instance documentation to clarify performance insights configuration and defaults. +- Revised examples to include DocumentDB with performance insights. + +## 2024-09-10 + +### Enhanced + +- Enabled performance insights for DocumentDB in RDS instances by updating the create and update context logic. +- Modified validation logic for RDS parameters to support DocumentDB performance insights. +- Added `ApplyImmediately` option for performance insights updates to apply changes immediately. +- Increased the delete timeout for MWAA environments to 60 minutes to accommodate longer deletion times. + ## 2024-09-10 ### Enhanced diff --git a/Makefile b/Makefile index 2e6e0bf6d..02fc25fa1 100644 --- a/Makefile +++ b/Makefile @@ -8,7 +8,7 @@ NAMESPACE=duplocloud NAME=duplocloud BINARY=terraform-provider-${NAME} -VERSION=0.10.47 +VERSION=0.10.48 #mac #OS_ARCH=darwin_amd64 #OS_ARCH=linux_amd64 diff --git a/docs/resources/gcp_sql_database_instance.md b/docs/resources/gcp_sql_database_instance.md index a91be9a82..383508822 100644 --- a/docs/resources/gcp_sql_database_instance.md +++ b/docs/resources/gcp_sql_database_instance.md @@ -36,7 +36,7 @@ resource "duplocloud_gcp_sql_database_instance" "sql_instance" { ### Required -- `database_version` (String) The MySQL, PostgreSQL orSQL Server version to use.Supported values include `MYSQL_5_6`,`MYSQL_5_7`, `MYSQL_8_0`, `POSTGRES_9_6`,`POSTGRES_10`,`POSTGRES_11`,`POSTGRES_12`, `POSTGRES_13`, `POSTGRES_14`, `POSTGRES_15`, `SQLSERVER_2017_STANDARD`,`SQLSERVER_2017_ENTERPRISE`,`SQLSERVER_2017_EXPRESS`, `SQLSERVER_2017_WEB`.`SQLSERVER_2019_STANDARD`, `SQLSERVER_2019_ENTERPRISE`, `SQLSERVER_2019_EXPRESS`,`SQLSERVER_2019_WEB`.[Database Version Policies](https://cloud.google.com/sql/docs/db-versions)includes an up-to-date reference of supported versions. +- `database_version` (String) The MySQL, PostgreSQL or SQL Server version to use.Supported values include `MYSQL_5_6`,`MYSQL_5_7`, `MYSQL_8_0`, `POSTGRES_9_6`,`POSTGRES_10`,`POSTGRES_11`,`POSTGRES_12`, `POSTGRES_13`, `POSTGRES_14`, `POSTGRES_15`, `SQLSERVER_2017_STANDARD`,`SQLSERVER_2017_ENTERPRISE`,`SQLSERVER_2017_EXPRESS`, `SQLSERVER_2017_WEB`,`SQLSERVER_2019_STANDARD`, `SQLSERVER_2019_ENTERPRISE`, `SQLSERVER_2019_EXPRESS`,`SQLSERVER_2019_WEB`.[Database Version Policies](https://cloud.google.com/sql/docs/db-versions) includes an up-to-date reference of supported versions. - `name` (String) The short name of the sql database. Duplo will add a prefix to the name. You can retrieve the full name from the `fullname` attribute. - `tenant_id` (String) The GUID of the tenant that the sql database will be created in. - `tier` (String) The machine type to use. See tiers for more details and supported versions. Postgres supports only shared-core machine types, and custom machine types such as `db-custom-2-13312`.See the [Custom Machine Type Documentation](https://cloud.google.com/compute/docs/instances/creating-instance-with-custom-machine-type#create) to learn about specifying custom machine types. @@ -51,10 +51,10 @@ resource "duplocloud_gcp_sql_database_instance" "sql_instance" { ### Read-Only -- `connection_name` (String) Connection name of the database. +- `connection_name` (String) Connection name of the database. - `fullname` (String) The full name of the sql database. - `id` (String) The ID of this resource. -- `ip_address` (String) IP address of the database. +- `ip_address` (List of String) List of IP addresses of the database. - `self_link` (String) The SelfLink of the sql database. diff --git a/docs/resources/rds_instance.md b/docs/resources/rds_instance.md index 22e567a85..5742dde37 100644 --- a/docs/resources/rds_instance.md +++ b/docs/resources/rds_instance.md @@ -254,6 +254,76 @@ resource "duplocloud_rds_instance" "mysql-db" { } ``` + +# Example for enabling performance insights in a RDS instance + +``` +resource "duplocloud_rds_instance" "mydb" { + tenant_id = data.duplocloud_tenant.tenant.id + name = "mydb1psql" + engine = 1 // PostgreSQL + engine_version = "14.11" + size = "db.t3.micro" + + master_username = "myuser" + master_password = "Qaazwedd#1" + + encrypt_storage = true + store_details_in_secret_manager = true + enhanced_monitoring = 0 + storage_type = "gp2" + performance_insights { + enabled = true + retention_period = 7 + } +} +``` + +# Example for enabling performance insights in a RDS cluster + +``` +resource "duplocloud_rds_instance" "mydb" { + tenant_id = data.duplocloud_tenant.tenant.id + name = "clust" + engine = 8 // PostgreSQL + engine_version = "8.0.mysql_aurora.3.07.1" + size = "db.r5.large" + + master_username = "myuser" + master_password = "Qaazwedd#1" + + encrypt_storage = true + store_details_in_secret_manager = true + enhanced_monitoring = 0 + performance_insights { + enabled = true + retention_period = 7 + } +} +``` + +# Example for enabling performance insights in a Document DB +``` +resource "duplocloud_rds_instance" "mydb" { + tenant_id = data.duplocloud_tenant.tenant.id + name = "doc" + engine = 13 + engine_version = "3.6.0" + size = "db.t3.medium" + + master_username = "myuser" + master_password = "Qaazwedd#1" + + encrypt_storage = true + store_details_in_secret_manager = true + enhanced_monitoring = 0 + performance_insights { + enabled = true + retention_period = 7 + } +} +``` + ## Schema @@ -300,7 +370,7 @@ If you don't know the available engine versions for your RDS instance, you can u - `master_username` (String) The master username of the RDS instance. - `multi_az` (Boolean) Specifies if the RDS instance is multi-AZ. - `parameter_group_name` (String) A RDS parameter group name to apply to the RDS instance. -- `performance_insights` (Block List, Max: 1) Amazon RDS Performance Insights is a database performance tuning and monitoring feature that helps you quickly assess the load on your database, and determine when and where to take action. Perfomance Insights get apply when enable is set to true. Not applicable for Cluster Db (see [below for nested schema](#nestedblock--performance_insights)) +- `performance_insights` (Block List, Max: 1) Amazon RDS Performance Insights is a database performance tuning and monitoring feature that helps you quickly assess the load on your database, and determine when and where to take action. Perfomance Insights get apply when enable is set to true. (see [below for nested schema](#nestedblock--performance_insights)) - `skip_final_snapshot` (Boolean) If the final snapshot should be taken. When set to true, the final snapshot will not be taken when the resource is deleted. Defaults to `false`. - `snapshot_id` (String) A database snapshot to initialize the RDS instance from, at launch. - `storage_type` (String) Valid values: gp2 | gp3 | io1 | standard | aurora. Storage type to be used for RDS instance storage. @@ -326,7 +396,7 @@ Optional: - `enabled` (Boolean) Turn on or off Performance Insights Defaults to `false`. - `kms_key_id` (String) Specify ARN for the KMS key to encrypt Performance Insights data. -- `retention_period` (Number) Specify retention period in Days. Valid values are 7, 731 (2 years) or a multiple of 31 +- `retention_period` (Number) Specify retention period in Days. Valid values are 7, 731 (2 years) or a multiple of 31. For Document DB retention period is 7 Defaults to `7`. diff --git a/docs/resources/rds_read_replica.md b/docs/resources/rds_read_replica.md index 2138de4f9..fb6700a04 100644 --- a/docs/resources/rds_read_replica.md +++ b/docs/resources/rds_read_replica.md @@ -37,6 +37,115 @@ resource "duplocloud_rds_read_replica" "replica" { size = "db.t2.small" cluster_identifier = duplocloud_rds_instance.rds.cluster_identifier } + +//Performance insight example for document db read replica +resource "duplocloud_rds_instance" "rds" { + tenant_id = duplocloud_tenant.myapp.tenant_id + name = "docDb" + engine = 13 + engine_version = "3.6.0" + size = "db.t3.medium" + + master_username = "myuser" + master_password = "Qaazwedd#1" + + encrypt_storage = true + store_details_in_secret_manager = true + enhanced_monitoring = 0 + +} + +resource "duplocloud_rds_read_replica" "replica" { + tenant_id = duplocloud_rds_instance.rds.tenant_id + name = "read-replica" + size = "db.t3.medium" + cluster_identifier = duplocloud_rds_instance.rds.cluster_identifier + performance_insights { + enabled = true + retention_period = 7 + } +} + + +//Performance insight example for cluster db read replica +//Performance insight for aurora cluster db is applied at cluster level +resource "duplocloud_rds_instance" "rds" { + tenant_id = duplocloud_tenant.myapp.tenant_id + name = "clust" + engine = 8 + engine_version = "8.0.mysql_aurora.3.07.1" + size = "db.r5.large" + + master_username = "myuser" + master_password = "Qaazwedd#1" + encrypt_storage = true + store_details_in_secret_manager = true + enhanced_monitoring = 0 + performance_insights { + enabled = false + retention_period = 31 + kms_key_id = "arn:aws:kms:us-west-2:182680712604:key/6b8dc967-92bf-43de-a850-ee7b945260f8" + } +} +//referencing performance insights block from writer or primary resource is must, +//to maintain tfstate to be in sync for performance insights block. +resource "duplocloud_rds_read_replica" "replica" { + tenant_id = duplocloud_rds_instance.rds.tenant_id + name = "read-replica" + size = "db.r5.large" + cluster_identifier = duplocloud_rds_instance.rds.cluster_identifier + performance_insights { + enabled = duplocloud_rds_instance.rds.performance_insights.0.enabled + retention_period = duplocloud_rds_instance.rds.performance_insights.0.retention_period + kms_key_id = duplocloud_rds_instance.rds.performance_insights.0.kms_key_id + } +} + +resource "duplocloud_rds_read_replica" "replica2" { + tenant_id = duplocloud_rds_instance.rds.tenant_id + name = "read-replica2" + size = "db.r5.large" + cluster_identifier = duplocloud_rds_instance.rds.cluster_identifier + performance_insights { + enabled = duplocloud_rds_instance.rds.performance_insights.0.enabled + retention_period = duplocloud_rds_instance.rds.performance_insights.0.retention_period + kms_key_id = duplocloud_rds_instance.rds.performance_insights.0.kms_key_id + } + +} + + +//Performance insight example for instance db read replica +resource "duplocloud_rds_instance" "mydb" { + tenant_id = duplocloud_tenant.myapp.tenant_id + name = "mydbpsql" + engine = 1 // PostgreSQL + engine_version = "14.11" + size = "db.t3.medium" + + master_username = "myuser" + master_password = "Qaazwedd#1" + + encrypt_storage = false + store_details_in_secret_manager = false + enhanced_monitoring = 0 + storage_type = "gp2" + performance_insights { + enabled = true + retention_period = 7 + } +} + +resource "duplocloud_rds_read_replica" "replica" { + tenant_id = duplocloud_rds_instance.mydb.tenant_id + name = "inst-replica" + size = "db.t3.medium" + cluster_identifier = duplocloud_rds_instance.mydb.cluster_identifier + performance_insights { + enabled = true + retention_period = 7 + } +} ``` @@ -53,6 +162,7 @@ See AWS documentation for the [available instance types](https://aws.amazon.com/ ### Optional - `availability_zone` (String) The AZ for the RDS instance. +- `performance_insights` (Block List, Max: 1) Amazon RDS Performance Insights is a database performance tuning and monitoring feature that helps you quickly assess the load on your database, and determine when and where to take action. Perfomance Insights get apply when enable is set to true. (see [below for nested schema](#nestedblock--performance_insights)) - `timeouts` (Block, Optional) (see [below for nested schema](#nestedblock--timeouts)) ### Read-Only @@ -71,6 +181,16 @@ See AWS documentation for the [available instance types](https://aws.amazon.com/ - `port` (Number) The listening port of the RDS read replica. - `replica_status` (String) The current status of the RDS read replica. + +### Nested Schema for `performance_insights` + +Optional: + +- `enabled` (Boolean) Turn on or off Performance Insights Defaults to `false`. +- `kms_key_id` (String) Specify ARN for the KMS key to encrypt Performance Insights data. +- `retention_period` (Number) Specify retention period in Days. Valid values are 7, 731 (2 years) or a multiple of 31. For Document DB retention period is 7 Defaults to `7`. + + ### Nested Schema for `timeouts` diff --git a/duplocloud/resource_duplo_aws_mwaa_environment.go b/duplocloud/resource_duplo_aws_mwaa_environment.go index f98334588..7941b5478 100644 --- a/duplocloud/resource_duplo_aws_mwaa_environment.go +++ b/duplocloud/resource_duplo_aws_mwaa_environment.go @@ -298,7 +298,7 @@ func resourceMwaaAirflow() *schema.Resource { }, Timeouts: &schema.ResourceTimeout{ Create: schema.DefaultTimeout(60 * time.Minute), - Delete: schema.DefaultTimeout(15 * time.Minute), + Delete: schema.DefaultTimeout(60 * time.Minute), }, Schema: duploMwaaAirflowSchema(), } diff --git a/duplocloud/resource_duplo_gcp_sql_database.go b/duplocloud/resource_duplo_gcp_sql_database.go index 61ecac23c..09257bf66 100644 --- a/duplocloud/resource_duplo_gcp_sql_database.go +++ b/duplocloud/resource_duplo_gcp_sql_database.go @@ -41,11 +41,11 @@ func gcpSqlDBInstanceSchema() map[string]*schema.Schema { Computed: true, }, "database_version": { - Description: "The MySQL, PostgreSQL orSQL Server version to use." + + Description: "The MySQL, PostgreSQL or SQL Server version to use." + "Supported values include `MYSQL_5_6`,`MYSQL_5_7`, `MYSQL_8_0`, `POSTGRES_9_6`,`POSTGRES_10`," + "`POSTGRES_11`,`POSTGRES_12`, `POSTGRES_13`, `POSTGRES_14`, `POSTGRES_15`, `SQLSERVER_2017_STANDARD`,`SQLSERVER_2017_ENTERPRISE`," + - "`SQLSERVER_2017_EXPRESS`, `SQLSERVER_2017_WEB`.`SQLSERVER_2019_STANDARD`, `SQLSERVER_2019_ENTERPRISE`, `SQLSERVER_2019_EXPRESS`," + - "`SQLSERVER_2019_WEB`.[Database Version Policies](https://cloud.google.com/sql/docs/db-versions)includes an up-to-date reference of supported versions.", + "`SQLSERVER_2017_EXPRESS`, `SQLSERVER_2017_WEB`,`SQLSERVER_2019_STANDARD`, `SQLSERVER_2019_ENTERPRISE`, `SQLSERVER_2019_EXPRESS`," + + "`SQLSERVER_2019_WEB`.[Database Version Policies](https://cloud.google.com/sql/docs/db-versions) includes an up-to-date reference of supported versions.", Type: schema.TypeString, Required: true, ValidateFunc: validation.StringInSlice(supportedGcpSQLDBVersions(), false), @@ -84,12 +84,13 @@ func gcpSqlDBInstanceSchema() map[string]*schema.Schema { Computed: true, }, "ip_address": { - Description: "IP address of the database.", - Type: schema.TypeString, + Description: "List of IP addresses of the database.", + Type: schema.TypeList, Computed: true, + Elem: &schema.Schema{Type: schema.TypeString}, }, "connection_name": { - Description: "Connection name of the database.", + Description: "Connection name of the database.", Type: schema.TypeString, Computed: true, }, @@ -99,7 +100,6 @@ func gcpSqlDBInstanceSchema() map[string]*schema.Schema { func checkPasswordNeeded(d *schema.ResourceData) bool { // Check the value of dependent_field - dependentFieldValue := d.Get("database_version").(string) mp := map[string]bool{ "SQLSERVER_2017_STANDARD": true, @@ -113,6 +113,7 @@ func checkPasswordNeeded(d *schema.ResourceData) bool { } return mp[dependentFieldValue] } + func resourceGcpSqlDBInstance() *schema.Resource { return &schema.Resource{ Description: "`duplocloud_gcp_sql_database_instance` manages a GCP SQL Database Instance in Duplo.", @@ -322,7 +323,7 @@ func flattenGcpSqlDBInstance(d *schema.ResourceData, tenantID string, name strin d.Set("tier", duplo.Tier) d.Set("database_version", reverseGcpSQLDBVersionsMap()[duplo.DatabaseVersion]) d.Set("disk_size", duplo.DataDiskSizeGb) - d.Set("ip_address", duplo.IPAddress) + d.Set("ip_address", flattenStringList(duplo.IPAddress)) d.Set("connection_name", duplo.ConnectionName) flattenGcpLabels(d, duplo.Labels) } diff --git a/duplocloud/resource_duplo_rds_instance.go b/duplocloud/resource_duplo_rds_instance.go index cdaf7a985..bd9396b7e 100644 --- a/duplocloud/resource_duplo_rds_instance.go +++ b/duplocloud/resource_duplo_rds_instance.go @@ -290,10 +290,11 @@ func rdsInstanceSchema() map[string]*schema.Schema { ValidateFunc: validation.IntInSlice([]int{0, 1, 5, 10, 15, 30, 60}), }, "performance_insights": { - Description: "Amazon RDS Performance Insights is a database performance tuning and monitoring feature that helps you quickly assess the load on your database, and determine when and where to take action. Perfomance Insights get apply when enable is set to true. Not applicable for Cluster Db", - Type: schema.TypeList, - MaxItems: 1, - Optional: true, + Description: "Amazon RDS Performance Insights is a database performance tuning and monitoring feature that helps you quickly assess the load on your database, and determine when and where to take action. Perfomance Insights get apply when enable is set to true.", + Type: schema.TypeList, + MaxItems: 1, + Optional: true, + DiffSuppressFunc: suppressIfPerformanceInsightsDisabled, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ "enabled": { @@ -303,20 +304,22 @@ func rdsInstanceSchema() map[string]*schema.Schema { Default: false, }, "kms_key_id": { - Description: "Specify ARN for the KMS key to encrypt Performance Insights data.", - Type: schema.TypeString, - Optional: true, - Computed: true, + Description: "Specify ARN for the KMS key to encrypt Performance Insights data.", + Type: schema.TypeString, + Optional: true, + Computed: true, + DiffSuppressFunc: suppressKmsIfPerformanceInsightsDisabled, }, "retention_period": { - Description: "Specify retention period in Days. Valid values are 7, 731 (2 years) or a multiple of 31", + Description: "Specify retention period in Days. Valid values are 7, 731 (2 years) or a multiple of 31. For Document DB retention period is 7", Type: schema.TypeInt, Optional: true, - Computed: true, + Default: 7, ValidateFunc: validation.Any( validation.IntInSlice([]int{7, 731}), validation.IntDivisibleBy(31), ), + DiffSuppressFunc: suppressRetentionPeriodIfPerformanceInsightsDisabled, }, }, }, @@ -328,6 +331,7 @@ func rdsInstanceSchema() map[string]*schema.Schema { Type: schema.TypeString, Computed: true, Optional: true, + ForceNew: true, }, } } @@ -368,13 +372,13 @@ func resourceDuploRdsInstanceRead(ctx context.Context, d *schema.ResourceData, m d.SetId("") return nil } + d.SetId(fmt.Sprintf("v2/subscriptions/%s/RDSDBInstance/%s", duplo.TenantID, duplo.Name)) // Convert the object into Terraform resource data jo := rdsInstanceToState(duplo, d) - for key := range jo { - d.Set(key, jo[key]) + for key, val := range jo { + d.Set(key, val) //jo[key]) } - d.SetId(fmt.Sprintf("v2/subscriptions/%s/RDSDBInstance/%s", duplo.TenantID, duplo.Name)) log.Printf("[TRACE] resourceDuploRdsInstanceRead ******** end") return nil @@ -429,7 +433,21 @@ func resourceDuploRdsInstanceCreate(ctx context.Context, d *schema.ResourceData, } identifier := createdRds.Identifier + pI := expandPerformanceInsight(d) + if pI != nil && duplo.Engine == RDS_DOCUMENT_DB_ENGINE { + obj := enablePerformanceInstanceObject(pI) + obj.DBInstanceIdentifier = identifier + insightErr := c.UpdateDBInstancePerformanceInsight(tenantID, obj) + if insightErr != nil { + return diag.FromErr(insightErr) + + } + err = performanceInsightsWaitUntilEnabled(ctx, c, id) + if err != nil { + return diag.Errorf("Error waiting for RDS DB instance '%s' performance insights : %s", id, err) + } + } if d.HasChange("deletion_protection") || d.HasChange("skip_final_snapshot") { skipFinalSnapshot := d.Get("skip_final_snapshot").(bool) deleteProtection := new(bool) @@ -617,31 +635,26 @@ func resourceDuploRdsInstanceUpdate(ctx context.Context, d *schema.ResourceData, obj := duplosdk.DuploRdsUpdatePerformanceInsights{} pI := expandPerformanceInsight(d) if pI != nil { - period := pI["retention_period"].(int) - kmsid := pI["kms_key_id"].(string) - enable := duplosdk.PerformanceInsightEnable{ - EnablePerformanceInsights: pI["enabled"].(bool), - PerformanceInsightsRetentionPeriod: period, - PerformanceInsightsKMSKeyId: kmsid, - } - obj.Enable = &enable + obj = enablePerformanceInstanceObject(pI) + } else { disable := duplosdk.PerformanceInsightDisable{ EnablePerformanceInsights: false, } obj.Disable = &disable } - obj.DBInstanceIdentifier = identifier + "-cluster" + obj.DBInstanceIdentifier = identifier if isAuroraDB(d) { + obj.DBInstanceIdentifier = identifier + "-cluster" insightErr := c.UpdateDBClusterPerformanceInsight(tenantID, obj) if insightErr != nil { - return diag.FromErr(err) + return diag.FromErr(insightErr) } } else { insightErr := c.UpdateDBInstancePerformanceInsight(tenantID, obj) if insightErr != nil { - return diag.FromErr(err) + return diag.FromErr(insightErr) } } @@ -659,6 +672,7 @@ func resourceDuploRdsInstanceUpdate(ctx context.Context, d *schema.ResourceData, log.Printf("[TRACE] resourceDuploRdsInstanceUpdate ******** end") return diags + } // DELETE resource @@ -796,7 +810,7 @@ func rdsInstanceFromState(d *schema.ResourceData) (*duplosdk.DuploRdsInstance, e } duploObject.DatabaseName = d.Get("db_name").(string) pI := expandPerformanceInsight(d) - if pI != nil { + if pI != nil && d.Get("engine").(int) != RDS_DOCUMENT_DB_ENGINE { period := pI["retention_period"].(int) kmsid := pI["kms_key_id"].(string) @@ -890,14 +904,12 @@ func rdsInstanceToState(duploObject *duplosdk.DuploRdsInstance, d *schema.Resour pis := []interface{}{} pi := make(map[string]interface{}) pi["enabled"] = duploObject.EnablePerformanceInsights - if duploObject.EnablePerformanceInsights { - pi["retention_period"] = duploObject.PerformanceInsightsRetentionPeriod - pi["kms_key_id"] = duploObject.PerformanceInsightsKMSKeyId - } + pi["retention_period"] = duploObject.PerformanceInsightsRetentionPeriod + pi["kms_key_id"] = duploObject.PerformanceInsightsKMSKeyId pis = append(pis, pi) jo["performance_insights"] = pis jsonData2, _ := json.Marshal(jo) - log.Printf("[TRACE] duplo-RdsInstanceToState ******** 2: OUTPUT => %s ", jsonData2) + log.Printf("[TRACE] duplo-RdsInstanceToState ******** 2: OUTPUT => %s ", string(jsonData2)) return jo } @@ -952,7 +964,7 @@ func isAuroraDB(d *schema.ResourceData) bool { func isDeleteProtectionSupported(d *schema.ResourceData) bool { // Avoid setting delete protection for document DB - return d.Get("engine").(int) != 13 + return d.Get("engine").(int) != RDS_DOCUMENT_DB_ENGINE } func isClusterGroupParameterSupportDb(db int) bool { @@ -997,7 +1009,6 @@ func validateRDSParameters(ctx context.Context, diff *schema.ResourceDiff, m int "db.t4g.micro": {}, "db.t4g.small": {}, }, - 13: {"ALL": {}}, } engines := map[int]string{ 0: "MySQL", @@ -1013,6 +1024,7 @@ func validateRDSParameters(ctx context.Context, diff *schema.ResourceDiff, m int 14: "MariaDB", 16: "Aurora", } + eng := diff.Get("engine").(int) perf_insights_enabled := false perf_insights_configuration_list := diff.Get("performance_insights").([]interface{}) @@ -1023,19 +1035,92 @@ func validateRDSParameters(ctx context.Context, diff *schema.ResourceDiff, m int if v, ok := nonsup[eng]; perf_insights_enabled && ok { s := diff.Get("size").(string) if _, ok := v[s]; ok { - if engines[eng] == "DocumentDB" { - return fmt.Errorf("RDS engine %s do not support Performance Insights at cluster level.", engines[eng]) - } return fmt.Errorf("RDS engine %s for instance size %s do not support Performance Insights.", engines[eng], s) } } - if eng == 8 || eng == 9 || eng == 16 || eng == 13 || eng == 11 || eng == 12 { - st := diff.Get("storage_type").(string) - if st != "" && st != "aurora" { - return fmt.Errorf("RDS engine %s invalid storage type %s valid value is aurora", engines[eng], st) + //if eng == 8 || eng == 9 || eng == 16 || eng == 11 || eng == 12 { + // //st := diff.Get("storage_type").(string) + // new, _ := diff.GetChange("storage_type") + // st := new.(string) + // if st != "" && st != "aurora" { + // return fmt.Errorf("RDS engine %s invalid storage type %s valid value is aurora", engines[eng], st) + // + // } + // + //} + return nil +} + +func enablePerformanceInstanceObject(pI map[string]interface{}) duplosdk.DuploRdsUpdatePerformanceInsights { + obj := duplosdk.DuploRdsUpdatePerformanceInsights{} + period := pI["retention_period"].(int) + kmsid := pI["kms_key_id"].(string) + enable := duplosdk.PerformanceInsightEnable{ + EnablePerformanceInsights: pI["enabled"].(bool), + PerformanceInsightsRetentionPeriod: period, + PerformanceInsightsKMSKeyId: kmsid, + ApplyImmediately: true, + } + obj.Enable = &enable + return obj +} + +func performanceInsightsWaitUntilEnabled(ctx context.Context, c *duplosdk.Client, id string) error { + stateConf := &retry.StateChangeConf{ + Pending: []string{"false"}, + Target: []string{"true"}, + MinTimeout: 10 * time.Second, + PollInterval: 30 * time.Second, + Timeout: 20 * time.Minute, + Refresh: func() (interface{}, string, error) { + status := "false" + resp, err := c.RdsInstanceGet(id) + if err != nil { + return 0, "", err + } + if resp.EnablePerformanceInsights { + status = "true" + } + return resp, status, nil + }, + } + log.Printf("[DEBUG] performanceInsightsWaitUntilAvailable (%s)", id) + _, err := stateConf.WaitForStateContext(ctx) + return err +} + +func suppressIfPerformanceInsightsDisabled(k, old, new string, d *schema.ResourceData) bool { + // Check if the `enable` field is set to false + oldPI, newPI := d.GetChange("performance_insights.0.enabled") + if !oldPI.(bool) && !newPI.(bool) { //both false return no change + return true + } else if oldPI.(bool) && newPI.(bool) { //both true check if kms and retention period has change + if d.HasChange("performance_insights.0.kms_key_id") || d.HasChange("performance_insights.0.retention_period") { + return false + } + return true + } + return false +} +func suppressKmsIfPerformanceInsightsDisabled(k, old, new string, d *schema.ResourceData) bool { + oldPI, newPI := d.GetChange("performance_insights.0.enabled") + if oldPI.(bool) && !newPI.(bool) { + if d.HasChange("performance_insights.0.kms_key_id") { + return true } + } + return false + +} +func suppressRetentionPeriodIfPerformanceInsightsDisabled(k, old, new string, d *schema.ResourceData) bool { + oldPI, newPI := d.GetChange("performance_insights.0.enabled") + if oldPI.(bool) && !newPI.(bool) { + if d.HasChange("performance_insights.0.retention_period") { + return true + } } - return nil + return false + } diff --git a/duplocloud/resource_duplo_rds_read_replica.go b/duplocloud/resource_duplo_rds_read_replica.go index 29716cba2..ce47d6c8a 100644 --- a/duplocloud/resource_duplo_rds_read_replica.go +++ b/duplocloud/resource_duplo_rds_read_replica.go @@ -12,6 +12,7 @@ import ( "time" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/customdiff" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" @@ -123,6 +124,41 @@ func rdsReadReplicaSchema() map[string]*schema.Schema { Type: schema.TypeString, Computed: true, }, + "performance_insights": { + Description: "Amazon RDS Performance Insights is a database performance tuning and monitoring feature that helps you quickly assess the load on your database, and determine when and where to take action. Perfomance Insights get apply when enable is set to true.", + Type: schema.TypeList, + MaxItems: 1, + Optional: true, + DiffSuppressFunc: suppressIfPerformanceInsightsDisabled, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "enabled": { + Description: "Turn on or off Performance Insights", + Type: schema.TypeBool, + Optional: true, + Default: false, + }, + "kms_key_id": { + Description: "Specify ARN for the KMS key to encrypt Performance Insights data.", + Type: schema.TypeString, + Optional: true, + Computed: true, + DiffSuppressFunc: suppressKmsIfPerformanceInsightsDisabled, + }, + "retention_period": { + Description: "Specify retention period in Days. Valid values are 7, 731 (2 years) or a multiple of 31. For Document DB retention period is 7", + Type: schema.TypeInt, + Optional: true, + Default: 7, + ValidateFunc: validation.Any( + validation.IntInSlice([]int{7, 731}), + validation.IntDivisibleBy(31), + ), + DiffSuppressFunc: suppressRetentionPeriodIfPerformanceInsightsDisabled, + }, + }, + }, + }, } } @@ -143,7 +179,8 @@ func resourceDuploRdsReadReplica() *schema.Resource { Update: schema.DefaultTimeout(20 * time.Minute), Delete: schema.DefaultTimeout(20 * time.Minute), }, - Schema: rdsReadReplicaSchema(), + Schema: rdsReadReplicaSchema(), + CustomizeDiff: customdiff.All(validateRDSParameters), } } @@ -204,13 +241,25 @@ func resourceDuploRdsReadReplicaCreate(ctx context.Context, d *schema.ResourceDa } id := fmt.Sprintf("v2/subscriptions/%s/RDSDBInstance/%s", tenantID, duplo.Name) + pI := expandPerformanceInsight(d) + + if pI != nil && duplo.Engine != RDS_DOCUMENT_DB_ENGINE && !validateReplicaPerformanceInsightsConfigurationAuroaDB(duplo.Engine, d) { + + period := pI["retention_period"].(int) + kmsid := pI["kms_key_id"].(string) + duplo.EnablePerformanceInsights = pI["enabled"].(bool) + duplo.PerformanceInsightsRetentionPeriod = period + duplo.PerformanceInsightsKMSKeyId = kmsid + + } + // Validate the RDS instance. errors := validateRdsInstance(duplo) if len(errors) > 0 { return errorsToDiagnostics(fmt.Sprintf("Cannot create RDS DB read replica: %s: ", id), errors) } - _, err = c.RdsInstanceCreate(tenantID, duplo) + instResp, err := c.RdsInstanceCreate(tenantID, duplo) if err != nil { return diag.Errorf("Error creating RDS DB read replica '%s': %s", id, err) } @@ -223,12 +272,26 @@ func resourceDuploRdsReadReplicaCreate(ctx context.Context, d *schema.ResourceDa if diags != nil { return diags } - // Wait for the instance to become available. err = rdsReadReplicaWaitUntilAvailable(ctx, c, id, d.Timeout("create")) if err != nil { return diag.Errorf("Error waiting for RDS DB read replica '%s' to be available: %s", id, err) } + //performance insights update for document db specific + if pI != nil && duplo.Engine == RDS_DOCUMENT_DB_ENGINE { + obj := enablePerformanceInstanceObject(pI) + obj.DBInstanceIdentifier = instResp.Identifier + insightErr := c.UpdateDBInstancePerformanceInsight(tenantID, obj) + if insightErr != nil { + return diag.FromErr(insightErr) + + } + err = performanceInsightsWaitUntilEnabled(ctx, c, id) + if err != nil { + return diag.Errorf("Error waiting for RDS DB instance '%s' to be available: %s", id, err) + } + + } diags = resourceDuploRdsReadReplicaRead(ctx, d, m) @@ -238,7 +301,52 @@ func resourceDuploRdsReadReplicaCreate(ctx context.Context, d *schema.ResourceDa // UPDATE resource func resourceDuploRdsReadReplicaUpdate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { - return nil + var err error + + c := m.(*duplosdk.Client) + tenantID := d.Get("tenant_id").(string) + id := d.Id() + identifier := d.Get("identifier").(string) + + obj := duplosdk.DuploRdsUpdatePerformanceInsights{} + pI := expandPerformanceInsight(d) + if pI != nil { + period := pI["retention_period"].(int) + kmsid := pI["kms_key_id"].(string) + enable := duplosdk.PerformanceInsightEnable{ + EnablePerformanceInsights: pI["enabled"].(bool), + PerformanceInsightsRetentionPeriod: period, + PerformanceInsightsKMSKeyId: kmsid, + } + obj.Enable = &enable + } else { + disable := duplosdk.PerformanceInsightDisable{ + EnablePerformanceInsights: false, + } + obj.Disable = &disable + } + obj.DBInstanceIdentifier = identifier + if !isAuroraDB(d) { + insightErr := c.UpdateDBInstancePerformanceInsight(tenantID, obj) + if insightErr != nil { + return diag.FromErr(insightErr) + + } + + } + // Wait for the instance to become unavailable - but continue on if we timeout, without any errors raised. + _ = readReplicaInstanceWaitUntilUnavailable(ctx, c, id, 150*time.Second) + + // Wait for the instance to become available. + err = rdsReadReplicaWaitUntilAvailable(ctx, c, id, d.Timeout("update")) + if err != nil { + return diag.Errorf("Error waiting for RDS DB instance '%s' to be available: %s", id, err) + } + + diags := resourceDuploRdsReadReplicaRead(ctx, d, m) + + log.Printf("[TRACE] resourceDuploRdsReadReplicaUpdate ******** end") + return diags } // DELETE resource @@ -295,6 +403,36 @@ func rdsReadReplicaWaitUntilAvailable(ctx context.Context, c *duplosdk.Client, i return err } +// ReadReplicaInstanceWaitUntilUnavailable waits until an RDS instance is unavailable. +// +// It should be usable post-modification. +func readReplicaInstanceWaitUntilUnavailable(ctx context.Context, c *duplosdk.Client, id string, timeout time.Duration) error { + stateConf := &retry.StateChangeConf{ + Target: []string{ + "processing", "backing-up", "backtracking", "configuring-enhanced-monitoring", "configuring-iam-database-auth", "configuring-log-exports", "creating", + "maintenance", "modifying", "moving-to-vpc", "rebooting", "renaming", + "resetting-master-credentials", "starting", "stopping", "storage-optimization", "upgrading", + }, + Pending: []string{"available"}, + MinTimeout: 10 * time.Second, + PollInterval: 30 * time.Second, + Timeout: timeout, + Refresh: func() (interface{}, string, error) { + resp, err := c.RdsInstanceGet(id) + if err != nil { + return 0, "", err + } + if resp.InstanceStatus == "" { + resp.InstanceStatus = "available" + } + return resp, resp.InstanceStatus, nil + }, + } + log.Printf("[DEBUG] RdsInstanceWaitUntilUnavailable (%s)", id) + _, err := stateConf.WaitForStateContext(ctx) + return err +} + // RdsInstanceFromState converts resource data respresenting an RDS read replica to a Duplo SDK object. func rdsReadReplicaFromState(d *schema.ResourceData) (*duplosdk.DuploRdsInstance, error) { duploObject := new(duplosdk.DuploRdsInstance) @@ -302,6 +440,7 @@ func rdsReadReplicaFromState(d *schema.ResourceData) (*duplosdk.DuploRdsInstance duploObject.Identifier = d.Get("name").(string) duploObject.SizeEx = d.Get("size").(string) duploObject.AvailabilityZone = d.Get("availability_zone").(string) + return duploObject, nil } @@ -342,9 +481,42 @@ func rdsReadReplicaToState(duploObject *duplosdk.DuploRdsInstance, d *schema.Res clusterIdentifier = duploObject.ReplicationSourceIdentifier } jo["cluster_identifier"] = clusterIdentifier + pis := []interface{}{} + pi := make(map[string]interface{}) + pi["enabled"] = duploObject.EnablePerformanceInsights + pi["retention_period"] = duploObject.PerformanceInsightsRetentionPeriod + pi["kms_key_id"] = duploObject.PerformanceInsightsKMSKeyId + pis = append(pis, pi) + jo["performance_insights"] = pis jsonData2, _ := json.Marshal(jo) log.Printf("[TRACE] duplo-RdsInstanceToState ******** 2: OUTPUT => %s ", jsonData2) return jo } + +func validateReplicaPerformanceInsightsConfigurationAuroaDB(engineCode int, tfSpecification *schema.ResourceData) bool { + if isEngineAuroraType(engineCode) && hasPerformanceInsightConfigurations(tfSpecification) { + return true + } + return false +} + +func isEngineAuroraType(engineCode int) bool { + engineNameByCode := map[int]string{ + 8: "AuroraMySql", + 9: "AuroraPostgreSql", + 11: "AuroraServerlessMySql", + 12: "AuroraServerlessPostgreSql", + 16: "Aurora", + } + + value, ok := engineNameByCode[engineCode] + + return ok && strings.HasPrefix(value, "Aurora") +} + +func hasPerformanceInsightConfigurations(tfRdsReplicaSpecification *schema.ResourceData) bool { + configuration := tfRdsReplicaSpecification.Get("performance_insights").([]interface{}) + return len(configuration) > 0 +} diff --git a/duplocloud/utils.go b/duplocloud/utils.go index 149ee5072..23c5963e7 100644 --- a/duplocloud/utils.go +++ b/duplocloud/utils.go @@ -26,6 +26,7 @@ const ( MAX_DUPLO_LENGTH = len("duplo-") MAX_DUPLOSERVICES_LENGTH = len("duploservices-1234567890ab-") MAX_DUPLOSERVICES_AND_SUFFIX_LENGTH = len("duploservices-1234567890ab--1234567890ab") + RDS_DOCUMENT_DB_ENGINE = 13 ) // Utility function to make a single schema element computed. diff --git a/duplosdk/gcp_sql_database.go b/duplosdk/gcp_sql_database.go index c23723612..df3ac9e7f 100644 --- a/duplosdk/gcp_sql_database.go +++ b/duplosdk/gcp_sql_database.go @@ -76,7 +76,7 @@ type DuploGCPSqlDBInstance struct { Labels map[string]string `json:"labels,omitempty"` SelfLink string `json:"SelfLink,omitempty"` RootPassword string `json:"RootPassword,omitempty"` - IPAddress string `json:"IpAddress,omitempty"` + IPAddress []string `json:"IpAddress,omitempty"` ConnectionName string `json:"ConnectionName,omitempty"` } diff --git a/duplosdk/rds_instance.go b/duplosdk/rds_instance.go index df774909c..e78c3f8c7 100644 --- a/duplosdk/rds_instance.go +++ b/duplosdk/rds_instance.go @@ -73,7 +73,7 @@ type DuploRdsInstance struct { EnableIamAuth bool `json:"EnableIamAuth"` MonitoringInterval int `json:"MonitoringInterval"` DatabaseName string `json:"DatabaseName,omitempty"` - EnablePerformanceInsights bool `json:"EnablePerformanceInsights,omitempty"` + EnablePerformanceInsights bool `json:"EnablePerformanceInsights"` PerformanceInsightsRetentionPeriod int `json:"PerformanceInsightsRetentionPeriod,omitempty"` PerformanceInsightsKMSKeyId string `json:"PerformanceInsightsKMSKeyId,omitempty"` } @@ -112,6 +112,7 @@ type PerformanceInsightEnable struct { EnablePerformanceInsights bool `json:"EnablePerformanceInsights"` PerformanceInsightsRetentionPeriod int `json:"PerformanceInsightsRetentionPeriod,omitempty"` PerformanceInsightsKMSKeyId string `json:"PerformanceInsightsKMSKeyId,omitempty"` + ApplyImmediately bool `json:"ApplyImmediately"` } type PerformanceInsightDisable struct { EnablePerformanceInsights bool `json:"EnablePerformanceInsights"` diff --git a/examples/aws-integration/main.tf b/examples/aws-integration/main.tf index e83f0e75f..53e777de5 100644 --- a/examples/aws-integration/main.tf +++ b/examples/aws-integration/main.tf @@ -1,7 +1,7 @@ terraform { required_providers { duplocloud = { - version = "0.10.47" # RELEASE VERSION + version = "0.10.48" # RELEASE VERSION source = "registry.terraform.io/duplocloud/duplocloud" } aws = { diff --git a/examples/ecs/main.tf b/examples/ecs/main.tf index 377c4639d..b9f17147d 100644 --- a/examples/ecs/main.tf +++ b/examples/ecs/main.tf @@ -1,7 +1,7 @@ terraform { required_providers { duplocloud = { - version = "0.10.47" # RELEASE VERSION + version = "0.10.48" # RELEASE VERSION source = "registry.terraform.io/duplocloud/duplocloud" } } diff --git a/examples/eks-integration/main.tf b/examples/eks-integration/main.tf index 73666be36..12cf7b400 100644 --- a/examples/eks-integration/main.tf +++ b/examples/eks-integration/main.tf @@ -1,7 +1,7 @@ terraform { required_providers { duplocloud = { - version = "0.10.47" # RELEASE VERSION + version = "0.10.48" # RELEASE VERSION source = "registry.terraform.io/duplocloud/duplocloud" } aws = { diff --git a/examples/emr/files/emr_auto_scaling/main.tf b/examples/emr/files/emr_auto_scaling/main.tf index 105c53817..6d0cf4957 100644 --- a/examples/emr/files/emr_auto_scaling/main.tf +++ b/examples/emr/files/emr_auto_scaling/main.tf @@ -1,7 +1,7 @@ terraform { required_providers { duplocloud = { - version = "0.10.47" # RELEASE VERSION + version = "0.10.48" # RELEASE VERSION source = "registry.terraform.io/duplocloud/duplocloud" } } diff --git a/examples/emr/files/emr_spot/main.tf b/examples/emr/files/emr_spot/main.tf index 9d109d639..31dbe363a 100644 --- a/examples/emr/files/emr_spot/main.tf +++ b/examples/emr/files/emr_spot/main.tf @@ -1,7 +1,7 @@ terraform { required_providers { duplocloud = { - version = "0.10.47" # RELEASE VERSION + version = "0.10.48" # RELEASE VERSION source = "registry.terraform.io/duplocloud/duplocloud" } } diff --git a/examples/emr/main.tf b/examples/emr/main.tf index ebc043ee0..9709d85d1 100644 --- a/examples/emr/main.tf +++ b/examples/emr/main.tf @@ -1,7 +1,7 @@ terraform { required_providers { duplocloud = { - version = "0.10.47" # RELEASE VERSION + version = "0.10.48" # RELEASE VERSION source = "registry.terraform.io/duplocloud/duplocloud" } } diff --git a/examples/ephemeral-storage/main.tf b/examples/ephemeral-storage/main.tf index 798149ac4..0473b1661 100644 --- a/examples/ephemeral-storage/main.tf +++ b/examples/ephemeral-storage/main.tf @@ -1,7 +1,7 @@ terraform { required_providers { duplocloud = { - version = "0.10.47" # RELEASE VERSION + version = "0.10.48" # RELEASE VERSION source = "registry.terraform.io/duplocloud/duplocloud" } } diff --git a/examples/infrastructure/main.tf b/examples/infrastructure/main.tf index 0822bdeb9..f7d4695b4 100644 --- a/examples/infrastructure/main.tf +++ b/examples/infrastructure/main.tf @@ -1,7 +1,7 @@ terraform { required_providers { duplocloud = { - version = "0.10.47" # RELEASE VERSION + version = "0.10.48" # RELEASE VERSION source = "registry.terraform.io/duplocloud/duplocloud" } } diff --git a/examples/k8/main.tf b/examples/k8/main.tf index 2a2cd7448..1c1128c64 100644 --- a/examples/k8/main.tf +++ b/examples/k8/main.tf @@ -1,7 +1,7 @@ terraform { required_providers { duplocloud = { - version = "0.10.47" # RELEASE VERSION + version = "0.10.48" # RELEASE VERSION source = "registry.terraform.io/duplocloud/duplocloud" } } diff --git a/examples/resources/duplocloud_rds_instance/resource.tf b/examples/resources/duplocloud_rds_instance/resource.tf index a6b5bb210..92551e0c5 100644 --- a/examples/resources/duplocloud_rds_instance/resource.tf +++ b/examples/resources/duplocloud_rds_instance/resource.tf @@ -63,12 +63,11 @@ resource "duplocloud_rds_instance" "mydb" { } } -#performance insigts example for cluster - +//performance insights cluster example resource "duplocloud_rds_instance" "mydb" { tenant_id = duplocloud_tenant.myapp.tenant_id name = "clust" - engine = 8 + engine = 8 // PostgreSQL engine_version = "8.0.mysql_aurora.3.07.1" size = "db.r5.large" @@ -78,7 +77,27 @@ resource "duplocloud_rds_instance" "mydb" { encrypt_storage = true store_details_in_secret_manager = true enhanced_monitoring = 0 - storage_type = "aurora" + performance_insights { + enabled = true + retention_period = 7 + } +} + +//performance insights document db example + +resource "duplocloud_rds_instance" "mydb" { + tenant_id = duplocloud_tenant.myapp.tenant_id + name = "doc" + engine = 13 + engine_version = "3.6.0" + size = "db.t3.medium" + + master_username = "myuser" + master_password = "Qaazwedd#1" + + encrypt_storage = true + store_details_in_secret_manager = true + enhanced_monitoring = 0 performance_insights { enabled = true retention_period = 7 diff --git a/examples/resources/duplocloud_rds_read_replica/resource.tf b/examples/resources/duplocloud_rds_read_replica/resource.tf index a35dc9497..beb15ca05 100644 --- a/examples/resources/duplocloud_rds_read_replica/resource.tf +++ b/examples/resources/duplocloud_rds_read_replica/resource.tf @@ -22,3 +22,112 @@ resource "duplocloud_rds_read_replica" "replica" { size = "db.t2.small" cluster_identifier = duplocloud_rds_instance.rds.cluster_identifier } + +//Performance insight example for document db read replica +resource "duplocloud_rds_instance" "rds" { + tenant_id = duplocloud_tenant.myapp.tenant_id + name = "docDb" + engine = 13 + engine_version = "3.6.0" + size = "db.t3.medium" + + master_username = "myuser" + master_password = "Qaazwedd#1" + + encrypt_storage = true + store_details_in_secret_manager = true + enhanced_monitoring = 0 + +} + +resource "duplocloud_rds_read_replica" "replica" { + tenant_id = duplocloud_rds_instance.rds.tenant_id + name = "read-replica" + size = "db.t3.medium" + cluster_identifier = duplocloud_rds_instance.rds.cluster_identifier + performance_insights { + enabled = true + retention_period = 7 + } +} + + +//Performance insight example for cluster db read replica +//Performance insight for aurora cluster db is applied at cluster level +resource "duplocloud_rds_instance" "rds" { + tenant_id = duplocloud_tenant.myapp.tenant_id + name = "clust" + engine = 8 + engine_version = "8.0.mysql_aurora.3.07.1" + size = "db.r5.large" + + master_username = "myuser" + master_password = "Qaazwedd#1" + encrypt_storage = true + store_details_in_secret_manager = true + enhanced_monitoring = 0 + performance_insights { + enabled = false + retention_period = 31 + kms_key_id = "arn:aws:kms:us-west-2:182680712604:key/6b8dc967-92bf-43de-a850-ee7b945260f8" + } +} +//referencing performance insights block from writer or primary resource is must, +//to maintain tfstate to be in sync for performance insights block. +resource "duplocloud_rds_read_replica" "replica" { + tenant_id = duplocloud_rds_instance.rds.tenant_id + name = "read-replica" + size = "db.r5.large" + cluster_identifier = duplocloud_rds_instance.rds.cluster_identifier + performance_insights { + enabled = duplocloud_rds_instance.rds.performance_insights.0.enabled + retention_period = duplocloud_rds_instance.rds.performance_insights.0.retention_period + kms_key_id = duplocloud_rds_instance.rds.performance_insights.0.kms_key_id + } +} + +resource "duplocloud_rds_read_replica" "replica2" { + tenant_id = duplocloud_rds_instance.rds.tenant_id + name = "read-replica2" + size = "db.r5.large" + cluster_identifier = duplocloud_rds_instance.rds.cluster_identifier + performance_insights { + enabled = duplocloud_rds_instance.rds.performance_insights.0.enabled + retention_period = duplocloud_rds_instance.rds.performance_insights.0.retention_period + kms_key_id = duplocloud_rds_instance.rds.performance_insights.0.kms_key_id + } + +} + + +//Performance insight example for instance db read replica +resource "duplocloud_rds_instance" "mydb" { + tenant_id = duplocloud_tenant.myapp.tenant_id + name = "mydbpsql" + engine = 1 // PostgreSQL + engine_version = "14.11" + size = "db.t3.medium" + + master_username = "myuser" + master_password = "Qaazwedd#1" + + encrypt_storage = false + store_details_in_secret_manager = false + enhanced_monitoring = 0 + storage_type = "gp2" + performance_insights { + enabled = true + retention_period = 7 + } +} + +resource "duplocloud_rds_read_replica" "replica" { + tenant_id = duplocloud_rds_instance.mydb.tenant_id + name = "inst-replica" + size = "db.t3.medium" + cluster_identifier = duplocloud_rds_instance.mydb.cluster_identifier + performance_insights { + enabled = true + retention_period = 7 + } +} \ No newline at end of file diff --git a/examples/service/main.tf b/examples/service/main.tf index 5ce209674..7ef80ee19 100644 --- a/examples/service/main.tf +++ b/examples/service/main.tf @@ -1,7 +1,7 @@ terraform { required_providers { duplocloud = { - version = "0.10.47" # RELEASE VERSION + version = "0.10.48" # RELEASE VERSION source = "registry.terraform.io/duplocloud/duplocloud" } } diff --git a/templates/resources/rds_instance.md.tmpl b/templates/resources/rds_instance.md.tmpl index 23964e77b..09bd72c13 100644 --- a/templates/resources/rds_instance.md.tmpl +++ b/templates/resources/rds_instance.md.tmpl @@ -254,6 +254,76 @@ resource "duplocloud_rds_instance" "mysql-db" { } ``` + +# Example for enabling performance insights in a RDS instance + +``` +resource "duplocloud_rds_instance" "mydb" { + tenant_id = data.duplocloud_tenant.tenant.id + name = "mydb1psql" + engine = 1 // PostgreSQL + engine_version = "14.11" + size = "db.t3.micro" + + master_username = "myuser" + master_password = "Qaazwedd#1" + + encrypt_storage = true + store_details_in_secret_manager = true + enhanced_monitoring = 0 + storage_type = "gp2" + performance_insights { + enabled = true + retention_period = 7 + } +} +``` + +# Example for enabling performance insights in a RDS cluster + +``` +resource "duplocloud_rds_instance" "mydb" { + tenant_id = data.duplocloud_tenant.tenant.id + name = "clust" + engine = 8 // PostgreSQL + engine_version = "8.0.mysql_aurora.3.07.1" + size = "db.r5.large" + + master_username = "myuser" + master_password = "Qaazwedd#1" + + encrypt_storage = true + store_details_in_secret_manager = true + enhanced_monitoring = 0 + performance_insights { + enabled = true + retention_period = 7 + } +} +``` + +# Example for enabling performance insights in a Document DB +``` +resource "duplocloud_rds_instance" "mydb" { + tenant_id = data.duplocloud_tenant.tenant.id + name = "doc" + engine = 13 + engine_version = "3.6.0" + size = "db.t3.medium" + + master_username = "myuser" + master_password = "Qaazwedd#1" + + encrypt_storage = true + store_details_in_secret_manager = true + enhanced_monitoring = 0 + performance_insights { + enabled = true + retention_period = 7 + } +} +``` + {{ .SchemaMarkdown | trimspace }} ## Import