2015-10-02 00:13:12 +02:00
|
|
|
package aws
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/aws/aws-sdk-go/aws"
|
2015-12-22 16:02:19 +01:00
|
|
|
"github.com/aws/aws-sdk-go/aws/awserr"
|
2015-10-02 00:13:12 +02:00
|
|
|
elasticsearch "github.com/aws/aws-sdk-go/service/elasticsearchservice"
|
2016-08-05 09:59:15 +02:00
|
|
|
"github.com/hashicorp/terraform/helper/acctest"
|
2015-10-02 00:13:12 +02:00
|
|
|
"github.com/hashicorp/terraform/helper/resource"
|
|
|
|
"github.com/hashicorp/terraform/terraform"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestAccAWSElasticSearchDomain_basic(t *testing.T) {
|
|
|
|
var domain elasticsearch.ElasticsearchDomainStatus
|
2016-08-05 09:59:15 +02:00
|
|
|
ri := acctest.RandInt()
|
2015-10-02 00:13:12 +02:00
|
|
|
|
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Providers: testAccProviders,
|
|
|
|
CheckDestroy: testAccCheckESDomainDestroy,
|
|
|
|
Steps: []resource.TestStep{
|
|
|
|
resource.TestStep{
|
2016-08-05 09:59:15 +02:00
|
|
|
Config: testAccESDomainConfig(ri),
|
2015-10-02 00:13:12 +02:00
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
testAccCheckESDomainExists("aws_elasticsearch_domain.example", &domain),
|
2016-08-05 09:59:15 +02:00
|
|
|
resource.TestCheckResourceAttr(
|
|
|
|
"aws_elasticsearch_domain.example", "elasticsearch_version", "1.5"),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestAccAWSElasticSearchDomain_v23(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{
|
|
|
|
resource.TestStep{
|
|
|
|
Config: testAccESDomainConfigV23(ri),
|
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
testAccCheckESDomainExists("aws_elasticsearch_domain.example", &domain),
|
|
|
|
resource.TestCheckResourceAttr(
|
|
|
|
"aws_elasticsearch_domain.example", "elasticsearch_version", "2.3"),
|
2015-10-02 00:13:12 +02:00
|
|
|
),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestAccAWSElasticSearchDomain_complex(t *testing.T) {
|
|
|
|
var domain elasticsearch.ElasticsearchDomainStatus
|
2016-08-05 09:59:15 +02:00
|
|
|
ri := acctest.RandInt()
|
2015-10-02 00:13:12 +02:00
|
|
|
|
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Providers: testAccProviders,
|
|
|
|
CheckDestroy: testAccCheckESDomainDestroy,
|
|
|
|
Steps: []resource.TestStep{
|
|
|
|
resource.TestStep{
|
2016-08-05 09:59:15 +02:00
|
|
|
Config: testAccESDomainConfig_complex(ri),
|
2015-10-02 00:13:12 +02:00
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
testAccCheckESDomainExists("aws_elasticsearch_domain.example", &domain),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2016-02-02 14:54:11 +01:00
|
|
|
func TestAccAWSElasticSearch_tags(t *testing.T) {
|
|
|
|
var domain elasticsearch.ElasticsearchDomainStatus
|
|
|
|
var td elasticsearch.ListTagsOutput
|
2016-08-05 09:59:15 +02:00
|
|
|
ri := acctest.RandInt()
|
2016-02-02 14:54:11 +01:00
|
|
|
|
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Providers: testAccProviders,
|
|
|
|
CheckDestroy: testAccCheckAWSELBDestroy,
|
|
|
|
Steps: []resource.TestStep{
|
|
|
|
resource.TestStep{
|
2016-08-05 09:59:15 +02:00
|
|
|
Config: testAccESDomainConfig(ri),
|
2016-02-02 14:54:11 +01:00
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
testAccCheckESDomainExists("aws_elasticsearch_domain.example", &domain),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
|
|
|
|
resource.TestStep{
|
2016-08-05 09:59:15 +02:00
|
|
|
Config: testAccESDomainConfig_TagUpdate(ri),
|
2016-02-02 14:54:11 +01:00
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
testAccCheckESDomainExists("aws_elasticsearch_domain.example", &domain),
|
|
|
|
testAccLoadESTags(&domain, &td),
|
|
|
|
testAccCheckElasticsearchServiceTags(&td.TagList, "foo", "bar"),
|
|
|
|
testAccCheckElasticsearchServiceTags(&td.TagList, "new", "type"),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func testAccLoadESTags(conf *elasticsearch.ElasticsearchDomainStatus, td *elasticsearch.ListTagsOutput) resource.TestCheckFunc {
|
|
|
|
return func(s *terraform.State) error {
|
|
|
|
conn := testAccProvider.Meta().(*AWSClient).esconn
|
|
|
|
|
|
|
|
describe, err := conn.ListTags(&elasticsearch.ListTagsInput{
|
|
|
|
ARN: conf.ARN,
|
|
|
|
})
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if len(describe.TagList) > 0 {
|
|
|
|
*td = *describe
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-02 00:13:12 +02:00
|
|
|
func testAccCheckESDomainExists(n string, domain *elasticsearch.ElasticsearchDomainStatus) resource.TestCheckFunc {
|
|
|
|
return func(s *terraform.State) error {
|
|
|
|
rs, ok := s.RootModule().Resources[n]
|
|
|
|
if !ok {
|
|
|
|
return fmt.Errorf("Not found: %s", n)
|
|
|
|
}
|
|
|
|
|
|
|
|
if rs.Primary.ID == "" {
|
|
|
|
return fmt.Errorf("No ES Domain ID is set")
|
|
|
|
}
|
|
|
|
|
|
|
|
conn := testAccProvider.Meta().(*AWSClient).esconn
|
|
|
|
opts := &elasticsearch.DescribeElasticsearchDomainInput{
|
|
|
|
DomainName: aws.String(rs.Primary.Attributes["domain_name"]),
|
|
|
|
}
|
|
|
|
|
|
|
|
resp, err := conn.DescribeElasticsearchDomain(opts)
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("Error describing domain: %s", err.Error())
|
|
|
|
}
|
|
|
|
|
|
|
|
*domain = *resp.DomainStatus
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func testAccCheckESDomainDestroy(s *terraform.State) error {
|
|
|
|
for _, rs := range s.RootModule().Resources {
|
|
|
|
if rs.Type != "aws_elasticsearch_domain" {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
conn := testAccProvider.Meta().(*AWSClient).esconn
|
|
|
|
opts := &elasticsearch.DescribeElasticsearchDomainInput{
|
|
|
|
DomainName: aws.String(rs.Primary.Attributes["domain_name"]),
|
|
|
|
}
|
|
|
|
|
|
|
|
_, err := conn.DescribeElasticsearchDomain(opts)
|
2015-12-22 16:02:19 +01:00
|
|
|
// Verify the error is what we want
|
2015-10-02 00:13:12 +02:00
|
|
|
if err != nil {
|
2015-12-22 16:02:19 +01:00
|
|
|
if awsErr, ok := err.(awserr.Error); ok && awsErr.Code() == "ResourceNotFoundException" {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
return err
|
2015-10-02 00:13:12 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2016-08-05 09:59:15 +02:00
|
|
|
func testAccESDomainConfig(randInt int) string {
|
|
|
|
return fmt.Sprintf(`
|
2015-10-02 00:13:12 +02:00
|
|
|
resource "aws_elasticsearch_domain" "example" {
|
2016-08-05 09:59:15 +02:00
|
|
|
domain_name = "tf-test-%d"
|
|
|
|
}
|
|
|
|
`, randInt)
|
2016-02-02 14:54:11 +01:00
|
|
|
}
|
|
|
|
|
2016-08-05 09:59:15 +02:00
|
|
|
func testAccESDomainConfig_TagUpdate(randInt int) string {
|
|
|
|
return fmt.Sprintf(`
|
2016-02-02 14:54:11 +01:00
|
|
|
resource "aws_elasticsearch_domain" "example" {
|
2016-08-05 09:59:15 +02:00
|
|
|
domain_name = "tf-test-%d"
|
2016-02-02 14:54:11 +01:00
|
|
|
|
|
|
|
tags {
|
|
|
|
foo = "bar"
|
|
|
|
new = "type"
|
|
|
|
}
|
2015-10-02 00:13:12 +02:00
|
|
|
}
|
2016-08-05 09:59:15 +02:00
|
|
|
`, randInt)
|
|
|
|
}
|
2015-10-02 00:13:12 +02:00
|
|
|
|
2016-08-05 09:59:15 +02:00
|
|
|
func testAccESDomainConfig_complex(randInt int) string {
|
|
|
|
return fmt.Sprintf(`
|
2015-10-02 00:13:12 +02:00
|
|
|
resource "aws_elasticsearch_domain" "example" {
|
2016-08-05 09:59:15 +02:00
|
|
|
domain_name = "tf-test-%d"
|
2015-10-02 00:13:12 +02:00
|
|
|
|
2016-02-02 14:54:11 +01:00
|
|
|
advanced_options {
|
|
|
|
"indices.fielddata.cache.size" = 80
|
|
|
|
}
|
2015-10-02 00:13:12 +02:00
|
|
|
|
2016-02-02 14:54:11 +01:00
|
|
|
ebs_options {
|
|
|
|
ebs_enabled = false
|
|
|
|
}
|
2015-10-02 00:13:12 +02:00
|
|
|
|
2016-02-02 14:54:11 +01:00
|
|
|
cluster_config {
|
|
|
|
instance_count = 2
|
|
|
|
zone_awareness_enabled = true
|
|
|
|
}
|
2015-10-02 00:13:12 +02:00
|
|
|
|
2016-02-02 14:54:11 +01:00
|
|
|
snapshot_options {
|
|
|
|
automated_snapshot_start_hour = 23
|
|
|
|
}
|
|
|
|
|
|
|
|
tags {
|
|
|
|
bar = "complex"
|
|
|
|
}
|
2015-10-02 00:13:12 +02:00
|
|
|
}
|
2016-08-05 09:59:15 +02:00
|
|
|
`, randInt)
|
|
|
|
}
|
|
|
|
|
|
|
|
func testAccESDomainConfigV23(randInt int) string {
|
|
|
|
return fmt.Sprintf(`
|
|
|
|
resource "aws_elasticsearch_domain" "example" {
|
|
|
|
domain_name = "tf-test-%d"
|
|
|
|
elasticsearch_version = "2.3"
|
|
|
|
}
|
|
|
|
`, randInt)
|
|
|
|
}
|