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

New Resource: aws_dx_connection_association #2360

Merged

Conversation

atsushi-ishibashi
Copy link
Contributor

make testacc TEST=./aws TESTARGS='-run=TestAccAwsDxConnectionAssociation_basic'
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./aws -v -run=TestAccAwsDxConnectionAssociation_basic -timeout 120m
=== RUN   TestAccAwsDxConnectionAssociation_basic
--- PASS: TestAccAwsDxConnectionAssociation_basic (100.67s)
PASS
ok  	github.com/terraform-providers/terraform-provider-aws/aws	100.725s

@Ninir Ninir added the enhancement Requests to existing resources that expand the functionality or scope. label Nov 20, 2017
@radeksimko radeksimko added new-resource Introduces a new resource. and removed enhancement Requests to existing resources that expand the functionality or scope. labels Dec 2, 2017
Copy link
Member

@radeksimko radeksimko left a comment

Choose a reason for hiding this comment

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

@atsushi-ishibashi Thanks for another PR!

This looks overall good, I just left you some questions. Please keep in mind those are questions - I am not implying that it should be one way or another, I'm opening a conversation. 😉

d.SetId("")
return nil
}
if *resp.Connections[0].LagId != d.Get("lag_id").(string) {
Copy link
Member

Choose a reason for hiding this comment

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

As far as I understand there's 1-to-1 relationship between a connection and a LAG which this resource should represent, so shouldn't we instead treat this as if the resource (i.e. unique pair) is gone?

return nil
}
if len(resp.Connections) != 1 {
return fmt.Errorf("Number of DX Connection (%s) isn't one, got %d", connectionId, len(resp.Connections))
Copy link
Member

Choose a reason for hiding this comment

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

Just grammar nitpick - do you mind changing this to Found %d DX connections for %s, expected 1?

if err != nil {
return err
}
if resp.LagId != nil {
Copy link
Member

Choose a reason for hiding this comment

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

Have you ever experienced this in reality? Is it just a matter of time until it becomes actually disassociated or is it an erroneous/unrecoverable state? If it's the former then I'd suggest we just put a retry logic in place and wait until it's disassociated. If it's the latter then I guess this is a correct behaviour - I'm just trying to ensure that we know what we're doing here.

page_title: "AWS: aws_dx_connection_association"
sidebar_current: "docs-aws-resource-dx-connection-association"
description: |-
Associates a Connection with LAG.
Copy link
Member

Choose a reason for hiding this comment

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

Nitpick, but do you mind changing this to Associates a Direct Connect Connection with a LAG.?


# aws_dx_connection_association

Associates a Connection with LAG.
Copy link
Member

Choose a reason for hiding this comment

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

Nitpick, but do you mind changing this to Associates a Direct Connect Connection with a LAG.?

@radeksimko radeksimko added the waiting-response Maintainers are waiting on response from community or contributor. label Dec 2, 2017
@atsushi-ishibashi
Copy link
Contributor Author

I removed some extra error handling.

if len(resp.Connections) < 1 {
d.SetId("")
return nil
}
Copy link
Member

Choose a reason for hiding this comment

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

I think there was a bit of misunderstanding about what I meant by my question about LAG ID mismatch - I wasn't implying it should be removed. I meant we should treat it the same way as if there is no connection - i.e. d.SetId(""); return nil.

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, I got it👍

}
for _, v := range resp.Connections {
if *v.ConnectionId == rs.Primary.ID && v.LagId != nil {
return fmt.Errorf("Dx Connection (%s) is not diasociated with Lag", rs.Primary.ID)
Copy link
Member

Choose a reason for hiding this comment

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

nitpick: is not dissociated from Lag

@radeksimko
Copy link
Member

So I took a deeper look into how Direct Connect works with LAGs & connections and I think we'll need to add a for loop to read through all connections for the given connection ID as we cannot assume that there's only 1 connection per lag.

Basically we need to make the following config work:

resource "aws_dx_connection" "example" {
  name = "example"
  bandwidth = "1Gbps"
  location = "EqSe2"
}

resource "aws_dx_lag" "example" {
  name = "example"
  connections_bandwidth = "1Gbps"
  location = "EqSe2"
  number_of_connections = 1
}

resource "aws_dx_lag" "example2" {
  name = "example2"
  connections_bandwidth = "1Gbps"
  location = "EqSe2"
  number_of_connections = 1
}

resource "aws_dx_connection_association" "example" {
  connection_id = "${aws_dx_connection.example.id}"
  lag_id = "${aws_dx_lag.example.id}"
}

resource "aws_dx_connection_association" "example2" {
  connection_id = "${aws_dx_connection.example.id}"
  lag_id = "${aws_dx_lag.example2.id}"
}

can you also add it as an acceptance test and make it pass, please?

@atsushi-ishibashi
Copy link
Contributor Author

Could I understand what you meant? @radeksimko

TF_ACC=1 go test ./aws -v -run=TestAccAwsDxConnectionAssociation_multiConns -timeout 120m
=== RUN   TestAccAwsDxConnectionAssociation_multiConns
--- PASS: TestAccAwsDxConnectionAssociation_multiConns (41.34s)
PASS
ok  	github.com/terraform-providers/terraform-provider-aws/aws	41.386s

@radeksimko
Copy link
Member

Having a test for multiple connections is certainly helpful (thanks 👍 ), but I was talking about multiple LAGs. I just committed a failing test to you branch which hopefully explains what I mean.

You should see the following failure:

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

		DIFF:

		CREATE: aws_dx_connection_association.test2
		  connection_id: "" => "dxcon-ffo66i6d" (forces new resource)
		  lag_id:        "" => "dxlag-fhdhkf6q" (forces new resource)
...

Let me know if you need any further help in reproducing it.

@atsushi-ishibashi
Copy link
Contributor Author

atsushi-ishibashi commented Dec 4, 2017

@radeksimko
At first, I added acctest which you provided above but I had the same error. On web console, the connection which is associated with a LAG doesn't show available connection list of another LAG.
LAG can have many connections but a connection can belong to only one LAG

@radeksimko
Copy link
Member

@atsushi-ishibashi I see, thanks for the explanation.

It looks like the AWS API is behaving unexpectedly in the sense that it just accepts any association and overrides the existing one. 😞

I assume there isn't much we can do in this case - other than ask AWS to change/fix the API.

I'll merge it as is then - after removing my test.

@radeksimko radeksimko force-pushed the aws_dx_connection_association branch from c0fc1fe to 53df933 Compare December 4, 2017 16:04
@radeksimko radeksimko removed the waiting-response Maintainers are waiting on response from community or contributor. label Dec 4, 2017
@radeksimko radeksimko merged commit dcb44db into hashicorp:master Dec 4, 2017
mdlavin pushed a commit to mdlavin/terraform-provider-aws that referenced this pull request Dec 9, 2017
* New Resource: aws_dx_connection_association

* Reflect reviews

* fix

* fix

* Reflect 2nd reviews

* Add acctest
@atsushi-ishibashi atsushi-ishibashi deleted the aws_dx_connection_association branch December 13, 2017 15:16
@ghost
Copy link

ghost commented Apr 10, 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 10, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
new-resource Introduces a new resource.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants