mirror of
https://github.com/opentofu/opentofu.git
synced 2025-01-24 23:46:26 -06:00
744b266995
`elasticsearch_version` 2.3 Fixes #7836 This will allow ElasticSearch domains to be deployed with version 2.3 of ElasticSearch The other slight modifications are to stop dereferencing values before passing to d.Set in the Read func. It is safer to pass the pointer to d.Set and allow that to dereference if there is a value ``` % make testacc TEST=./builtin/providers/aws TESTARGS='-run=TestAccAWSElasticSearchDomain_' ==> Checking that code complies with gofmt requirements... go generate $(go list ./... | grep -v /terraform/vendor/) TF_ACC=1 go test ./builtin/providers/aws -v -run=TestAccAWSElasticSearchDomain_ -timeout 120m === RUN TestAccAWSElasticSearchDomain_basic --- PASS: TestAccAWSElasticSearchDomain_basic (1611.74s) === RUN TestAccAWSElasticSearchDomain_v23 --- PASS: TestAccAWSElasticSearchDomain_v23 (1898.80s) === RUN TestAccAWSElasticSearchDomain_complex --- PASS: TestAccAWSElasticSearchDomain_complex (1802.44s) PASS ok github.com/hashicorp/terraform/builtin/providers/aws 5313.006s ``` Update resource_aws_elasticsearch_domain.go
232 lines
5.8 KiB
Go
232 lines
5.8 KiB
Go
package aws
|
|
|
|
import (
|
|
"fmt"
|
|
"testing"
|
|
|
|
"github.com/aws/aws-sdk-go/aws"
|
|
"github.com/aws/aws-sdk-go/aws/awserr"
|
|
elasticsearch "github.com/aws/aws-sdk-go/service/elasticsearchservice"
|
|
"github.com/hashicorp/terraform/helper/acctest"
|
|
"github.com/hashicorp/terraform/helper/resource"
|
|
"github.com/hashicorp/terraform/terraform"
|
|
)
|
|
|
|
func TestAccAWSElasticSearchDomain_basic(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: testAccESDomainConfig(ri),
|
|
Check: resource.ComposeTestCheckFunc(
|
|
testAccCheckESDomainExists("aws_elasticsearch_domain.example", &domain),
|
|
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"),
|
|
),
|
|
},
|
|
},
|
|
})
|
|
}
|
|
|
|
func TestAccAWSElasticSearchDomain_complex(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: testAccESDomainConfig_complex(ri),
|
|
Check: resource.ComposeTestCheckFunc(
|
|
testAccCheckESDomainExists("aws_elasticsearch_domain.example", &domain),
|
|
),
|
|
},
|
|
},
|
|
})
|
|
}
|
|
|
|
func TestAccAWSElasticSearch_tags(t *testing.T) {
|
|
var domain elasticsearch.ElasticsearchDomainStatus
|
|
var td elasticsearch.ListTagsOutput
|
|
ri := acctest.RandInt()
|
|
|
|
resource.Test(t, resource.TestCase{
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
Providers: testAccProviders,
|
|
CheckDestroy: testAccCheckAWSELBDestroy,
|
|
Steps: []resource.TestStep{
|
|
resource.TestStep{
|
|
Config: testAccESDomainConfig(ri),
|
|
Check: resource.ComposeTestCheckFunc(
|
|
testAccCheckESDomainExists("aws_elasticsearch_domain.example", &domain),
|
|
),
|
|
},
|
|
|
|
resource.TestStep{
|
|
Config: testAccESDomainConfig_TagUpdate(ri),
|
|
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
|
|
}
|
|
}
|
|
|
|
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)
|
|
// Verify the error is what we want
|
|
if err != nil {
|
|
if awsErr, ok := err.(awserr.Error); ok && awsErr.Code() == "ResourceNotFoundException" {
|
|
continue
|
|
}
|
|
return err
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func testAccESDomainConfig(randInt int) string {
|
|
return fmt.Sprintf(`
|
|
resource "aws_elasticsearch_domain" "example" {
|
|
domain_name = "tf-test-%d"
|
|
}
|
|
`, randInt)
|
|
}
|
|
|
|
func testAccESDomainConfig_TagUpdate(randInt int) string {
|
|
return fmt.Sprintf(`
|
|
resource "aws_elasticsearch_domain" "example" {
|
|
domain_name = "tf-test-%d"
|
|
|
|
tags {
|
|
foo = "bar"
|
|
new = "type"
|
|
}
|
|
}
|
|
`, randInt)
|
|
}
|
|
|
|
func testAccESDomainConfig_complex(randInt int) string {
|
|
return fmt.Sprintf(`
|
|
resource "aws_elasticsearch_domain" "example" {
|
|
domain_name = "tf-test-%d"
|
|
|
|
advanced_options {
|
|
"indices.fielddata.cache.size" = 80
|
|
}
|
|
|
|
ebs_options {
|
|
ebs_enabled = false
|
|
}
|
|
|
|
cluster_config {
|
|
instance_count = 2
|
|
zone_awareness_enabled = true
|
|
}
|
|
|
|
snapshot_options {
|
|
automated_snapshot_start_hour = 23
|
|
}
|
|
|
|
tags {
|
|
bar = "complex"
|
|
}
|
|
}
|
|
`, randInt)
|
|
}
|
|
|
|
func testAccESDomainConfigV23(randInt int) string {
|
|
return fmt.Sprintf(`
|
|
resource "aws_elasticsearch_domain" "example" {
|
|
domain_name = "tf-test-%d"
|
|
elasticsearch_version = "2.3"
|
|
}
|
|
`, randInt)
|
|
}
|