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 all 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
7 changes: 7 additions & 0 deletions .changelog/35970.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
```release-note:enhancement
resource/aws_opensearch_domain: Add `off_peak_window_options` configuration block
```

```release-note:enhancement
data-source/aws_opensearch_domain: Add `off_peak_window_options` attribute
```
125 changes: 95 additions & 30 deletions internal/service/opensearch/domain.go
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,51 @@ func ResourceDomain() *schema.Resource {
},
},
},
"off_peak_window_options": {
Type: schema.TypeList,
Optional: true,
Computed: true,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"enabled": {
Type: schema.TypeBool,
Optional: true,
Computed: true,
},
"off_peak_window": {
Type: schema.TypeList,
Optional: true,
Computed: true,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"window_start_time": {
Type: schema.TypeList,
Optional: true,
Computed: true,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"hours": {
Type: schema.TypeInt,
Optional: true,
Computed: true,
},
"minutes": {
Type: schema.TypeInt,
Optional: true,
Computed: true,
},
},
},
},
},
},
},
},
},
},
"snapshot_options": {
Type: schema.TypeList,
Optional: true,
Expand Down Expand Up @@ -563,13 +608,13 @@ func resourceDomainCreate(ctx context.Context, d *schema.ResourceData, meta inte
return sdkdiag.AppendErrorf(diags, "OpenSearch Domain %q already exists", aws.StringValue(resp.DomainName))
}

inputCreateDomain := opensearchservice.CreateDomainInput{
input := &opensearchservice.CreateDomainInput{
DomainName: aws.String(d.Get("domain_name").(string)),
TagList: GetTagsIn(ctx),
}

if v, ok := d.GetOk("engine_version"); ok {
inputCreateDomain.EngineVersion = aws.String(v.(string))
input.EngineVersion = aws.String(v.(string))
}

if v, ok := d.GetOk("access_policies"); ok {
Expand All @@ -579,19 +624,19 @@ func resourceDomainCreate(ctx context.Context, d *schema.ResourceData, meta inte
return sdkdiag.AppendErrorf(diags, "policy (%s) is invalid JSON: %s", policy, err)
}

inputCreateDomain.AccessPolicies = aws.String(policy)
input.AccessPolicies = aws.String(policy)
}

if v, ok := d.GetOk("advanced_options"); ok {
inputCreateDomain.AdvancedOptions = flex.ExpandStringMap(v.(map[string]interface{}))
input.AdvancedOptions = flex.ExpandStringMap(v.(map[string]interface{}))
}

if v, ok := d.GetOk("advanced_security_options"); ok {
inputCreateDomain.AdvancedSecurityOptions = expandAdvancedSecurityOptions(v.([]interface{}))
input.AdvancedSecurityOptions = expandAdvancedSecurityOptions(v.([]interface{}))
}

if v, ok := d.GetOk("auto_tune_options"); ok && len(v.([]interface{})) > 0 {
inputCreateDomain.AutoTuneOptions = expandAutoTuneOptionsInput(v.([]interface{})[0].(map[string]interface{}))
input.AutoTuneOptions = expandAutoTuneOptionsInput(v.([]interface{})[0].(map[string]interface{}))
}

if v, ok := d.GetOk("ebs_options"); ok {
Expand All @@ -603,7 +648,7 @@ func resourceDomainCreate(ctx context.Context, d *schema.ResourceData, meta inte
}

s := options[0].(map[string]interface{})
inputCreateDomain.EBSOptions = expandEBSOptions(s)
input.EBSOptions = expandEBSOptions(s)
}
}

Expand All @@ -614,7 +659,7 @@ func resourceDomainCreate(ctx context.Context, d *schema.ResourceData, meta inte
}

s := options[0].(map[string]interface{})
inputCreateDomain.EncryptionAtRestOptions = expandEncryptAtRestOptions(s)
input.EncryptionAtRestOptions = expandEncryptAtRestOptions(s)
}

