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

provider/aws: Handle missing EFS mount target in aws_efs_mount_target. #8529

Conversation

kwilczynski
Copy link
Contributor

This commit resolves issue where the EFS mount target would be already
deleted (e.g. it was deleted outside of Terraform, etc.). Also, correct
how values are begin set in the ReadFunc to avoid nil pointer dereference.

Signed-off-by: Krzysztof Wilczynski [email protected]

This commit resolves issue where the EFS mount target would be already
deleted (e.g. it was deleted outside of Terraform, etc.). Also, correct
how values are begin set in the ReadFunc to avoid nil pointer dereference.

Signed-off-by: Krzysztof Wilczynski <[email protected]>
@kwilczynski
Copy link
Contributor Author

Resolves #8523.

d.Set("ip_address", *mt.IpAddress)
d.Set("subnet_id", *mt.SubnetId)
d.Set("network_interface_id", *mt.NetworkInterfaceId)
d.Set("file_system_id", mt.FileSystemId)
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice changes!

@kwilczynski
Copy link
Contributor Author

Tests are passing:

$ make testacc TEST=./builtin/providers/aws TESTARGS='-run=TestAccAWSEFSMountTarget'
==> Checking that code complies with gofmt requirements...
go generate $(go list ./... | grep -v /terraform/vendor/)
2016/08/29 15:18:55 Generated command/internal_plugin_list.go
TF_ACC=1 go test ./builtin/providers/aws -v -run=TestAccAWSEFSMountTarget -timeout 120m
=== RUN   TestAccAWSEFSMountTarget_importBasic
--- PASS: TestAccAWSEFSMountTarget_importBasic (256.33s)
=== RUN   TestAccAWSEFSMountTarget_basic
--- PASS: TestAccAWSEFSMountTarget_basic (448.11s)
PASS
ok      github.com/hashicorp/terraform/builtin/providers/aws    704.461s

@kwilczynski
Copy link
Contributor Author

@stack72 over to you 🚀

@@ -114,8 +114,8 @@ func resourceAwsEfsMountTargetCreate(d *schema.ResourceData, meta interface{}) e
return nil, "error", err
}

if len(resp.MountTargets) < 1 {
return nil, "error", fmt.Errorf("EFS mount target %q not found", d.Id())
if resp.MountTargets != nil && len(resp.MountTargets) < 1 {
Copy link
Contributor

Choose a reason for hiding this comment

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

Could this be refactored into a helper method? We tend to repeat this process a lot

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You mean a lot in here, or a lot all over the place?

Copy link
Contributor

Choose a reason for hiding this comment

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

i believe it's used 3 or 4 times in this file right?

@stack72
Copy link
Contributor

stack72 commented Aug 29, 2016

Few nit picks inline but this looks pretty good :)

@kwilczynski
Copy link
Contributor Author

@stack72 thank you! I will update as per the suggestions :)

@kwilczynski kwilczynski changed the title Handle missing EFS mount target in aws_efs_mount_target. [WIP] provider/aws: Handle missing EFS mount target in aws_efs_mount_target. Aug 29, 2016
@kwilczynski kwilczynski force-pushed the fix/handle-missing-mount-aws_efs_mount_target branch 2 times, most recently from 320e026 to a7e5953 Compare August 29, 2016 17:36
region := "non-existant-1"
id := "fs-123456ab"

expected := fmt.Sprintf("%s.%s.efs.%s.amazonaws.com", az, id, region)
Copy link
Member

@radeksimko radeksimko Aug 29, 2016

Choose a reason for hiding this comment

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

I think that a black-box approach here would be more useful. i.e. The function should not try to cover all possible cases, because that would mean we'd have to reimplement the function again inside a test - which is what you did here.

e.g. typically you'd be testing that

testedSum(1, 1) == 2
testedSum(3, 4) == 7

rather than

mySumInTest(a, b) == testedSum(a, b)

Having static and simpler tests also makes it easier to spot a bug.

@kwilczynski kwilczynski force-pushed the fix/handle-missing-mount-aws_efs_mount_target branch from a7e5953 to 09c37b0 Compare August 29, 2016 17:48
Signed-off-by: Krzysztof Wilczynski <[email protected]>
@kwilczynski kwilczynski force-pushed the fix/handle-missing-mount-aws_efs_mount_target branch from 09c37b0 to 4df4bb6 Compare August 29, 2016 20:16
This commit adds a helper which can be used to check whether the response
contains a valid and non-empty list of EFS file system mount targets.

