Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

r/db_instance - add listener_endpoint + validations #28434

Merged
merged 5 commits into from
Mar 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changelog/28434.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
```release-note:enhancement
resource/aws_db_instance: Add `listener_endpoint` attribute
```

```release-note:enhancement
resource/aws_db_instance: Add plan time validations for `backup_retention_period`, `monitoring_interval`, and `monitoring_role_arn`
```
71 changes: 62 additions & 9 deletions internal/service/rds/instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,10 @@ func ResourceInstance() *schema.Resource {
ForceNew: true,
},
"backup_retention_period": {
Type: schema.TypeInt,
Optional: true,
Computed: true,
Type: schema.TypeInt,
Optional: true,
Computed: true,
ValidateFunc: validation.IntBetween(0, 35),
},
"backup_window": {
Type: schema.TypeString,
Expand Down Expand Up @@ -294,6 +295,26 @@ func ResourceInstance() *schema.Resource {
Optional: true,
Computed: true,
},
"listener_endpoint": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"address": {
Type: schema.TypeString,
Computed: true,
},
"hosted_zone_id": {
Type: schema.TypeString,
Computed: true,
},
"port": {
Type: schema.TypeInt,
Computed: true,
},
},
},
},
"maintenance_window": {
Type: schema.TypeString,
Optional: true,
Expand All @@ -318,14 +339,16 @@ func ResourceInstance() *schema.Resource {
},
},
"monitoring_interval": {
Type: schema.TypeInt,
Optional: true,
Default: 0,
Type: schema.TypeInt,
Optional: true,
Default: 0,
ValidateFunc: validation.IntInSlice([]int{0, 1, 5, 10, 15, 30, 60}),
},
"monitoring_role_arn": {
Type: schema.TypeString,
Optional: true,
Computed: true,
Type: schema.TypeString,
Optional: true,
Computed: true,
ValidateFunc: verify.ValidARN,
},
"multi_az": {
Type: schema.TypeBool,
Expand Down Expand Up @@ -1644,6 +1667,14 @@ func resourceInstanceRead(ctx context.Context, d *schema.ResourceData, meta inte
d.Set("port", v.Endpoint.Port)
}

if v.ListenerEndpoint != nil {
if err := d.Set("listener_endpoint", []interface{}{flattenEndpoint(v.ListenerEndpoint)}); err != nil {
return sdkdiag.AppendErrorf(diags, "setting listener_endpoint: %s", err)
}
} else {
d.Set("listener_endpoint", nil)
}

dbSetResourceDataEngineVersionFromInstance(d, v)

tags, err := ListTags(ctx, conn, arn)
Expand Down Expand Up @@ -2585,3 +2616,25 @@ func dbInstanceValidBlueGreenEngines() []string {
InstanceEngineMySQL,
}
}

func flattenEndpoint(apiObject *rds.Endpoint) map[string]interface{} {
if apiObject == nil {
return nil
}

tfMap := map[string]interface{}{}

if v := apiObject.Address; v != nil {
tfMap["address"] = aws.StringValue(v)
}

if v := apiObject.HostedZoneId; v != nil {
tfMap["hosted_zone_id"] = aws.StringValue(v)
}

if v := apiObject.Port; v != nil {
tfMap["port"] = aws.Int64Value(v)
}

return tfMap
}
2 changes: 2 additions & 0 deletions internal/service/rds/instance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ func TestAccRDSInstance_basic(t *testing.T) {
resource.TestCheckResourceAttrPair(resourceName, "instance_class", "data.aws_rds_orderable_db_instance.test", "instance_class"),
resource.TestCheckResourceAttr(resourceName, "iops", "0"),
resource.TestCheckResourceAttr(resourceName, "license_model", "general-public-license"),
resource.TestCheckResourceAttr(resourceName, "listener_endpoint.#", "0"),
resource.TestCheckResourceAttrSet(resourceName, "maintenance_window"),
resource.TestCheckResourceAttr(resourceName, "max_allocated_storage", "0"),
resource.TestCheckResourceAttr(resourceName, "name", "test"),
Expand Down Expand Up @@ -2827,6 +2828,7 @@ func TestAccRDSInstance_SnapshotIdentifier_multiAZSQLServer(t *testing.T) {
testAccCheckInstanceExists(ctx, sourceDbResourceName, &sourceDbInstance),
testAccCheckDBSnapshotExists(ctx, snapshotResourceName, &dbSnapshot),
testAccCheckInstanceExists(ctx, resourceName, &dbInstance),
resource.TestCheckResourceAttr(resourceName, "listener_endpoint.#", "1"),
resource.TestCheckResourceAttr(resourceName, "multi_az", "true"),
),
},
Expand Down
7 changes: 7 additions & 0 deletions website/docs/r/db_instance.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,7 @@ in a Route 53 Alias record).
* `id` - The RDS instance ID.
* `instance_class`- The RDS instance class.
* `latest_restorable_time` - The latest time, in UTC [RFC3339 format](https://tools.ietf.org/html/rfc3339#section-5.8), to which a database can be restored with point-in-time restore.
* `listener_endpoint` - Specifies the listener connection endpoint for SQL Server Always On. See [endpoint](#endpoint) below.
* `maintenance_window` - The instance maintenance window.
* `multi_az` - If the RDS instance is multi AZ enabled.
* `name` - The database name.
Expand All @@ -323,6 +324,12 @@ On Oracle and Microsoft SQL instances the following is exported additionally:

* `character_set_name` - The character set (collation) used on Oracle and Microsoft SQL instances.

### Endpoint

* `address` - Specifies the DNS address of the DB instance.
* `hosted_zone_id` - Specifies the ID that Amazon Route 53 assigns when you create a hosted zone.
* `port` - Specifies the port that the database engine is listening on.

## Timeouts

[Configuration options](https://developer.hashicorp.com/terraform/language/resources/syntax#operation-timeouts):
Expand Down