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 node options support for dedicated coordinator nodes. #40181

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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/40181.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
resource/aws_opensearch_domain: Add support for dedicated coordinator nodes
```
113 changes: 113 additions & 0 deletions internal/service/opensearch/domain.go
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,40 @@ func resourceDomain() *schema.Resource {
Type: schema.TypeBool,
Optional: true,
},
"node_options": {
Type: schema.TypeList,
Optional: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"node_type": {
Type: schema.TypeString,
Required: true,
},
"node_config": {
Type: schema.TypeList,
Required: true,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"count": {
Type: schema.TypeInt,
Optional: true,
ValidateFunc: validation.IntAtLeast(1),
},
"enabled": {
Type: schema.TypeBool,
Required: true,
},
"type": {
Type: schema.TypeString,
Optional: true,
},
},
},
},
},
},
},
"warm_count": {
Type: schema.TypeInt,
Optional: true,
Expand Down Expand Up @@ -1302,6 +1336,10 @@ func expandClusterConfig(m map[string]interface{}) *awstypes.ClusterConfig {
config.MultiAZWithStandbyEnabled = aws.Bool(v.(bool))
}

if v, ok := m["node_options"]; ok {
config.NodeOptions = expandNodeOptions(v.([]interface{}))
}

if v, ok := m["warm_enabled"]; ok {
isEnabled := v.(bool)
config.WarmEnabled = aws.Bool(isEnabled)
Expand Down Expand Up @@ -1363,6 +1401,43 @@ func expandColdStorageOptions(l []interface{}) *awstypes.ColdStorageOptions {
return ColdStorageOptions
}

func expandNodeOptions(l []interface{}) []awstypes.NodeOption {
if len(l) == 0 {
return nil
}

NodeOptions := make([]awstypes.NodeOption, 0)
for _, no := range l {
m := no.(map[string]interface{})
nt := awstypes.NodeOptionsNodeType(m["node_type"].(string))
NodeOptions = append(NodeOptions, awstypes.NodeOption{
NodeType: nt,
NodeConfig: expandNodeConfig(m["node_config"].([]interface{})),
})
}
return NodeOptions
}

func expandNodeConfig(l []interface{}) *awstypes.NodeConfig {
if len(l) == 0 || l[0] == nil {
return nil
}

m := l[0].(map[string]interface{})

NodeConfig := &awstypes.NodeConfig{}

isEnabled := m["enabled"].(bool)
NodeConfig.Enabled = aws.Bool(isEnabled)

if isEnabled {
NodeConfig.Count = aws.Int32(int32(m["count"].(int)))
NodeConfig.Type = awstypes.OpenSearchPartitionInstanceType(m["type"].(string))
}

return NodeConfig
}

func flattenClusterConfig(c *awstypes.ClusterConfig) []map[string]interface{} {
m := map[string]interface{}{
"zone_awareness_config": flattenZoneAwarenessConfig(c.ZoneAwarenessConfig),
Expand Down Expand Up @@ -1390,6 +1465,11 @@ func flattenClusterConfig(c *awstypes.ClusterConfig) []map[string]interface{} {
if c.MultiAZWithStandbyEnabled != nil {
m["multi_az_with_standby_enabled"] = aws.ToBool(c.MultiAZWithStandbyEnabled)
}

if len(c.NodeOptions) > 0 {
m["node_options"] = flattenNodeOptions(c.NodeOptions)
}

if c.WarmEnabled != nil {
m["warm_enabled"] = aws.ToBool(c.WarmEnabled)
}
Expand Down Expand Up @@ -1426,6 +1506,39 @@ func flattenColdStorageOptions(coldStorageOptions *awstypes.ColdStorageOptions)
return []interface{}{m}
}

func flattenNodeOptions(nodeOptions []awstypes.NodeOption) []interface{} {
if len(nodeOptions) == 0 {
return []interface{}{}
}

var l []interface{}

for _, n := range nodeOptions {
m := map[string]interface{}{}
m["node_config"] = flattenNodeConfig(n.NodeConfig)
m["node_type"] = string(n.NodeType)
l = append(l, m)
}

return l
}

func flattenNodeConfig(nodeConfig *awstypes.NodeConfig) []interface{} {
m := map[string]interface{}{
"enabled": aws.ToBool(nodeConfig.Enabled),
}

if nodeConfig.Count != nil {
m["count"] = aws.ToInt32(nodeConfig.Count)
}

if nodeConfig.Type != "" {
m["type"] = nodeConfig.Type
}

return []interface{}{m}
}

// advancedOptionsIgnoreDefault checks for defaults in the n map and, if
// they don't exist in the o map, it deletes them. AWS returns default advanced
// options that cause perpetual diffs.
Expand Down
85 changes: 85 additions & 0 deletions internal/service/opensearch/domain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,46 @@ func TestAccOpenSearchDomain_Cluster_dedicatedMaster(t *testing.T) {
})
}

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

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(ctx, t); testAccPreCheckIAMServiceLinkedRole(ctx, t) },
ErrorCheck: acctest.ErrorCheck(t, names.OpenSearchServiceID),
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
CheckDestroy: testAccCheckDomainDestroy(ctx),
Steps: []resource.TestStep{
{
Config: testAccDomainConfig_dedicatedCoordinator(rName, false),
Check: resource.ComposeTestCheckFunc(
testAccCheckDomainExists(ctx, resourceName, &domain),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateId: rName,
ImportStateVerify: true,
},
{
Config: testAccDomainConfig_dedicatedCoordinator(rName, true),
Check: resource.ComposeTestCheckFunc(
testAccCheckDomainExists(ctx, resourceName, &domain),
),
},
{
Config: testAccDomainConfig_dedicatedCoordinator(rName, false),
Check: resource.ComposeTestCheckFunc(
testAccCheckDomainExists(ctx, resourceName, &domain),
),
},
},
})
}

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

func testAccDomainConfig_dedicatedCoordinator(rName string, enabled bool) string {
nodeOptions := `
node_options {
node_type = "coordinator"
node_config {
enabled = false
}
}`

if enabled {
nodeOptions = `
node_options {
node_type = "coordinator"
node_config {
enabled = true
count = 1
type = "m5.large.search"
}
}`

}

return fmt.Sprintf(`
resource "aws_opensearch_domain" "test" {
domain_name = %[1]q

cluster_config {
instance_type = "t2.small.search"
instance_count = "1"
dedicated_master_enabled = true
dedicated_master_count = "3"
dedicated_master_type = "t2.small.search"

%[2]s

}

ebs_options {
ebs_enabled = true
volume_size = 10
}
}
`, rName, nodeOptions)
}

func testAccDomainConfig_multiAzWithStandbyEnabled(rName string, enableStandby bool) string {
return fmt.Sprintf(`
resource "aws_opensearch_domain" "test" {
Expand Down