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

F/adding off peak window to opensearch service #30965

Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
fb02d86
Adding offpeak window configuration to the provider for opensearch re…
Jramirezg Apr 24, 2023
417ae7b
Remove optional from schema when using required already
Jramirezg Apr 24, 2023
4eebcfa
Merge branch 'hashicorp:main' into jramirez/adding_off_peak_window
Jramirezg Apr 25, 2023
1d4a5a7
Bugfixes
Jramirezg Apr 25, 2023
9dca258
Merge remote-tracking branch 'origin/jramirez/adding_off_peak_window'…
Jramirezg Apr 25, 2023
a4daeda
Bugfixes to Update
Jramirezg Apr 25, 2023
c4be027
Adding Documentation
Jramirezg Apr 25, 2023
b50d8f1
Adding changelog entry
Jramirezg Apr 25, 2023
50ab783
Merge branch 'main' into HEAD
ewbankkit Jun 1, 2023
2e941ec
Tweak CHANGELOG entry.
ewbankkit Jun 1, 2023
210c04b
r/aws_opensearch_domain: Alphabetize attributes.
ewbankkit Jun 1, 2023
501d01c
Tidy up 'expandOffPeakWindowOptions' etc.
ewbankkit Jun 1, 2023
164b1c4
r/aws_opensearch_domain: Add and use 'flattenOffPeakWindowOptions'.
ewbankkit Jun 1, 2023
a33c47d
Add 'TestAccOpenSearchDomain_offPeakWindowOptions'.
ewbankkit Jun 1, 2023
0ac2dc2
Default value for 'off_peak_window_options.enabled' is 'true'.
ewbankkit Jun 1, 2023
33722a7
Fix acceptance test configuration typo.
ewbankkit Jun 1, 2023
b0a6dd5
r/aws_opensearch_domain: 'off_peak_window' is Computed.
ewbankkit Jun 1, 2023
b2ecf58
Fix acceptance test typos.
ewbankkit Jun 1, 2023
6e607e3
r/aws_opensearch_domain: 'off_peak_window' is fully Computed.
ewbankkit Jun 1, 2023
bd33ff0
d/aws_opensearch_domain: Alphabetize attributes.
ewbankkit Jun 1, 2023
23897f6
d/aws_opensearch_domain: Add 'off_peak_window_options' attribute.
ewbankkit Jun 1, 2023
c20f266
r/aws_opensearch_domain: Don't set 'OffPeakWindowOptions.Enabled' on …
ewbankkit Jun 1, 2023
0b9b26c
Fix 'An off-peak window is required for a domain and cannot be disabl…
ewbankkit Jun 1, 2023
4ea72ed
Fix markdown-lint 'MD009/no-trailing-spaces Trailing spaces [Expected…
ewbankkit Jun 1, 2023
c616906
Fix markdown-lint 'MD007/ul-indent Unordered list indentation'.
ewbankkit Jun 1, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/35970.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
resource/aws_opensearch_domain: Add off_peak_window_options argument
```
69 changes: 69 additions & 0 deletions internal/service/opensearch/domain.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,46 @@ func ResourceDomain() *schema.Resource {
Type: schema.TypeString,
Computed: true,
},
"off_peak_window_options": {
Type: schema.TypeList,
Optional: true,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"enabled": {
Type: schema.TypeBool,
Optional: true,
Default: false,
},
"off_peak_window": {
Type: schema.TypeList,
Optional: true,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"window_start_time": {
Type: schema.TypeList,
Optional: true,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"hours": {
Type: schema.TypeInt,
Required: true,
},
"minutes": {
Type: schema.TypeInt,
Required: true,
},
},
},
},
},
},
},
},
},
},
"auto_tune_options": {
Type: schema.TypeList,
Optional: true,
Expand Down Expand Up @@ -676,6 +716,29 @@ func resourceDomainCreate(ctx context.Context, d *schema.ResourceData, meta inte
inputCreateDomain.CognitoOptions = expandCognitoOptions(v.([]interface{}))
}

if len(d.Get("off_peak_window_options").([]interface{})) > 0 {
if v, ok := d.GetOk("off_peak_window_options"); ok {
offPeakWindowOptionsEnabled := v.([]interface{})[0].(map[string]interface{})["enabled"].(bool)
if offPeakWindowOptionsEnabled {
offPeakWindowStartTime := v.([]interface{})[0].(map[string]interface{})["off_peak_window"].([]interface{})[0].(map[string]interface{})["window_start_time"].([]interface{})[0].(map[string]interface{})
offPeakWindowHours := offPeakWindowStartTime["hours"].(int)
offPeakWindowHoursInt64 := int64(offPeakWindowHours)
offPeakWindowMinutes := offPeakWindowStartTime["minutes"].(int)
offPeakWindowMinutesInt64 := int64(offPeakWindowMinutes)
WindowStartTime := opensearchservice.WindowStartTime{
Hours: &offPeakWindowHoursInt64,
Minutes: &offPeakWindowMinutesInt64,
}
inputCreateDomain.OffPeakWindowOptions = &opensearchservice.OffPeakWindowOptions{
Enabled: aws.Bool(true),
OffPeakWindow: &opensearchservice.OffPeakWindow{
WindowStartTime: &WindowStartTime,
},
}
}
}
}

// IAM Roles can take some time to propagate if set in AccessPolicies and created in the same terraform
var out *opensearchservice.CreateDomainOutput
err = retry.RetryContext(ctx, propagationTimeout, func() *retry.RetryError {
Expand Down Expand Up @@ -892,6 +955,12 @@ func resourceDomainUpdate(ctx context.Context, d *schema.ResourceData, meta inte
if d.HasChange("advanced_options") {
input.AdvancedOptions = flex.ExpandStringMap(d.Get("advanced_options").(map[string]interface{}))
}
if d.HasChange("off_peak_window_options") {
enabled := d.Get("off_peak_window_options.0.enabled").(bool)
hours := d.Get("off_peak_window_options.0.off_peak_window.0.window_start_time.0.hours").(int)
minutes := d.Get("off_peak_window_options.0.off_peak_window.0.window_start_time.0.minutes").(int)
input.OffPeakWindowOptions = expandOffPeakWindowOptions(enabled, int64(hours), int64(minutes))
}

if d.HasChange("advanced_security_options") {
input.AdvancedSecurityOptions = expandAdvancedSecurityOptions(d.Get("advanced_security_options").([]interface{}))
Expand Down
12 changes: 12 additions & 0 deletions internal/service/opensearch/domain_structure.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,18 @@ func expandAutoTuneOptions(tfMap map[string]interface{}) *opensearchservice.Auto
return options
}

func expandOffPeakWindowOptions(enabled bool, hours int64, minutes int64) *opensearchservice.OffPeakWindowOptions {
options := &opensearchservice.OffPeakWindowOptions{}
options.Enabled = &enabled
options.OffPeakWindow = &opensearchservice.OffPeakWindow{
WindowStartTime: &opensearchservice.WindowStartTime{
Hours: aws.Int64(hours),
Minutes: aws.Int64(minutes),
},
}
return options
}

func expandAutoTuneOptionsInput(tfMap map[string]interface{}) *opensearchservice.AutoTuneOptionsInput_ {
if tfMap == nil {
return nil
Expand Down
6 changes: 6 additions & 0 deletions website/docs/d/opensearch_domain.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -93,3 +93,9 @@ The following attributes are exported:
* `security_group_ids` - Security groups used by the domain.
* `subnet_ids` - Subnets used by the domain.
* `vpc_id` - VPC used by the domain.
* `off_peak_window_options` - Off Peak update options
* `enabled` - Enabled disabled toggle for off-peak update window
* `off_peak_window`
* `window_start_time` - 10h window for updates
* `hours` - Starting hour of the 10-hour window for updates
* `minutes` - Starting minute of the 10-hour window for updates
11 changes: 11 additions & 0 deletions website/docs/r/opensearch_domain.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,7 @@ The following arguments are optional:
* `snapshot_options` - (Optional) Configuration block for snapshot related options. Detailed below. DEPRECATED. For domains running OpenSearch 5.3 and later, Amazon OpenSearch takes hourly automated snapshots, making this setting irrelevant. For domains running earlier versions, OpenSearch takes daily automated snapshots.
* `tags` - (Optional) Map of tags to assign to the resource. If configured with a provider [`default_tags` configuration block](https://registry.terraform.io/providers/hashicorp/aws/latest/docs#default_tags-configuration-block) present, tags with matching keys will overwrite those defined at the provider-level.
* `vpc_options` - (Optional) Configuration block for VPC related options. Adding or removing this configuration forces a new resource ([documentation](https://docs.aws.amazon.com/opensearch-service/latest/developerguide/vpc.html)). Detailed below.
* `off_peak_window_options` - (Optional) Configuration to add Off Peak update options. ([documentation](https://docs.aws.amazon.com/opensearch-service/latest/developerguide/off-peak.html)). Detailed below.

### advanced_security_options

Expand Down Expand Up @@ -444,6 +445,16 @@ AWS documentation: [VPC Support for Amazon OpenSearch Service Domains](https://d
* `security_group_ids` - (Optional) List of VPC Security Group IDs to be applied to the OpenSearch domain endpoints. If omitted, the default Security Group for the VPC will be used.
* `subnet_ids` - (Required) List of VPC Subnet IDs for the OpenSearch domain endpoints to be created in.

### off_peak_window_options

AWS documentation: [Off Peak Hours Support for Amazon OpenSearch Service Domains](https://docs.aws.amazon.com/opensearch-service/latest/developerguide/off-peak.html)

* `enabled` - Enabled disabled toggle for off-peak update window
* `off_peak_window` - (Optional)
* `window_start_time` - (Optional) 10h window for updates
* `hours` - (Required) Starting hour of the 10-hour window for updates
* `minutes` - (Required) Starting minute of the 10-hour window for updates

## Attributes Reference

In addition to all arguments above, the following attributes are exported:
Expand Down