diff --git a/aws/resource_aws_elasticsearch_domain_test.go b/aws/resource_aws_elasticsearch_domain_test.go index 7c76e42bb190..ebb3e06eeda5 100644 --- a/aws/resource_aws_elasticsearch_domain_test.go +++ b/aws/resource_aws_elasticsearch_domain_test.go @@ -14,6 +14,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" + "github.com/terraform-providers/terraform-provider-aws/aws/internal/tfawsresource" ) func init() { @@ -570,7 +571,7 @@ func TestAccAWSElasticSearchDomain_AdvancedSecurityOptions_Disabled(t *testing.T }) } -func TestAccAWSElasticSearchDomain_LogPublishingOptions(t *testing.T) { +func TestAccAWSElasticSearchDomain_LogPublishingOptions_IndexSlowLogs(t *testing.T) { var domain elasticsearch.ElasticsearchDomainStatus ri := acctest.RandInt() resourceId := fmt.Sprintf("tf-test-%d", ri) @@ -582,9 +583,106 @@ func TestAccAWSElasticSearchDomain_LogPublishingOptions(t *testing.T) { CheckDestroy: testAccCheckESDomainDestroy, Steps: []resource.TestStep{ { - Config: testAccESDomainConfig_LogPublishingOptions(ri), + Config: testAccESDomainConfig_LogPublishingOptions(ri, elasticsearch.LogTypeIndexSlowLogs), Check: resource.ComposeTestCheckFunc( testAccCheckESDomainExists(resourceName, &domain), + resource.TestCheckResourceAttr(resourceName, "log_publishing_options.#", "1"), + tfawsresource.TestCheckTypeSetElemNestedAttrs(resourceName, "log_publishing_options.*", map[string]string{ + "log_type": elasticsearch.LogTypeIndexSlowLogs, + }), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateId: resourceId, + ImportStateVerify: true, + }, + }, + }) +} + +func TestAccAWSElasticSearchDomain_LogPublishingOptions_SearchSlowLogs(t *testing.T) { + var domain elasticsearch.ElasticsearchDomainStatus + ri := acctest.RandInt() + resourceId := fmt.Sprintf("tf-test-%d", ri) + resourceName := "aws_elasticsearch_domain.test" + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t); testAccPreCheckIamServiceLinkedRoleEs(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckESDomainDestroy, + Steps: []resource.TestStep{ + { + Config: testAccESDomainConfig_LogPublishingOptions(ri, elasticsearch.LogTypeSearchSlowLogs), + Check: resource.ComposeTestCheckFunc( + testAccCheckESDomainExists(resourceName, &domain), + resource.TestCheckResourceAttr(resourceName, "log_publishing_options.#", "1"), + tfawsresource.TestCheckTypeSetElemNestedAttrs(resourceName, "log_publishing_options.*", map[string]string{ + "log_type": elasticsearch.LogTypeSearchSlowLogs, + }), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateId: resourceId, + ImportStateVerify: true, + }, + }, + }) +} + +func TestAccAWSElasticSearchDomain_LogPublishingOptions_EsApplicationLogs(t *testing.T) { + var domain elasticsearch.ElasticsearchDomainStatus + ri := acctest.RandInt() + resourceId := fmt.Sprintf("tf-test-%d", ri) + resourceName := "aws_elasticsearch_domain.test" + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t); testAccPreCheckIamServiceLinkedRoleEs(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckESDomainDestroy, + Steps: []resource.TestStep{ + { + Config: testAccESDomainConfig_LogPublishingOptions(ri, elasticsearch.LogTypeEsApplicationLogs), + Check: resource.ComposeTestCheckFunc( + testAccCheckESDomainExists(resourceName, &domain), + resource.TestCheckResourceAttr(resourceName, "log_publishing_options.#", "1"), + tfawsresource.TestCheckTypeSetElemNestedAttrs(resourceName, "log_publishing_options.*", map[string]string{ + "log_type": elasticsearch.LogTypeEsApplicationLogs, + }), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateId: resourceId, + ImportStateVerify: true, + }, + }, + }) +} + +func TestAccAWSElasticSearchDomain_LogPublishingOptions_AuditLogs(t *testing.T) { + var domain elasticsearch.ElasticsearchDomainStatus + ri := acctest.RandInt() + resourceId := fmt.Sprintf("tf-test-%d", ri) + resourceName := "aws_elasticsearch_domain.test" + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t); testAccPreCheckIamServiceLinkedRoleEs(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckESDomainDestroy, + Steps: []resource.TestStep{ + { + Config: testAccESDomainConfig_LogPublishingOptions(ri, elasticsearch.LogTypeAuditLogs), + Check: resource.ComposeTestCheckFunc( + testAccCheckESDomainExists(resourceName, &domain), + resource.TestCheckResourceAttr(resourceName, "log_publishing_options.#", "1"), + tfawsresource.TestCheckTypeSetElemNestedAttrs(resourceName, "log_publishing_options.*", map[string]string{ + "log_type": elasticsearch.LogTypeAuditLogs, + }), ), }, { @@ -2071,17 +2169,17 @@ resource "aws_elasticsearch_domain" "test" { `, domainName) } -func testAccESDomainConfig_LogPublishingOptions(randInt int) string { +func testAccESDomain_LogPublishingOptions_BaseConfig(randInt int) string { return fmt.Sprintf(` data "aws_partition" "current" { } resource "aws_cloudwatch_log_group" "test" { - name = "tf-test-%d" + name = "tf-test-%[1]d" } resource "aws_cloudwatch_log_resource_policy" "example" { - policy_name = "tf-cwlp-%d" + policy_name = "tf-cwlp-%[1]d" policy_document = <