Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] r/aws_elasticsearchdomain: add support for cognito_options #5346

Merged
merged 14 commits into from
Aug 2, 2018

Conversation

aoggz
Copy link
Contributor

@aoggz aoggz commented Jul 26, 2018

Fixes #4061

Changes proposed in this pull request:

  • Add support for cognito_options in Elasticsearch domain creation.
  • Update documentation to reflect new functionality

Output from acceptance testing:

My test is currently failing. It looks like this is due to the 'behind-the-scenes' work that the Elasticsearch service is doing to configure Cognito to work with the cluster. It looks like the updates that the Elasticsearch service makes to the Cognito Identity Pool are being pulled in during the refresh, which is causing the test to fail (since tf wasn't aware of the 'initial' state).

I'm opening this PR before the this change is ready because I couldn't find an instance in the repo where a similar situation is occurring and would greatly appreciate feedback on how best to handle this!

$ make testacc TEST=./aws TESTARGS='-run=TestAccAWSElasticSearchDomain_CognitoOptions'
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./aws -v -run=TestAccAWSElasticSearchDomain_CognitoOptions -timeout 120m
=== RUN   TestAccAWSElasticSearchDomain_CognitoOptions
--- FAIL: TestAccAWSElasticSearchDomain_CognitoOptions (749.37s)
        testing.go:518: Step 0 error: After applying this step and refreshing, the plan was not empty:

                DIFF:

                UPDATE: aws_cognito_identity_pool.example
                  cognito_identity_providers.#:                                 "1" => "0"
                  cognito_identity_providers.188648750.client_id:               "l5vruqq3skb07fcbq2dgfbfuo" => ""
                  cognito_identity_providers.188648750.provider_name:           "cognito-idp.us-west-2.amazonaws.com/us-west-2_AhWuyNOVP" => ""
                  cognito_identity_providers.188648750.server_side_token_check: "true" => "false"

                STATE:

                aws_cognito_identity_pool.example:
                  ID = us-west-2:41618e40-c687-4206-bdc9-08f70ed00de4
                  provider = provider.aws
                  allow_unauthenticated_identities = false
                  arn = arn:aws:cognito-identity:us-west-2:143815088754:identitypool/us-west-2:41618e40-c687-4206-bdc9-08f70ed00de4
                  cognito_identity_providers.# = 1
                  cognito_identity_providers.188648750.client_id = l5vruqq3skb07fcbq2dgfbfuo
                  cognito_identity_providers.188648750.provider_name = cognito-idp.us-west-2.amazonaws.com/us-west-2_AhWuyNOVP
                  cognito_identity_providers.188648750.server_side_token_check = true
                  developer_provider_name =
                  identity_pool_name = tf_test_3433714343141331240
                  openid_connect_provider_arns.# = 0
                  saml_provider_arns.# = 0
                  supported_login_providers.% = 0
                aws_cognito_user_pool.example:
                  ID = us-west-2_AhWuyNOVP
                  provider = provider.aws
                  admin_create_user_config.# = 1
                  admin_create_user_config.0.allow_admin_create_user_only = false
                  admin_create_user_config.0.invite_message_template.# = 0
                  admin_create_user_config.0.unused_account_validity_days = 7
                  arn = arn:aws:cognito-idp:us-west-2:143815088754:userpool/us-west-2_AhWuyNOVP
                  auto_verified_attributes.# = 0
                  creation_date = 2018-07-26T10:42:17Z
                  device_configuration.# = 0
                  email_configuration.# = 0
                  endpoint = cognito-idp.us-west-2.amazonaws.com/us-west-2_AhWuyNOVP
                  lambda_config.# = 0
                  last_modified_date = 2018-07-26T10:42:17Z
                  mfa_configuration = OFF
                  name = tf-test-3433714343141331240
                  password_policy.# = 1
                  password_policy.0.minimum_length = 8
                  password_policy.0.require_lowercase = true
                  password_policy.0.require_numbers = true
                  password_policy.0.require_symbols = true
                  password_policy.0.require_uppercase = true
                  schema.# = 0
                  sms_configuration.# = 0
                  tags.% = 0
                  verification_message_template.# = 1
                  verification_message_template.0.default_email_option = CONFIRM_WITH_CODE
                  verification_message_template.0.email_message =
                  verification_message_template.0.email_message_by_link =
                  verification_message_template.0.email_subject =
                  verification_message_template.0.email_subject_by_link =
                  verification_message_template.0.sms_message =
                aws_cognito_user_pool_domain.example:
                  ID = tf-test-3433714343141331240
                  provider = provider.aws
                  aws_account_id = 143815088754
                  cloudfront_distribution_arn = dpp0gtxikpq3y.cloudfront.net
                  domain = tf-test-3433714343141331240
                  s3_bucket = aws-cognito-prod-pdx-assets
                  user_pool_id = us-west-2_AhWuyNOVP
                  version = 20180726104218

                  Dependencies:
                    aws_cognito_user_pool.example
                aws_elasticsearch_domain.example:
                  ID = arn:aws:es:us-west-2:143815088754:domain/tf-test-3433714343141331240
                  provider = provider.aws
                  advanced_options.% = 1
                  advanced_options.rest.action.multi.allow_explicit_index = true
                  arn = arn:aws:es:us-west-2:143815088754:domain/tf-test-3433714343141331240
                  cluster_config.# = 1
                  cluster_config.0.dedicated_master_count = 0
                  cluster_config.0.dedicated_master_enabled = false
                  cluster_config.0.dedicated_master_type =
                  cluster_config.0.instance_count = 1
                  cluster_config.0.instance_type = m4.large.elasticsearch
                  cluster_config.0.zone_awareness_enabled = false
                  cognito_options.# = 1
                  cognito_options.0.enabled = true
                  cognito_options.0.identity_pool_id = us-west-2:41618e40-c687-4206-bdc9-08f70ed00de4
                  cognito_options.0.role_arn = arn:aws:iam::143815088754:role/service-role/tf-test-3433714343141331240
                  cognito_options.0.user_pool_id = us-west-2_AhWuyNOVP
                  domain_id = 143815088754/tf-test-3433714343141331240
                  domain_name = tf-test-3433714343141331240
                  ebs_options.# = 1
                  ebs_options.0.ebs_enabled = true
                  ebs_options.0.iops = 0
                  ebs_options.0.volume_size = 10
                  ebs_options.0.volume_type = gp2
                  elasticsearch_version = 6.0
                  encrypt_at_rest.# = 1
                  encrypt_at_rest.0.enabled = false
                  encrypt_at_rest.0.kms_key_id =
                  endpoint = search-tf-test-3433714343141331240-inqnpmzxqaq3vopfc5dlmpa7cy.us-west-2.es.amazonaws.com
                  kibana_endpoint = search-tf-test-3433714343141331240-inqnpmzxqaq3vopfc5dlmpa7cy.us-west-2.es.amazonaws.com/_plugin/kibana/
                  tags.% = 0

                  Dependencies:
                    aws_cognito_identity_pool.example
                    aws_cognito_user_pool.example
                    aws_iam_role.example
                    aws_iam_role_policy_attachment.example
                aws_iam_role.example:
                  ID = tf-test-3433714343141331240
                  provider = provider.aws
                  arn = arn:aws:iam::143815088754:role/service-role/tf-test-3433714343141331240
                  assume_role_policy = {"Version":"2012-10-17","Statement":[{"Sid":"","Effect":"Allow","Principal":{"Service":"es.amazonaws.com"},"Action":"sts:AssumeRole"}]}
                  create_date = 2018-07-26T10:42:16Z
                  force_detach_policies = false
                  max_session_duration = 3600
                  name = tf-test-3433714343141331240
                  path = /service-role/
                  unique_id = AROAJAHBDLICLKECWAC3I

                  Dependencies:
                    data.aws_iam_policy_document.assume-role-policy
                aws_iam_role_policy_attachment.example:
                  ID = tf-test-3433714343141331240-20180726104216418000000001
                  provider = provider.aws
                  policy_arn = arn:aws:iam::aws:policy/AmazonESCognitoAccess
                  role = tf-test-3433714343141331240

                  Dependencies:
                    aws_iam_role.example
                data.aws_iam_policy_document.assume-role-policy:
                  ID = 196909887
                  provider = provider.aws
                  json = {
                  "Version": "2012-10-17",
                  "Statement": [
                    {
                      "Sid": "",
                      "Effect": "Allow",
                      "Action": "sts:AssumeRole",
                      "Principal": {
                        "Service": "es.amazonaws.com"
                      }
                    }
                  ]
                }
                  statement.# = 1
                  statement.0.actions.# = 1
                  statement.0.actions.2528466339 = sts:AssumeRole
                  statement.0.condition.# = 0
                  statement.0.effect = Allow
                  statement.0.not_actions.# = 0
                  statement.0.not_principals.# = 0
                  statement.0.not_resources.# = 0
                  statement.0.principals.# = 1
                  statement.0.principals.477085228.identifiers.# = 1
                  statement.0.principals.477085228.identifiers.1393498159 = es.amazonaws.com
                  statement.0.principals.477085228.type = Service
                  statement.0.resources.# = 0
                  statement.0.sid =
FAIL
FAIL    github.com/terraform-providers/terraform-provider-aws/aws       749.403s
GNUmakefile:20: recipe for target 'testacc' failed
make: *** [testacc] Error 1

...

@ghost ghost added the size/L Managed by automation to categorize the size of a PR. label Jul 26, 2018
@bflad bflad added enhancement Requests to existing resources that expand the functionality or scope. service/elasticsearch Issues and PRs that pertain to the elasticsearch service. labels Jul 26, 2018
Copy link
Contributor

@bflad bflad left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

HI @aoggz 👋 Thanks for submitting this, pretty exciting! Overall this is definitely on the right track, but I left some initial feedback. Please let us know if you have any questions or do not have time to implement these items.

As for the acceptance test refresh failure:

                UPDATE: aws_cognito_identity_pool.example
                  cognito_identity_providers.#:                                 "1" => "0"
                  cognito_identity_providers.188648750.client_id:               "l5vruqq3skb07fcbq2dgfbfuo" => ""
                  cognito_identity_providers.188648750.provider_name:           "cognito-idp.us-west-2.amazonaws.com/us-west-2_AhWuyNOVP" => ""
                  cognito_identity_providers.188648750.server_side_token_check: "true" => "false"

I'm personally okay if we double check if there's not already a filed service/cognito issue for this or create a new issue if there's not.

Once we have an issue number and since this refresh failure is outside the scope of the resource we are working on here, I'd recommend adding the following to the test configuration:

resource "aws_cognito_identity_pool" "example" {
  # ... other configuration ...

  # See also: https://github.com/terraform-providers/terraform-provider-aws/issues/XXXX
  lifecycle {
    ignore_changes = ["cognito_identity_providers"]
  }
}

I don't think we need to hold up this pull request to try and potentially adjust the other resource to better handle this situation.

if v, ok := d.GetOk("cognito_options"); ok {

options := v.([]interface{})
if len(options) > 1 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick: This error checking is already performed by the attribute schema so it can be removed 👍

  • MaxItems: 1 handles len(options) > 1
  • Required: true on nested arguments handles options[0] == nil

I'd recommend going with the below to simplify this:

if v, ok := d.GetOk("cognito_options"); ok && len(v.([]interface{})) > 0 {
  m := v.([]interface{})[0].(map[string]interface{})
  input.CognitoOptions = expandESCognitoOptions(m)
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh cool! That's much cleaner!

@@ -402,6 +444,9 @@ func resourceAwsElasticSearchDomainCreate(d *schema.ResourceData, meta interface
if isAWSErr(err, "ValidationException", "Domain is still being deleted") {
return resource.RetryableError(err)
}
if isAWSErr(err, "ValidationException", "Amazon Elasticsearch must be allowed to use the passed role") {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❤️

@@ -634,6 +683,12 @@ func resourceAwsElasticSearchDomainUpdate(d *schema.ResourceData, meta interface
input.VPCOptions = expandESVPCOptions(s)
}

if d.HasChange("cognito_options") {
options := d.Get("cognito_options").([]interface{})
s := options[0].(map[string]interface{})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line looks like it can cause a panic if cognito_options is removed from the configuration since options will have 0 elements. We should perform a length check and set the parameter to nil/empty/disabled as required, e.g.

if d.HasChange("cognito_options") {
  // default to disabling (change as necessary! this could also be handled in expandESCognitoOptions)
  input.CognitoOptions = &elasticsearch.CognitoOptions{
    Enabled: aws.Bool(false),
  }
  // only enable if provided
  if v, ok := d.GetOk("cognito_options"); ok && len(v.([]interface{})) > 0 {
    m := v.([]interface{})[0].(map[string]interface{})
    input.CognitoOptions = expandESCognitoOptions(m)
  }
}

I'd recommend adding a second TestStep to the acceptance test that covers trying to remove the cognito_options to ensure we're okay here. 👍

aws/structure.go Outdated
@@ -1088,6 +1088,51 @@ func flattenESClusterConfig(c *elasticsearch.ElasticsearchClusterConfig) []map[s
return []map[string]interface{}{m}
}

func expandESCognitoOptions(m map[string]interface{}) *elasticsearch.CognitoOptions {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems like its possible to simply some of the resource logic by accepting the []interface{} from the schema here instead of the map[string]interface{}. Then we can handle the length/nil checks in one place.

e.g.

if v, ok := d.GetOk("cognito_options"); ok {
  input.CognitoOptions = expandESCognitoOptions(v.([]interface{}))
}

aws/structure.go Outdated
}

if aws.BoolValue(c.Enabled) {
if c.UserPoolId != nil {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick: We can remove the nil checks and still prevent potential panics at the same time by using the SDK provided functions like aws.StringValue() -- since the schema will default to "" for schema.TypeString and aws.StringValue() returns "" for nil.

m["identity_pool_id"] = aws.StringValue(c.IdentityPoolId)
m["user_pool_id"] = aws.StringValue(c.UserPoolId)
m["role_arn"] = aws.StringValue(c.RoleArn)

**cognito_options** supports the following attribute:

AWS documentation: [Amazon Cognito Authentication for Kibana](https://docs.aws.amazon.com/elasticsearch-service/latest/developerguide/es-cognito-auth.html)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is missing the enabled attribute documentation 😄

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤦‍♂️

@bflad bflad added the waiting-response Maintainers are waiting on response from community or contributor. label Jul 26, 2018
@aoggz
Copy link
Contributor Author

aoggz commented Jul 27, 2018

@bflad Thanks for the feedback!

I didn't find an issue already entered, but as I was about to enter one, I wondered if it makes sense to? It doesn't feel like an issue that needs fixed, since terraform is technically working as one would expect. The lifecycle.ignore_changes functionality looks like it would achieve the desired effect.

I'll work on implementing the changes you suggested (thanks again!) and will enter the issue if you feel like it's the way we should go.

@bflad
Copy link
Contributor

bflad commented Jul 27, 2018

@aoggz you're probably right for now. 👍

@ghost ghost added the size/L Managed by automation to categorize the size of a PR. label Jul 31, 2018
@aoggz
Copy link
Contributor Author

aoggz commented Jul 31, 2018

@bflad I'm still working on incorporating your feedback, but I'm having some trouble with the tests. With the latest version, I'm seeing this issue when running my multi-step test.
I'm still digging through it. I'm focusing on my expand and flatten functions, since it looks like there's some issue parsing the state. I'll commit as I make progress, but if this error points to an obvious issue to you, guidance would be much appreciated! 😄

$ make testacc TEST=./aws TESTARGS='-run=TestAccAWSElasticSearchDomain_CognitoOptions'
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./aws -v -run=TestAccAWSElasticSearchDomain_CognitoOptions -timeout 120m
=== RUN   TestAccAWSElasticSearchDomain_CognitoOptions
--- FAIL: TestAccAWSElasticSearchDomain_CognitoOptions (1669.84s)
        testing.go:518: Step 1 error: After applying this step, the plan was not empty:

                DIFF:

                UPDATE: aws_elasticsearch_domain.example
                  cognito_options.#: "1" => "0"

                STATE:

                aws_cognito_identity_pool.example:
                  ID = us-west-2:34a46c6d-c882-4a57-bb18-bb797f321359
                  provider = provider.aws
                  allow_unauthenticated_identities = false
                  arn = arn:aws:cognito-identity:us-west-2:143815088754:identitypool/us-west-2:34a46c6d-c882-4a57-bb18-bb797f321359
                  cognito_identity_providers.# = 1
                  cognito_identity_providers.4194570943.client_id = 4ecp6go5td2er256qv2jvolqvq
                  cognito_identity_providers.4194570943.provider_name = cognito-idp.us-west-2.amazonaws.com/us-west-2_8RLGkBim7
                  cognito_identity_providers.4194570943.server_side_token_check = true
                  developer_provider_name =
                  identity_pool_name = tf_test_8021273742209468323
                  openid_connect_provider_arns.# = 0
                  saml_provider_arns.# = 0
                  supported_login_providers.% = 0
                aws_cognito_user_pool.example:
                  ID = us-west-2_8RLGkBim7
                  provider = provider.aws
                  admin_create_user_config.# = 1
                  admin_create_user_config.0.allow_admin_create_user_only = false
                  admin_create_user_config.0.invite_message_template.# = 0
                  admin_create_user_config.0.unused_account_validity_days = 7
                  arn = arn:aws:cognito-idp:us-west-2:143815088754:userpool/us-west-2_8RLGkBim7
                  auto_verified_attributes.# = 0
                  creation_date = 2018-07-31T18:27:56Z
                  device_configuration.# = 0
                  email_configuration.# = 0
                  endpoint = cognito-idp.us-west-2.amazonaws.com/us-west-2_8RLGkBim7
                  lambda_config.# = 0
                  last_modified_date = 2018-07-31T18:27:56Z
                  mfa_configuration = OFF
                  name = tf-test-8021273742209468323
                  password_policy.# = 1
                  password_policy.0.minimum_length = 8
                  password_policy.0.require_lowercase = true
                  password_policy.0.require_numbers = true
                  password_policy.0.require_symbols = true
                  password_policy.0.require_uppercase = true
                  schema.# = 0
                  sms_configuration.# = 0
                  tags.% = 0
                  verification_message_template.# = 1
                  verification_message_template.0.default_email_option = CONFIRM_WITH_CODE
                  verification_message_template.0.email_message =
                  verification_message_template.0.email_message_by_link =
                  verification_message_template.0.email_subject =
                  verification_message_template.0.email_subject_by_link =
                  verification_message_template.0.sms_message =
                aws_cognito_user_pool_domain.example:
                  ID = tf-test-8021273742209468323
                  provider = provider.aws
                  aws_account_id = 143815088754
                  cloudfront_distribution_arn = dpp0gtxikpq3y.cloudfront.net
                  domain = tf-test-8021273742209468323
                  s3_bucket = aws-cognito-prod-pdx-assets
                  user_pool_id = us-west-2_8RLGkBim7
                  version = 20180731182757

                  Dependencies:
                    aws_cognito_user_pool.example
                aws_elasticsearch_domain.example:
                  ID = arn:aws:es:us-west-2:143815088754:domain/tf-test-8021273742209468323
                  provider = provider.aws
                  advanced_options.% = 1
                  advanced_options.rest.action.multi.allow_explicit_index = true
                  arn = arn:aws:es:us-west-2:143815088754:domain/tf-test-8021273742209468323
                  cluster_config.# = 1
                  cluster_config.0.dedicated_master_count = 0
                  cluster_config.0.dedicated_master_enabled = false
                  cluster_config.0.dedicated_master_type =
                  cluster_config.0.instance_count = 1
                  cluster_config.0.instance_type = m4.large.elasticsearch
                  cluster_config.0.zone_awareness_enabled = false
                  cognito_options.# = 1
                  cognito_options.0.enabled = false
                  cognito_options.0.identity_pool_id =
                  cognito_options.0.role_arn =
                  cognito_options.0.user_pool_id =
                  domain_id = 143815088754/tf-test-8021273742209468323
                  domain_name = tf-test-8021273742209468323
                  ebs_options.# = 1
                  ebs_options.0.ebs_enabled = true
                  ebs_options.0.iops = 0
                  ebs_options.0.volume_size = 10
                  ebs_options.0.volume_type = gp2
                  elasticsearch_version = 6.0
                  encrypt_at_rest.# = 1
                  encrypt_at_rest.0.enabled = false
                  encrypt_at_rest.0.kms_key_id =
                  endpoint = search-tf-test-8021273742209468323-4yh4rtjbyi6v3op3fupltuihhu.us-west-2.es.amazonaws.com
                  kibana_endpoint = search-tf-test-8021273742209468323-4yh4rtjbyi6v3op3fupltuihhu.us-west-2.es.amazonaws.com/_plugin/kibana/
                  tags.% = 0
                aws_iam_role.example:
                  ID = tf-test-8021273742209468323
                  provider = provider.aws
                  arn = arn:aws:iam::143815088754:role/service-role/tf-test-8021273742209468323
                  assume_role_policy = {"Version":"2012-10-17","Statement":[{"Sid":"","Effect":"Allow","Principal":{"Service":"es.amazonaws.com"},"Action":"sts:AssumeRole"}]}
                  create_date = 2018-07-31T18:27:55Z
                  force_detach_policies = false
                  max_session_duration = 3600
                  name = tf-test-8021273742209468323
                  path = /service-role/
                  unique_id = AROAI7GQH5DS4KXMMQO7Y

                  Dependencies:
                    data.aws_iam_policy_document.assume-role-policy
                aws_iam_role_policy_attachment.example:
                  ID = tf-test-8021273742209468323-20180731182755304400000001
                  provider = provider.aws
                  policy_arn = arn:aws:iam::aws:policy/AmazonESCognitoAccess
                  role = tf-test-8021273742209468323

                  Dependencies:
                    aws_iam_role.example
                data.aws_iam_policy_document.assume-role-policy:
                  ID = 196909887
                  provider = provider.aws
                  json = {
                  "Version": "2012-10-17",
                  "Statement": [
                    {
                      "Sid": "",
                      "Effect": "Allow",
                      "Action": "sts:AssumeRole",
                      "Principal": {
                        "Service": "es.amazonaws.com"
                      }
                    }
                  ]
                }
                  statement.# = 1
                  statement.0.actions.# = 1
                  statement.0.actions.2528466339 = sts:AssumeRole
                  statement.0.condition.# = 0
                  statement.0.effect = Allow
                  statement.0.not_actions.# = 0
                  statement.0.not_principals.# = 0
                  statement.0.not_resources.# = 0
                  statement.0.principals.# = 1
                  statement.0.principals.477085228.identifiers.# = 1
                  statement.0.principals.477085228.identifiers.1393498159 = es.amazonaws.com
                  statement.0.principals.477085228.type = Service
                  statement.0.resources.# = 0
                  statement.0.sid =
FAIL
FAIL    github.com/terraform-providers/terraform-provider-aws/aws       1669.869s
GNUmakefile:20: recipe for target 'testacc' failed
make: *** [testacc] Error 1

@bflad
Copy link
Contributor

bflad commented Jul 31, 2018

The schema can sometimes be a little awkward with "container" attributes like cognito_options depending on how the API handles it. If the API continues to return CognitoOptions (e.g. with Enabled set to false after disabling it), then you can setup the cognito_options attribute to ignore the difference between the Terraform state (cognito_options existing with the API response) and not having it defined in the Terraform configuration (cognito_options missing) using a DiffSuppressFunc. We prefer this over using Computed: true on cognito_options since it still allows for drift detection of the child attributes.

Here's code I've used to workaround this with some other resources:

DiffSuppressFunc: func(k, old, new string, d *schema.ResourceData) bool {
	if old == "1" && new == "0" {
		return true
	}
	return false
},

Hope this helps.

Add func to suppress diff if cognito_options count changes from 1 to 0
@ghost ghost added the size/L Managed by automation to categorize the size of a PR. label Aug 1, 2018
@aoggz
Copy link
Contributor Author

aoggz commented Aug 1, 2018

@bflad, your suggestion worked! I added another test and simplified the test methods.

$ make testacc TEST=./aws TESTARGS='-run=TestAccAWSElasticSearchDomain_CognitoOptions'             
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./aws -v -run=TestAccAWSElasticSearchDomain_CognitoOptions -timeout 120m
=== RUN   TestAccAWSElasticSearchDomain_CognitoOptionsCreateAndRemove
--- PASS: TestAccAWSElasticSearchDomain_CognitoOptionsCreateAndRemove (1515.03s)
=== RUN   TestAccAWSElasticSearchDomain_CognitoOptionsUpdate
--- PASS: TestAccAWSElasticSearchDomain_CognitoOptionsUpdate (1565.07s)
PASS
ok      github.com/terraform-providers/terraform-provider-aws/aws       3080.130s

@bflad bflad removed the waiting-response Maintainers are waiting on response from community or contributor. label Aug 1, 2018
Copy link
Contributor

@bflad bflad left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great, @aoggz! 🚀

17 tests passed (all tests)
=== RUN   TestAccAWSElasticSearchDomain_duplicate
--- PASS: TestAccAWSElasticSearchDomain_duplicate (579.48s)
=== RUN   TestAccAWSElasticSearchDomain_encrypt_at_rest_specify_key
--- PASS: TestAccAWSElasticSearchDomain_encrypt_at_rest_specify_key (755.62s)
=== RUN   TestAccAWSElasticSearchDomain_v23
--- PASS: TestAccAWSElasticSearchDomain_v23 (768.86s)
=== RUN   TestAccAWSElasticSearchDomain_tags
--- PASS: TestAccAWSElasticSearchDomain_tags (901.22s)
=== RUN   TestAccAWSElasticSearchDomain_encrypt_at_rest_default_key
--- PASS: TestAccAWSElasticSearchDomain_encrypt_at_rest_default_key (948.02s)
=== RUN   TestAccAWSElasticSearchDomain_LogPublishingOptions
--- PASS: TestAccAWSElasticSearchDomain_LogPublishingOptions (967.62s)
=== RUN   TestAccAWSElasticSearchDomain_importBasic
--- PASS: TestAccAWSElasticSearchDomain_importBasic (967.74s)
=== RUN   TestAccAWSElasticSearchDomain_complex
--- PASS: TestAccAWSElasticSearchDomain_complex (1122.03s)
=== RUN   TestAccAWSElasticSearchDomain_basic
--- PASS: TestAccAWSElasticSearchDomain_basic (1276.59s)
=== RUN   TestAccAWSElasticSearchDomain_vpc
--- PASS: TestAccAWSElasticSearchDomain_vpc (1425.47s)
=== RUN   TestAccAWSElasticSearchDomain_CognitoOptionsCreateAndRemove
--- PASS: TestAccAWSElasticSearchDomain_CognitoOptionsCreateAndRemove (1513.36s)
=== RUN   TestAccAWSElasticSearchDomain_policy
--- PASS: TestAccAWSElasticSearchDomain_policy (1824.14s)
=== RUN   TestAccAWSElasticSearchDomain_update
--- PASS: TestAccAWSElasticSearchDomain_update (1876.49s)
=== RUN   TestAccAWSElasticSearchDomain_internetToVpcEndpoint
--- PASS: TestAccAWSElasticSearchDomain_internetToVpcEndpoint (2006.04s)
=== RUN   TestAccAWSElasticSearchDomain_CognitoOptionsUpdate
--- PASS: TestAccAWSElasticSearchDomain_CognitoOptionsUpdate (2049.42s)
=== RUN   TestAccAWSElasticSearchDomain_vpc_update
--- PASS: TestAccAWSElasticSearchDomain_vpc_update (2119.34s)
=== RUN   TestAccAWSElasticSearchDomain_update_volume_type
--- PASS: TestAccAWSElasticSearchDomain_update_volume_type (2769.39s)

@bflad bflad added this to the v1.30.0 milestone Aug 2, 2018
@bflad bflad merged commit 1887610 into hashicorp:master Aug 2, 2018
@bflad
Copy link
Contributor

bflad commented Aug 2, 2018

This has been released in version 1.30.0 of the AWS provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading.

@ghost
Copy link

ghost commented Apr 4, 2020

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. Thanks!

@ghost ghost locked and limited conversation to collaborators Apr 4, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement Requests to existing resources that expand the functionality or scope. service/elasticsearch Issues and PRs that pertain to the elasticsearch service. size/L Managed by automation to categorize the size of a PR.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Feature Request: Elasticsearch Service Kibana with Cognito authentication
2 participants