Signed-off-by: Krzysztof Wilczynski <[email protected]>
This commit adds a test to verify the condition where the underlying EFS mount
target would be deleted and/or disappear resulting in a new resource to be
created to replace it.

Signed-off-by: Krzysztof Wilczynski <[email protected]>
@kwilczynski
Copy link
Contributor Author

@stack72 @radeksimko over to you 🚀

I've added the helper methods with uni tests, plus an acceptance test to check for non-empty plan (the disappear case), the tests are passing:

(unit)

 make test TEST=./builtin/providers/aws TESTARGS='-run=TestResourceAWSEFSMountTarget_ -v'
==> Checking that code complies with gofmt requirements...
go generate $(go list ./... | grep -v /terraform/vendor/)
2016/08/29 23:10:45 Generated command/internal_plugin_list.go
TF_ACC= go test ./builtin/providers/aws -run=TestResourceAWSEFSMountTarget_ -v -timeout=30s -parallel=4
=== RUN   TestResourceAWSEFSMountTarget_mountTargetDnsName
--- PASS: TestResourceAWSEFSMountTarget_mountTargetDnsName (0.00s)
=== RUN   TestResourceAWSEFSMountTarget_hasEmptyMountTargets
--- PASS: TestResourceAWSEFSMountTarget_hasEmptyMountTargets (0.00s)
PASS
ok      github.com/hashicorp/terraform/builtin/providers/aws    0.016s

(acceptance)

$ make testacc TEST=./builtin/providers/aws TESTARGS='-run=TestAccAWSEFSMountTarget_'
==> Checking that code complies with gofmt requirements...
go generate $(go list ./... | grep -v /terraform/vendor/)
2016/08/29 23:06:27 Generated command/internal_plugin_list.go
TF_ACC=1 go test ./builtin/providers/aws -v -run=TestAccAWSEFSMountTarget_ -timeout 120m
=== RUN   TestAccAWSEFSMountTarget_importBasic
--- PASS: TestAccAWSEFSMountTarget_importBasic (226.74s)
=== RUN   TestAccAWSEFSMountTarget_basic
--- PASS: TestAccAWSEFSMountTarget_basic (420.03s)
=== RUN   TestAccAWSEFSMountTarget_disappears
--- PASS: TestAccAWSEFSMountTarget_disappears (219.64s)
PASS
ok      github.com/hashicorp/terraform/builtin/providers/aws    866.430s

@kwilczynski kwilczynski changed the title [WIP] provider/aws: Handle missing EFS mount target in aws_efs_mount_target. provider/aws: Handle missing EFS mount target in aws_efs_mount_target. Aug 29, 2016
@stack72
Copy link
Contributor

stack72 commented Aug 30, 2016

Hi @kwilczynski

This looks good :) Thanks for adding the extra test:

% make testacc TEST=./builtin/providers/aws TESTARGS='-run=TestAccAWSEFSMountTarget_'
==> Checking that code complies with gofmt requirements...
go generate $(go list ./... | grep -v /terraform/vendor/)
2016/08/30 10:26:01 Generated command/internal_plugin_list.go
TF_ACC=1 go test ./builtin/providers/aws -v -run=TestAccAWSEFSMountTarget_ -timeout 120m
=== RUN   TestAccAWSEFSMountTarget_importBasic
--- PASS: TestAccAWSEFSMountTarget_importBasic (227.40s)
=== RUN   TestAccAWSEFSMountTarget_basic
--- PASS: TestAccAWSEFSMountTarget_basic (425.92s)
=== RUN   TestAccAWSEFSMountTarget_disappears
--- PASS: TestAccAWSEFSMountTarget_disappears (219.35s)
PASS
ok      github.com/hashicorp/terraform/builtin/providers/aws    872.688s

Paul

@stack72 stack72 merged commit 6a94f92 into hashicorp:master Aug 30, 2016
@ghost
Copy link

ghost commented Apr 22, 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 have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@ghost ghost locked and limited conversation to collaborators Apr 22, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants