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

[Elasticsearch] Implement specifying availability zone count ... #8144

Closed
wants to merge 6 commits into from
Closed
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
4 changes: 4 additions & 0 deletions aws/resource_aws_elasticsearch_domain.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,10 @@ func resourceAwsElasticSearchDomain() *schema.Resource {
Type: schema.TypeBool,
Optional: true,
},
"zone_awareness_count": {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two notes:

  • This argument needs documentation added in website/docs/r/elasticsearch_domain.html.markdown
  • Since this argument is not marked ForceNew: true, an additional TestStep should be added to the acceptance test that attempts to update or remove it

Type: schema.TypeInt,
Optional: true,
},
},
},
},
Expand Down
73 changes: 73 additions & 0 deletions aws/resource_aws_elasticsearch_domain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,59 @@ func TestAccAWSElasticSearchDomain_basic(t *testing.T) {
})
}

func TestAccAWSElasticSearchDomain_ZoneAwareness(t *testing.T) {
var domain elasticsearch.ElasticsearchDomainStatus
ri := acctest.RandInt()

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckESDomainDestroy,
Steps: []resource.TestStep{
{
Config: testAccESDomainConfig_ZoneAwareness(ri, 3, false),
Check: resource.ComposeTestCheckFunc(
testAccCheckESDomainExists("aws_elasticsearch_domain.example", &domain),
resource.TestCheckResourceAttr("aws_elasticsearch_domain.example", "cluster_config.0.zone_awareness_enabled", "false"),
resource.TestCheckResourceAttr("aws_elasticsearch_domain.example", "cluster_config.0.zone_awareness_count", "3"),
),
},
{
Config: testAccESDomainConfig_ZoneAwareness(ri, 3, true),
Check: resource.ComposeTestCheckFunc(
testAccCheckESDomainExists("aws_elasticsearch_domain.example", &domain),
resource.TestCheckResourceAttr("aws_elasticsearch_domain.example", "cluster_config.0.zone_awareness_enabled", "true"),
resource.TestCheckResourceAttr("aws_elasticsearch_domain.example", "cluster_config.0.zone_awareness_count", "3"),
),
},
{
Config: testAccESDomainConfig_ZoneAwareness(ri, 3, false),
Check: resource.ComposeTestCheckFunc(
testAccCheckESDomainExists("aws_elasticsearch_domain.example", &domain),
resource.TestCheckResourceAttr("aws_elasticsearch_domain.example", "cluster_config.0.zone_awareness_enabled", "false"),
resource.TestCheckResourceAttr("aws_elasticsearch_domain.example", "cluster_config.0.zone_awareness_count", "3"),
),
},
{
Config: testAccESDomainConfig_ZoneAwareness(ri, 2, true),
Check: resource.ComposeTestCheckFunc(
testAccCheckESDomainExists("aws_elasticsearch_domain.example", &domain),
resource.TestCheckResourceAttr("aws_elasticsearch_domain.example", "cluster_config.0.zone_awareness_enabled", "true"),
resource.TestCheckResourceAttr("aws_elasticsearch_domain.example", "cluster_config.0.zone_awareness_count", "2"),
),
},
{
Config: testAccESDomainConfig_ZoneAwareness(ri, 3, true),
Check: resource.ComposeTestCheckFunc(
testAccCheckESDomainExists("aws_elasticsearch_domain.example", &domain),
resource.TestCheckResourceAttr("aws_elasticsearch_domain.example", "cluster_config.0.zone_awareness_enabled", "true"),
resource.TestCheckResourceAttr("aws_elasticsearch_domain.example", "cluster_config.0.zone_awareness_count", "3"),
),
},
},
})
}

func TestAccAWSElasticSearchDomain_withDedicatedMaster(t *testing.T) {
var domain elasticsearch.ElasticsearchDomainStatus
ri := acctest.RandInt()
Expand Down Expand Up @@ -749,6 +802,26 @@ resource "aws_elasticsearch_domain" "example" {
`, randInt)
}

func testAccESDomainConfig_ZoneAwareness(randInt int, azcount int, enabled bool) string {
return fmt.Sprintf(`
resource "aws_elasticsearch_domain" "example" {
domain_name = "tf-test-%d"

ebs_options {
ebs_enabled = true
volume_size = 10
}

cluster_config {
instance_type = "t2.micro.elasticsearch"
instance_count = "6"
zone_awareness_enabled = %t
zone_awareness_count = "%d"
}
}
`, randInt, enabled, azcount)
}

func testAccESDomainConfig_WithDedicatedClusterMaster(randInt int, enabled bool) string {
return fmt.Sprintf(`
resource "aws_elasticsearch_domain" "example" {
Expand Down
12 changes: 10 additions & 2 deletions aws/structure.go
Original file line number Diff line number Diff line change
Expand Up @@ -1202,7 +1202,13 @@ func expandESClusterConfig(m map[string]interface{}) *elasticsearch.Elasticsearc
}

if v, ok := m["zone_awareness_enabled"]; ok {
config.ZoneAwarenessEnabled = aws.Bool(v.(bool))
isEnabled := v.(bool)
config.ZoneAwarenessEnabled = aws.Bool(isEnabled)
if isEnabled {
if v, ok := m["zone_awareness_count"]; ok {
config.ZoneAwarenessConfig = &elasticsearch.ZoneAwarenessConfig{AvailabilityZoneCount: aws.Int64(int64(v.(int)))}
}
}
}

return &config
Expand All @@ -1229,7 +1235,9 @@ func flattenESClusterConfig(c *elasticsearch.ElasticsearchClusterConfig) []map[s
if c.ZoneAwarenessEnabled != nil {
m["zone_awareness_enabled"] = *c.ZoneAwarenessEnabled
}

if c.ZoneAwarenessConfig != nil && c.ZoneAwarenessConfig.AvailabilityZoneCount != nil {
m["zone_awareness_count"] = *c.ZoneAwarenessConfig.AvailabilityZoneCount
}
return []map[string]interface{}{m}
}

Expand Down