Skip to content

Commit

Permalink
Check that ES Domain isn't recreated when upgrading the version on a …
Browse files Browse the repository at this point in the history
…supported upgrade path

Not currently checking that unsupported upgrade paths leads to them being recreated.

Unfortunately we can't just switch all of the tests and helpers over to using the ElasticSearchDomainConfig because the testAccLoadESTags helper needs the ARN which isn't available or easily retrievable when using the ElasticSearchDomainConfig struct.
  • Loading branch information
tomelliff committed Dec 30, 2018
1 parent 4706736 commit 7529e0b
Showing 1 changed file with 31 additions and 3 deletions.
34 changes: 31 additions & 3 deletions aws/resource_aws_elasticsearch_domain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,7 @@ func TestAccAWSElasticSearchDomain_update_volume_type(t *testing.T) {
}

func TestAccAWSElasticSearchDomain_update_version(t *testing.T) {
var input elasticsearch.ElasticsearchDomainStatus
var domain1, domain2, domain3 elasticsearch.ElasticsearchDomainStatus
ri := acctest.RandInt()

resource.Test(t, resource.TestCase{
Expand All @@ -568,20 +568,23 @@ func TestAccAWSElasticSearchDomain_update_version(t *testing.T) {
{
Config: testAccESDomainConfig_ClusterUpdateVersion(ri, "5.5"),
Check: resource.ComposeTestCheckFunc(
testAccCheckESDomainExists("aws_elasticsearch_domain.example", &input),
testAccCheckESDomainExists("aws_elasticsearch_domain.example", &domain1),
resource.TestCheckResourceAttr("aws_elasticsearch_domain.example", "elasticsearch_version", "5.5"),
),
},
{
Config: testAccESDomainConfig_ClusterUpdateVersion(ri, "5.6"),
Check: resource.ComposeTestCheckFunc(
testAccCheckESDomainExists("aws_elasticsearch_domain.example", &domain2),
testAccCheckAWSESDomainNotRecreated(&domain1, &domain2),
resource.TestCheckResourceAttr("aws_elasticsearch_domain.example", "elasticsearch_version", "5.6"),
),
},
{
Config: testAccESDomainConfig_ClusterUpdateVersion(ri, "6.3"),
Check: resource.ComposeTestCheckFunc(
testAccCheckESDomainExists("aws_elasticsearch_domain.example", &input),
testAccCheckESDomainExists("aws_elasticsearch_domain.example", &domain3),
testAccCheckAWSESDomainNotRecreated(&domain2, &domain3),
resource.TestCheckResourceAttr("aws_elasticsearch_domain.example", "elasticsearch_version", "6.3"),
),
},
Expand Down Expand Up @@ -702,6 +705,31 @@ func testAccCheckESDomainExists(n string, domain *elasticsearch.ElasticsearchDom
}
}

func testAccCheckAWSESDomainNotRecreated(i, j *elasticsearch.ElasticsearchDomainStatus) resource.TestCheckFunc {
return func(s *terraform.State) error {
conn := testAccProvider.Meta().(*AWSClient).esconn

iConfig, err := conn.DescribeElasticsearchDomainConfig(&elasticsearch.DescribeElasticsearchDomainConfigInput{
DomainName: i.DomainName,
})
if err != nil {
return err
}
jConfig, err := conn.DescribeElasticsearchDomainConfig(&elasticsearch.DescribeElasticsearchDomainConfigInput{
DomainName: j.DomainName,
})
if err != nil {
return err
}

if aws.TimeValue(iConfig.DomainConfig.ElasticsearchClusterConfig.Status.CreationDate) != aws.TimeValue(jConfig.DomainConfig.ElasticsearchClusterConfig.Status.CreationDate) {
return fmt.Errorf("ES Domain was recreated")
}

return nil
}
}

func testAccCheckESDomainDestroy(s *terraform.State) error {
for _, rs := range s.RootModule().Resources {
if rs.Type != "aws_elasticsearch_domain" {
Expand Down

0 comments on commit 7529e0b

Please sign in to comment.