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

issue #5440 terraform crash in resource elasticsearch_domain #5451

Merged
merged 4 commits into from
Aug 8, 2018

Conversation

saravanan30erd
Copy link
Contributor

@saravanan30erd saravanan30erd commented Aug 4, 2018

Fixes #5440

Changes proposed in this pull request:

  • Change 1
    fixed panic nil pointer dereference error.
  • Change 2
    Properly dereferenced other attributes too.

@ghost ghost added the size/XS Managed by automation to categorize the size of a PR. label Aug 4, 2018
@ghost ghost added size/S Managed by automation to categorize the size of a PR. and removed size/XS Managed by automation to categorize the size of a PR. labels Aug 4, 2018
@@ -548,7 +548,7 @@ func resourceAwsElasticSearchDomainRead(d *schema.ResourceData, meta interface{}
}
if ds.SnapshotOptions != nil {
Copy link
Contributor

@bflad bflad Aug 6, 2018

Choose a reason for hiding this comment

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

This d.Set() was incorrectly implemented before (notice the missing [] before the map) and we should probably fix it now. I think the AutomatedSnapshotStartHour value also needs to be wrapped in int(). Something like the below could handle both for now and return an error if incorrect:

if err := d.Set("snapshot_options", flattenESSnapshotOptions(ds.SnapshotOptions)); err != nil {
	return fmt.Errorf("error setting snapshot_options: %s": err)
}
func flattenESSnapshotOptions(snapshotOptions *elasticsearch.SnapshotOptions) []map[string]interface{} {
	if snapshotOptions == nil {
		return []map[string]interface{}{}
	}

	m := map[string]interface{}{
		"automated_snapshot_start_hour": int(aws.Int64Value(snapshotOptions.AutomatedSnapshotStartHour)),
	}

	return []map[string]interface{}{m}
}

@bflad bflad added bug Addresses a defect in current functionality. crash Results from or addresses a Terraform crash or kernel panic. service/elasticsearch Issues and PRs that pertain to the elasticsearch service. labels Aug 6, 2018
@bflad bflad added this to the v1.31.0 milestone Aug 6, 2018
@ghost ghost added size/M Managed by automation to categorize the size of a PR. and removed size/S Managed by automation to categorize the size of a PR. labels Aug 6, 2018
@saravanan30erd
Copy link
Contributor Author

@bflad Done 👍

@bflad
Copy link
Contributor

bflad commented Aug 6, 2018

Looks like one more little thing if you have a chance, since we actually fixed the "container" snapshot_options attribute, its reporting a difference if its not defined in the configuration:

=== RUN   TestAccAWSElasticSearchDomain_basic
--- FAIL: TestAccAWSElasticSearchDomain_basic (1214.92s)
	testing.go:518: Step 0 error: After applying this step, the plan was not empty:
		
		DIFF:
		
		UPDATE: aws_elasticsearch_domain.example
		  snapshot_options.#: "1" => "0"

It should be okay if we tell the schema to ignore this difference as the underlying attributes are what really matter in this case. 👍

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

Thanks so much!

@ghost ghost added the size/M Managed by automation to categorize the size of a PR. label Aug 6, 2018
@saravanan30erd
Copy link
Contributor Author

saravanan30erd commented Aug 6, 2018

@bflad I added diffsuppress func. I think if we check the nil value for SnapshotOptions before setting it like below, we can prevent this issue right?

if ds.SnapshotOptions != nil {
    if err := d.Set("snapshot_options", flattenESSnapshotOptions(ds.SnapshotOptions)); err != nil {
	        return fmt.Errorf("error setting snapshot_options: %s", err)
    }
}

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.

Thanks @saravanan30erd! LGTM 🚀

(Test failures unrelated)

=== RUN   TestAccAWSElasticSearchDomain_duplicate
--- FAIL: TestAccAWSElasticSearchDomain_duplicate (551.56s)
=== RUN   TestAccAWSElasticSearchDomain_encrypt_at_rest_specify_key
--- PASS: TestAccAWSElasticSearchDomain_encrypt_at_rest_specify_key (787.75s)
=== RUN   TestAccAWSElasticSearchDomain_policy
--- PASS: TestAccAWSElasticSearchDomain_policy (820.13s)
=== RUN   TestAccAWSElasticSearchDomain_importBasic
--- PASS: TestAccAWSElasticSearchDomain_importBasic (1017.47s)
=== RUN   TestAccAWSElasticSearchDomain_v23
--- PASS: TestAccAWSElasticSearchDomain_v23 (1040.20s)
=== RUN   TestAccAWSElasticSearchDomain_basic
--- PASS: TestAccAWSElasticSearchDomain_basic (1054.86s)
=== RUN   TestAccAWSElasticSearchDomain_complex
--- PASS: TestAccAWSElasticSearchDomain_complex (1162.99s)
=== RUN   TestAccAWSElasticSearchDomain_encrypt_at_rest_default_key
--- PASS: TestAccAWSElasticSearchDomain_encrypt_at_rest_default_key (1265.94s)
=== RUN   TestAccAWSElasticSearchDomainPolicy_basic
--- PASS: TestAccAWSElasticSearchDomainPolicy_basic (1355.98s)
=== RUN   TestAccAWSElasticSearchDomain_vpc
--- PASS: TestAccAWSElasticSearchDomain_vpc (1366.21s)
=== RUN   TestAccAWSElasticSearchDomain_CognitoOptionsCreateAndRemove
--- PASS: TestAccAWSElasticSearchDomain_CognitoOptionsCreateAndRemove (1405.46s)
=== RUN   TestAccAWSElasticSearchDomain_tags
--- PASS: TestAccAWSElasticSearchDomain_tags (1471.90s)
=== RUN   TestAccAWSElasticSearchDomain_CognitoOptionsUpdate
--- PASS: TestAccAWSElasticSearchDomain_CognitoOptionsUpdate (1529.72s)
=== RUN   TestAccAWSElasticSearchDomain_LogPublishingOptions
--- PASS: TestAccAWSElasticSearchDomain_LogPublishingOptions (1655.18s)
=== RUN   TestAccAWSElasticSearchDomain_update
--- PASS: TestAccAWSElasticSearchDomain_update (2038.16s)
=== RUN   TestAccAWSElasticSearchDomain_vpc_update
--- PASS: TestAccAWSElasticSearchDomain_vpc_update (2267.89s)
=== RUN   TestAccAWSElasticSearchDomain_internetToVpcEndpoint
--- PASS: TestAccAWSElasticSearchDomain_internetToVpcEndpoint (2451.08s)
=== RUN   TestAccAWSElasticSearchDomain_update_volume_type
--- FAIL: TestAccAWSElasticSearchDomain_update_volume_type (5347.53s)

@bflad bflad merged commit fbf4ecf into hashicorp:master Aug 8, 2018
@bflad
Copy link
Contributor

bflad commented Aug 9, 2018

This has been released in version 1.31.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
bug Addresses a defect in current functionality. crash Results from or addresses a Terraform crash or kernel panic. service/elasticsearch Issues and PRs that pertain to the elasticsearch service. size/M Managed by automation to categorize the size of a PR.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Terraform crash (SIGSEGV) when running import of elasticsearch with Error logs enabled
2 participants