Skip to content

Commit

Permalink
Merge pull request #13937 from terraform-providers/b-elasticsearch-do…
Browse files Browse the repository at this point in the history
…main-validation

resource/elasticsearch_domain: allow empty string for EBS volume type validation
  • Loading branch information
anGie44 authored Jun 25, 2020
2 parents 29d7bff + 57ac9be commit b7463c5
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 5 deletions.
13 changes: 8 additions & 5 deletions aws/resource_aws_elasticsearch_domain.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,11 +141,14 @@ func resourceAwsElasticSearchDomain() *schema.Resource {
Type: schema.TypeString,
Optional: true,
Computed: true,
ValidateFunc: validation.StringInSlice([]string{
elasticsearch.VolumeTypeStandard,
elasticsearch.VolumeTypeGp2,
elasticsearch.VolumeTypeIo1,
}, false),
ValidateFunc: validation.Any(
validation.StringIsEmpty,
validation.StringInSlice([]string{
elasticsearch.VolumeTypeStandard,
elasticsearch.VolumeTypeGp2,
elasticsearch.VolumeTypeIo1,
}, false),
),
},
},
},
Expand Down
54 changes: 54 additions & 0 deletions aws/resource_aws_elasticsearch_domain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -797,6 +797,40 @@ func TestAccAWSElasticSearchDomain_update_volume_type(t *testing.T) {
}})
}

// Reference: https://github.com/terraform-providers/terraform-provider-aws/issues/13867
func TestAccAWSElasticSearchDomain_WithVolumeType_Missing(t *testing.T) {
var domain elasticsearch.ElasticsearchDomainStatus
resourceName := "aws_elasticsearch_domain.test"
rName := fmt.Sprintf("tf-acc-test-%s", acctest.RandStringFromCharSet(16, acctest.CharSetAlphaNum))

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t); testAccPreCheckIamServiceLinkedRoleEs(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckESDomainDestroy,
Steps: []resource.TestStep{
{
Config: testAccESDomainConfigWithDisabledEBSAndVolumeType(rName, ""),
Check: resource.ComposeTestCheckFunc(
testAccCheckESDomainExists(resourceName, &domain),
resource.TestCheckResourceAttr(resourceName, "cluster_config.#", "1"),
resource.TestCheckResourceAttr(resourceName, "cluster_config.0.instance_type", "i3.xlarge.elasticsearch"),
resource.TestCheckResourceAttr(resourceName, "cluster_config.0.instance_count", "1"),
resource.TestCheckResourceAttr(resourceName, "ebs_options.#", "1"),
resource.TestCheckResourceAttr(resourceName, "ebs_options.0.ebs_enabled", "false"),
resource.TestCheckResourceAttr(resourceName, "ebs_options.0.volume_size", "0"),
resource.TestCheckResourceAttr(resourceName, "ebs_options.0.volume_type", ""),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateId: rName,
ImportStateVerify: true,
},
},
})
}

func TestAccAWSElasticSearchDomain_update_version(t *testing.T) {
var domain1, domain2, domain3 elasticsearch.ElasticsearchDomainStatus
ri := acctest.RandInt()
Expand Down Expand Up @@ -1052,6 +1086,26 @@ resource "aws_elasticsearch_domain" "test" {
`, randInt)
}

func testAccESDomainConfigWithDisabledEBSAndVolumeType(rName, volumeType string) string {
return fmt.Sprintf(`
resource "aws_elasticsearch_domain" "test" {
domain_name = "%s"
elasticsearch_version = "6.0"
cluster_config {
instance_type = "i3.xlarge.elasticsearch"
instance_count = 1
}
ebs_options {
ebs_enabled = false
volume_size = 0
volume_type = "%s"
}
}
`, rName, volumeType)
}

func testAccESDomainConfig_DomainEndpointOptions(randInt int, enforceHttps bool, tlsSecurityPolicy string) string {
return fmt.Sprintf(`
resource "aws_elasticsearch_domain" "example" {
Expand Down

0 comments on commit b7463c5

Please sign in to comment.