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

Added the opensearch with standby functionality #33031

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
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/33031.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
```release-note:enhancement
resource/aws_opensearch_domain: Add `cluster_config.multi_az_with_standby_enabled` argument
```

```release-note:enhancement
data-source/aws_opensearch_domain: Add `cluster_config.multi_az_with_standby_enabled` attribute
```
44 changes: 28 additions & 16 deletions internal/service/opensearch/domain.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ func ResourceDomain() *schema.Resource {
"dedicated_master_count": {
Type: schema.TypeInt,
Optional: true,
DiffSuppressFunc: isDedicatedMasterDisabled,
DiffSuppressFunc: suppressComputedDedicatedMaster,
},
"dedicated_master_enabled": {
Type: schema.TypeBool,
Expand All @@ -259,7 +259,7 @@ func ResourceDomain() *schema.Resource {
"dedicated_master_type": {
Type: schema.TypeString,
Optional: true,
DiffSuppressFunc: isDedicatedMasterDisabled,
DiffSuppressFunc: suppressComputedDedicatedMaster,
},
"instance_count": {
Type: schema.TypeInt,
Expand All @@ -271,6 +271,10 @@ func ResourceDomain() *schema.Resource {
Optional: true,
Default: opensearchservice.OpenSearchPartitionInstanceTypeM3MediumSearch,
},
"multi_az_with_standby_enabled": {
Type: schema.TypeBool,
Optional: true,
},
"warm_count": {
Type: schema.TypeInt,
Optional: true,
Expand Down Expand Up @@ -1145,7 +1149,7 @@ func getKibanaEndpoint(d *schema.ResourceData) string {
return d.Get("endpoint").(string) + "/_plugin/kibana/"
}

func isDedicatedMasterDisabled(k, old, new string, d *schema.ResourceData) bool {
func suppressComputedDedicatedMaster(k, old, new string, d *schema.ResourceData) bool {
v, ok := d.GetOk("cluster_config")
if ok {
clusterConfig := v.([]interface{})[0].(map[string]interface{})
Expand Down Expand Up @@ -1188,6 +1192,10 @@ func flattenNodeToNodeEncryptionOptions(o *opensearchservice.NodeToNodeEncryptio
func expandClusterConfig(m map[string]interface{}) *opensearchservice.ClusterConfig {
config := opensearchservice.ClusterConfig{}

if v, ok := m["cold_storage_options"]; ok {
config.ColdStorageOptions = expandColdStorageOptions(v.([]interface{}))
}

if v, ok := m["dedicated_master_enabled"]; ok {
isEnabled := v.(bool)
config.DedicatedMasterEnabled = aws.Bool(isEnabled)
Expand All @@ -1205,23 +1213,13 @@ func expandClusterConfig(m map[string]interface{}) *opensearchservice.ClusterCon
if v, ok := m["instance_count"]; ok {
config.InstanceCount = aws.Int64(int64(v.(int)))
}

if v, ok := m["instance_type"]; ok {
config.InstanceType = aws.String(v.(string))
}

if v, ok := m["zone_awareness_enabled"]; ok {
isEnabled := v.(bool)
config.ZoneAwarenessEnabled = aws.Bool(isEnabled)

if isEnabled {
if v, ok := m["zone_awareness_config"]; ok {
config.ZoneAwarenessConfig = expandZoneAwarenessConfig(v.([]interface{}))
}
}
}

if v, ok := m["cold_storage_options"]; ok {
config.ColdStorageOptions = expandColdStorageOptions(v.([]interface{}))
if v, ok := m["multi_az_with_standby_enabled"]; ok {
config.MultiAZWithStandbyEnabled = aws.Bool(v.(bool))
}

if v, ok := m["warm_enabled"]; ok {
Expand All @@ -1239,6 +1237,17 @@ func expandClusterConfig(m map[string]interface{}) *opensearchservice.ClusterCon
}
}

if v, ok := m["zone_awareness_enabled"]; ok {
isEnabled := v.(bool)
config.ZoneAwarenessEnabled = aws.Bool(isEnabled)

if isEnabled {
if v, ok := m["zone_awareness_config"]; ok {
config.ZoneAwarenessConfig = expandZoneAwarenessConfig(v.([]interface{}))
}
}
}

return &config
}

Expand Down Expand Up @@ -1298,6 +1307,9 @@ func flattenClusterConfig(c *opensearchservice.ClusterConfig) []map[string]inter
if c.InstanceType != nil {
m["instance_type"] = aws.StringValue(c.InstanceType)
}
if c.MultiAZWithStandbyEnabled != nil {
m["multi_az_with_standby_enabled"] = aws.BoolValue(c.MultiAZWithStandbyEnabled)
}
if c.WarmEnabled != nil {
m["warm_enabled"] = aws.BoolValue(c.WarmEnabled)
}
Expand Down
4 changes: 4 additions & 0 deletions internal/service/opensearch/domain_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,10 @@ func DataSourceDomain() *schema.Resource {
Type: schema.TypeString,
Computed: true,
},
"multi_az_with_standby_enabled": {
Type: schema.TypeBool,
Computed: true,
},
"warm_count": {
Type: schema.TypeInt,
Computed: true,
Expand Down
75 changes: 75 additions & 0 deletions internal/service/opensearch/domain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,42 @@ func TestAccOpenSearchDomain_Cluster_update(t *testing.T) {
}})
}

func TestAccOpenSearchDomain_Cluster_multiAzWithStandbyEnabled(t *testing.T) {
ctx := acctest.Context(t)
var domain opensearchservice.DomainStatus
rName := testAccRandomDomainName()
resourceName := "aws_opensearch_domain.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(ctx, t) },
ErrorCheck: acctest.ErrorCheck(t, opensearchservice.EndpointsID),
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
CheckDestroy: testAccCheckDomainDestroy(ctx),
Steps: []resource.TestStep{
{
Config: testAccDomainConfig_multiAzWithStandbyEnabled(rName, true),
Check: resource.ComposeTestCheckFunc(
testAccCheckDomainExists(ctx, resourceName, &domain),
resource.TestCheckResourceAttr(resourceName, "cluster_config.0.multi_az_with_standby_enabled", "true"),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateId: rName,
ImportStateVerify: true,
},
{
Config: testAccDomainConfig_multiAzWithStandbyEnabled(rName, false),
Check: resource.ComposeTestCheckFunc(
testAccCheckDomainExists(ctx, resourceName, &domain),
resource.TestCheckResourceAttr(resourceName, "cluster_config.0.multi_az_with_standby_enabled", "false"),
),
},
},
})
}

func TestAccOpenSearchDomain_duplicate(t *testing.T) {
ctx := acctest.Context(t)
if testing.Short() {
Expand Down Expand Up @@ -2358,6 +2394,45 @@ resource "aws_opensearch_domain" "test" {
`, rName, enabled)
}

func testAccDomainConfig_multiAzWithStandbyEnabled(rName string, enableStandby bool) string {
return fmt.Sprintf(`
resource "aws_opensearch_domain" "test" {
domain_name = %[1]q
engine_version = "OpenSearch_2.7"

domain_endpoint_options {
enforce_https = true
tls_security_policy = "Policy-Min-TLS-1-0-2019-07"
}

ebs_options {
ebs_enabled = true
volume_size = 20
}

auto_tune_options {
desired_state = "ENABLED"
rollback_on_disable = "NO_ROLLBACK"
}

cluster_config {
zone_awareness_enabled = true
instance_count = 3
instance_type = "m6g.large.search"
dedicated_master_enabled = true
dedicated_master_count = 3
dedicated_master_type = "m6g.large.search"

zone_awareness_config {
availability_zone_count = 3
}

multi_az_with_standby_enabled = %[2]t
}
}
`, rName, enableStandby)
}

func testAccDomainConfig_clusterUpdate(rName string, instanceInt, snapshotInt int) string {
return fmt.Sprintf(`
resource "aws_opensearch_domain" "test" {
Expand Down
Loading