Skip to content

Commit

Permalink
Merge pull request #5423 from julienduchesne/fix-dedicated-master-fla…
Browse files Browse the repository at this point in the history
…pping

Supress ES domain dedicated master changes if it is disabled
  • Loading branch information
bflad authored Aug 8, 2018
2 parents 820e1e4 + 55d9b11 commit fa46385
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 4 deletions.
19 changes: 15 additions & 4 deletions aws/resource_aws_elasticsearch_domain.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,17 +125,19 @@ func resourceAwsElasticSearchDomain() *schema.Resource {
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"dedicated_master_count": {
Type: schema.TypeInt,
Optional: true,
Type: schema.TypeInt,
Optional: true,
DiffSuppressFunc: isDedicatedMasterDisabled,
},
"dedicated_master_enabled": {
Type: schema.TypeBool,
Optional: true,
Default: false,
},
"dedicated_master_type": {
Type: schema.TypeString,
Optional: true,
Type: schema.TypeString,
Optional: true,
DiffSuppressFunc: isDedicatedMasterDisabled,
},
"instance_count": {
Type: schema.TypeInt,
Expand Down Expand Up @@ -791,3 +793,12 @@ func esCognitoOptionsDiffSuppress(k, old, new string, d *schema.ResourceData) bo
}
return false
}

func isDedicatedMasterDisabled(k, old, new string, d *schema.ResourceData) bool {
v, ok := d.GetOk("cluster_config")
if ok {
clusterConfig := v.([]interface{})[0].(map[string]interface{})
return !clusterConfig["dedicated_master_enabled"].(bool)
}
return false
}
52 changes: 52 additions & 0 deletions aws/resource_aws_elasticsearch_domain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,37 @@ func TestAccAWSElasticSearchDomain_basic(t *testing.T) {
})
}

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

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckESDomainDestroy,
Steps: []resource.TestStep{
{
Config: testAccESDomainConfig_WithDedicatedClusterMaster(ri, false),
Check: resource.ComposeTestCheckFunc(
testAccCheckESDomainExists("aws_elasticsearch_domain.example", &domain),
),
},
{
Config: testAccESDomainConfig_WithDedicatedClusterMaster(ri, true),
Check: resource.ComposeTestCheckFunc(
testAccCheckESDomainExists("aws_elasticsearch_domain.example", &domain),
),
},
{
Config: testAccESDomainConfig_WithDedicatedClusterMaster(ri, false),
Check: resource.ComposeTestCheckFunc(
testAccCheckESDomainExists("aws_elasticsearch_domain.example", &domain),
),
},
},
})
}

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

func testAccESDomainConfig_WithDedicatedClusterMaster(randInt int, enabled bool) string {
return fmt.Sprintf(`
resource "aws_elasticsearch_domain" "example" {
domain_name = "tf-test-%d"
cluster_config {
instance_type = "t2.micro.elasticsearch"
instance_count = "1"
dedicated_master_enabled = %t
dedicated_master_count = "3"
dedicated_master_type = "t2.micro.elasticsearch"
}
ebs_options {
ebs_enabled = true
volume_size = 10
}
}
`, randInt, enabled)
}

func testAccESDomainConfig_ClusterUpdate(randInt, instanceInt, snapshotInt int) string {
return fmt.Sprintf(`
resource "aws_elasticsearch_domain" "example" {
Expand Down

0 comments on commit fa46385

Please sign in to comment.