if v, ok := d.GetOk("cluster_config"); ok {
Expand All @@ -625,15 +670,15 @@ func resourceDomainCreate(ctx context.Context, d *schema.ResourceData, meta inte
return sdkdiag.AppendErrorf(diags, "At least one field is expected inside cluster_config")
}
m := config[0].(map[string]interface{})
inputCreateDomain.ClusterConfig = expandClusterConfig(m)
input.ClusterConfig = expandClusterConfig(m)
}
}

if v, ok := d.GetOk("node_to_node_encryption"); ok {
options := v.([]interface{})

s := options[0].(map[string]interface{})
inputCreateDomain.NodeToNodeEncryptionOptions = expandNodeToNodeEncryptionOptions(s)
input.NodeToNodeEncryptionOptions = expandNodeToNodeEncryptionOptions(s)
}

if v, ok := d.GetOk("snapshot_options"); ok {
Expand All @@ -650,7 +695,7 @@ func resourceDomainCreate(ctx context.Context, d *schema.ResourceData, meta inte
AutomatedSnapshotStartHour: aws.Int64(int64(o["automated_snapshot_start_hour"].(int))),
}

inputCreateDomain.SnapshotOptions = &snapshotOptions
input.SnapshotOptions = &snapshotOptions
}
}

Expand All @@ -661,26 +706,36 @@ func resourceDomainCreate(ctx context.Context, d *schema.ResourceData, meta inte
}

s := options[0].(map[string]interface{})
inputCreateDomain.VPCOptions = expandVPCOptions(s)
input.VPCOptions = expandVPCOptions(s)
}

if v, ok := d.GetOk("log_publishing_options"); ok {
inputCreateDomain.LogPublishingOptions = expandLogPublishingOptions(v.(*schema.Set))
input.LogPublishingOptions = expandLogPublishingOptions(v.(*schema.Set))
}

if v, ok := d.GetOk("domain_endpoint_options"); ok {
inputCreateDomain.DomainEndpointOptions = expandDomainEndpointOptions(v.([]interface{}))
input.DomainEndpointOptions = expandDomainEndpointOptions(v.([]interface{}))
}

if v, ok := d.GetOk("cognito_options"); ok {
inputCreateDomain.CognitoOptions = expandCognitoOptions(v.([]interface{}))
input.CognitoOptions = expandCognitoOptions(v.([]interface{}))
}

if v, ok := d.GetOk("off_peak_window_options"); ok && len(v.([]interface{})) > 0 {
input.OffPeakWindowOptions = expandOffPeakWindowOptions(v.([]interface{})[0].(map[string]interface{}))

// This option is only available when modifying a domain created prior to February 16, 2023, not when creating a new domain.
// An off-peak window is required for a domain and cannot be disabled.
if input.OffPeakWindowOptions != nil {
input.OffPeakWindowOptions.Enabled = aws.Bool(true)
}
}

