Skip to content

Commit

Permalink
feat: Add use_off_peak_window arg to auto_tune_options block for aws_…
Browse files Browse the repository at this point in the history
…opensearch_domain
  • Loading branch information
acwwat committed Mar 4, 2024
1 parent 2dc8341 commit a446792
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 4 deletions.
6 changes: 5 additions & 1 deletion internal/service/opensearch/domain.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,6 @@ func ResourceDomain() *schema.Resource {
"maintenance_schedule": {
Type: schema.TypeSet,
Optional: true,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"cron_expression_for_recurrence": {
Expand Down Expand Up @@ -221,6 +220,11 @@ func ResourceDomain() *schema.Resource {
Computed: true,
ValidateFunc: validation.StringInSlice(opensearchservice.RollbackOnDisable_Values(), false),
},
"use_off_peak_window": {
Type: schema.TypeBool,
Optional: true,
Default: false,
},
},
},
},
Expand Down
5 changes: 5 additions & 0 deletions internal/service/opensearch/domain_structure.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ func expandAutoTuneOptions(tfMap map[string]interface{}) *opensearchservice.Auto

options.DesiredState = autoTuneOptionsInput.DesiredState
options.MaintenanceSchedules = autoTuneOptionsInput.MaintenanceSchedules
options.UseOffPeakWindow = autoTuneOptionsInput.UseOffPeakWindow

options.RollbackOnDisable = aws.String(tfMap["rollback_on_disable"].(string))

Expand All @@ -83,6 +84,8 @@ func expandAutoTuneOptionsInput(tfMap map[string]interface{}) *opensearchservice
options.MaintenanceSchedules = expandAutoTuneMaintenanceSchedules(v.List())
}

options.UseOffPeakWindow = aws.Bool(tfMap["use_off_peak_window"].(bool))

return options
}

Expand Down Expand Up @@ -257,6 +260,8 @@ func flattenAutoTuneOptions(autoTuneOptions *opensearchservice.AutoTuneOptions)

m["rollback_on_disable"] = aws.StringValue(autoTuneOptions.RollbackOnDisable)

m["use_off_peak_window"] = aws.BoolValue(autoTuneOptions.UseOffPeakWindow)

return m
}

Expand Down
45 changes: 42 additions & 3 deletions internal/service/opensearch/domain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -782,7 +782,7 @@ func TestAccOpenSearchDomain_autoTuneOptions(t *testing.T) {
CheckDestroy: testAccCheckDomainDestroy(ctx),
Steps: []resource.TestStep{
{
Config: testAccDomainConfig_autoTuneOptions(rName, autoTuneStartAtTime),
Config: testAccDomainConfig_autoTuneOptionsMaintenanceSchedule(rName, autoTuneStartAtTime),
Check: resource.ComposeTestCheckFunc(
testAccCheckDomainExists(ctx, resourceName, &domain),
resource.TestCheckResourceAttr(resourceName, "engine_version", "Elasticsearch_6.7"),
Expand All @@ -796,6 +796,26 @@ func TestAccOpenSearchDomain_autoTuneOptions(t *testing.T) {
resource.TestCheckResourceAttr(resourceName, "auto_tune_options.0.maintenance_schedule.0.duration.0.unit", "HOURS"),
resource.TestCheckResourceAttr(resourceName, "auto_tune_options.0.maintenance_schedule.0.cron_expression_for_recurrence", "cron(0 0 ? * 1 *)"),
resource.TestCheckResourceAttr(resourceName, "auto_tune_options.0.rollback_on_disable", "NO_ROLLBACK"),
resource.TestCheckResourceAttr(resourceName, "auto_tune_options.0.use_off_peak_window", "false"),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateId: rName,
ImportStateVerify: true,
},
{
Config: testAccDomainConfig_autoTuneOptionsUseOffPeakWindow(rName),
Check: resource.ComposeTestCheckFunc(
testAccCheckDomainExists(ctx, resourceName, &domain),
resource.TestCheckResourceAttr(resourceName, "engine_version", "Elasticsearch_6.7"),
resource.TestMatchResourceAttr(resourceName, "kibana_endpoint", regexache.MustCompile(`.*(opensearch|es)\..*/_plugin/kibana/`)),
resource.TestCheckResourceAttr(resourceName, "auto_tune_options.#", "1"),
resource.TestCheckResourceAttr(resourceName, "auto_tune_options.0.desired_state", "ENABLED"),
resource.TestCheckResourceAttr(resourceName, "auto_tune_options.0.maintenance_schedule.#", "0"),
resource.TestCheckResourceAttr(resourceName, "auto_tune_options.0.rollback_on_disable", "NO_ROLLBACK"),
resource.TestCheckResourceAttr(resourceName, "auto_tune_options.0.use_off_peak_window", "true"),
),
},
{
Expand Down Expand Up @@ -2183,7 +2203,7 @@ resource "aws_opensearch_domain" "test" {
`, rName)
}

func testAccDomainConfig_autoTuneOptions(rName, autoTuneStartAtTime string) string {
func testAccDomainConfig_autoTuneOptionsMaintenanceSchedule(rName, autoTuneStartAtTime string) string {
return fmt.Sprintf(`
resource "aws_opensearch_domain" "test" {
domain_name = %[1]q
Expand All @@ -2207,12 +2227,31 @@ resource "aws_opensearch_domain" "test" {
}
rollback_on_disable = "NO_ROLLBACK"
}
}
`, rName, autoTuneStartAtTime)
}

func testAccDomainConfig_autoTuneOptionsUseOffPeakWindow(rName string) string {
return fmt.Sprintf(`
resource "aws_opensearch_domain" "test" {
domain_name = %[1]q
engine_version = "Elasticsearch_6.7"
ebs_options {
ebs_enabled = true
volume_size = 10
}
auto_tune_options {
desired_state = "ENABLED"
rollback_on_disable = "NO_ROLLBACK"
use_off_peak_window = true
}
}
`, rName)
}

func testAccDomainConfig_disabledEBSNullVolume(rName string) string {
return fmt.Sprintf(`
resource "aws_opensearch_domain" "test" {
Expand Down
3 changes: 3 additions & 0 deletions website/docs/r/opensearch_domain.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,10 @@ The following arguments are optional:

* `desired_state` - (Required) Auto-Tune desired state for the domain. Valid values: `ENABLED` or `DISABLED`.
* `maintenance_schedule` - (Required if `rollback_on_disable` is set to `DEFAULT_ROLLBACK`) Configuration block for Auto-Tune maintenance windows. Can be specified multiple times for each maintenance window. Detailed below.

**NOTE:** Maintenance windows are deprecated and have been replaced with [off-peak windows](https://docs.aws.amazon.com/opensearch-service/latest/developerguide/off-peak.html). Consequently, `maintenance_schedule` configuration blocks cannot be specified when `use_off_peak_window` is set to `true`.
* `rollback_on_disable` - (Optional) Whether to roll back to default Auto-Tune settings when disabling Auto-Tune. Valid values: `DEFAULT_ROLLBACK` or `NO_ROLLBACK`.
* `use_off_peak_window` - (Optional) Whether to schedule Auto-Tune optimizations that require blue/green deployments during the domain's configured daily off-peak window. Defaults to `false`.

#### maintenance_schedule

Expand Down

0 comments on commit a446792

Please sign in to comment.