// 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 {
var err error
out, err = conn.CreateDomainWithContext(ctx, &inputCreateDomain)
out, err = conn.CreateDomainWithContext(ctx, input)
if err != nil {
if tfawserr.ErrMessageContains(err, "InvalidTypeException", "Error setting policy") {
return retry.RetryableError(err)
Expand Down Expand Up @@ -711,7 +766,7 @@ func resourceDomainCreate(ctx context.Context, d *schema.ResourceData, meta inte
return nil
})
if tfresource.TimedOut(err) {
out, err = conn.CreateDomainWithContext(ctx, &inputCreateDomain)
out, err = conn.CreateDomainWithContext(ctx, input)
}
if err != nil {
return sdkdiag.AppendErrorf(diags, "creating OpenSearch Domain: %s", err)
Expand All @@ -729,13 +784,13 @@ func resourceDomainCreate(ctx context.Context, d *schema.ResourceData, meta inte
if v, ok := d.GetOk("auto_tune_options"); ok && len(v.([]interface{})) > 0 {
log.Printf("[DEBUG] Modifying config for OpenSearch Domain %q", d.Id())

inputUpdateDomainConfig := &opensearchservice.UpdateDomainConfigInput{
input := &opensearchservice.UpdateDomainConfigInput{
DomainName: aws.String(d.Get("domain_name").(string)),
}

inputUpdateDomainConfig.AutoTuneOptions = expandAutoTuneOptions(v.([]interface{})[0].(map[string]interface{}))
input.AutoTuneOptions = expandAutoTuneOptions(v.([]interface{})[0].(map[string]interface{}))

_, err = conn.UpdateDomainConfigWithContext(ctx, inputUpdateDomainConfig)
_, err = conn.UpdateDomainConfigWithContext(ctx, input)

if err != nil {
return sdkdiag.AppendErrorf(diags, "modifying config for OpenSearch Domain: %s", err)
Expand Down Expand Up @@ -789,6 +844,7 @@ func resourceDomainRead(ctx context.Context, d *schema.ResourceData, meta interf
}

d.SetId(aws.StringValue(ds.ARN))
d.Set("arn", ds.ARN)
d.Set("domain_id", ds.DomainId)
d.Set("domain_name", ds.DomainName)
d.Set("engine_version", ds.EngineVersion)
Expand Down Expand Up @@ -867,7 +923,13 @@ func resourceDomainRead(ctx context.Context, d *schema.ResourceData, meta interf
return sdkdiag.AppendErrorf(diags, "setting domain_endpoint_options: %s", err)
}

d.Set("arn", ds.ARN)
if ds.OffPeakWindowOptions != nil {
if err := d.Set("off_peak_window_options", []interface{}{flattenOffPeakWindowOptions(ds.OffPeakWindowOptions)}); err != nil {
return sdkdiag.AppendErrorf(diags, "setting off_peak_window_options: %s", err)
}
} else {
d.Set("off_peak_window_options", nil)
}

return diags
}
Expand Down Expand Up @@ -901,6 +963,10 @@ func resourceDomainUpdate(ctx context.Context, d *schema.ResourceData, meta inte
input.AutoTuneOptions = expandAutoTuneOptions(d.Get("auto_tune_options").([]interface{})[0].(map[string]interface{}))
}

if d.HasChange("cognito_options") {
input.CognitoOptions = expandCognitoOptions(d.Get("cognito_options").([]interface{}))
}

if d.HasChange("domain_endpoint_options") {
input.DomainEndpointOptions = expandDomainEndpointOptions(d.Get("domain_endpoint_options").([]interface{}))
}
Expand Down Expand Up @@ -952,6 +1018,10 @@ func resourceDomainUpdate(ctx context.Context, d *schema.ResourceData, meta inte
}
}

if d.HasChange("log_publishing_options") {
input.LogPublishingOptions = expandLogPublishingOptions(d.Get("log_publishing_options").(*schema.Set))
}

if d.HasChange("node_to_node_encryption") {
input.NodeToNodeEncryptionOptions = nil
if v, ok := d.GetOk("node_to_node_encryption"); ok {
Expand All @@ -962,6 +1032,10 @@ func resourceDomainUpdate(ctx context.Context, d *schema.ResourceData, meta inte
}
}

if d.HasChange("off_peak_window_options") {
input.OffPeakWindowOptions = expandOffPeakWindowOptions(d.Get("off_peak_window_options").([]interface{})[0].(map[string]interface{}))
}

if d.HasChange("snapshot_options") {
options := d.Get("snapshot_options").([]interface{})

Expand All @@ -982,15 +1056,6 @@ func resourceDomainUpdate(ctx context.Context, d *schema.ResourceData, meta inte
input.VPCOptions = expandVPCOptions(s)
}

if d.HasChange("cognito_options") {
options := d.Get("cognito_options").([]interface{})
input.CognitoOptions = expandCognitoOptions(options)
}

if d.HasChange("log_publishing_options") {
input.LogPublishingOptions = expandLogPublishingOptions(d.Get("log_publishing_options").(*schema.Set))
}

_, err := conn.UpdateDomainConfigWithContext(ctx, &input)
if err != nil {
return sdkdiag.AppendErrorf(diags, "updating OpenSearch Domain (%s): %s", d.Id(), err)
Expand Down
Loading