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

DNAT: allow different src/translated port #14437

Closed
wants to merge 11 commits into from
Closed

Conversation

Boran
Copy link

@Boran Boran commented May 12, 2017

Initial work on #12384.

Building with UKCloud/govcloudair@81750aa

The corresponding issue in govair is vmware-archive/govcloudair#37 and UKCloud/govcloudair#3

Added a new (optional) param translated_port, keeping the existing port as the src port.
If translated_port is not specified use port - allows backward compatibility.
The name translated_port was selected because it is closer to the api and is less confusing than internal/external for example.

  • Does the output have to have a specific format?
    vcd_dnat.test-ssh1: Creation complete (ID: 193.1.1.1:22 > 172.16.8.36:40022)
  • How/where does one define the version of govcloudair to pull in, so that travis tests work?

@Boran Boran changed the title DNAT: all different src/translated port DNAT: allow different src/translated port May 12, 2017
@Boran
Copy link
Author

Boran commented May 22, 2017

@robcoward could you have a look please, anything else needed?

FYI
15:04 $ make test TEST=./builtin/providers/vcd
.....
echo ./builtin/providers/vcd |
xargs -t -n4 go test -timeout=60s -parallel=4
go test -timeout=60s -parallel=4 ./builtin/providers/vcd
ok github.com/hashicorp/terraform/builtin/providers/vcd 0.031s

@Boran
Copy link
Author

Boran commented May 23, 2017

@ewypych could you look too please? I integrated your code for the test, as that part was missing.

@ewypych
Copy link
Contributor

ewypych commented May 23, 2017

@Boran LGTM. If everything works properly, I don't mind merging. 👍 Hope it will be merged. 😄

@bobbydeveaux
Copy link
Contributor

Awesome- looks great. @robcoward has left UKCloud now so not sure he'll be checking these alerts.

Would be great if you could merge please @ewypych

@robcoward
Copy link
Contributor

@Boran LGTM. Like @bobbydeveaux said, I no longer work for UKCloud so dont have the infrastructure to test this against, but the logic looks sound.
👍

@ewypych
Copy link
Contributor

ewypych commented May 26, 2017

@robcoward @bobbydeveaux If you mean whether it works with vCloud, I can compile and test it on vCloud Director (8.2 and 8.0 for SP, have access only to these versions). Unfortunately, Sunday evening is the first possible date.

I've made my version (didn't notice that @Boran made it first) and it works fine with the infrastructure (you can look at the code here #14709). Code is similar, so I assume that everything is great and there should be no problems.

And Bobby - bad news, I haven't permissions to merge, I'm just an ordinary contributor. 😄 But I have the same view - merging would be great!

@Boran
Copy link
Author

Boran commented May 29, 2017

I have tested on vCloud Director 8.02.4348775

@bobbydeveaux: Have you merge rights?

@bobbydeveaux
Copy link
Contributor

Afraid not. I can merge anything UKCloud, but not Hashicorp! :)

@Boran
Copy link
Author

Boran commented May 31, 2017

@jbardin Could you help, or know who could help us get this PR merged?

Copy link
Member

@jbardin jbardin left a comment

Choose a reason for hiding this comment

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

Thanks for the contribution!

There's a few comments in-line. We also need the output from an acceptance test run.

I'll hand this off to someone who does more providers to give it the final review and merge.!

@@ -77,7 +89,7 @@ func resourceVcdDNATCreate(d *schema.ResourceData, meta interface{}) error {
return fmt.Errorf("Error completing tasks: %#v", err)
}

d.SetId(d.Get("external_ip").(string) + "_" + portString)
d.SetId(d.Get("external_ip").(string) + ":" + portString + " > " + d.Get("internal_ip").(string) + ":" + trlateportString)
Copy link
Member

Choose a reason for hiding this comment

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

Is changing the ID going effect existing resources?

Copy link
Author

Choose a reason for hiding this comment

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

Yes, but the current ID is not unique and is a bug if left so (in my opinion).

@@ -49,6 +55,10 @@ func resourceVcdDNATCreate(d *schema.ResourceData, meta interface{}) error {
vcdClient.Mutex.Lock()
defer vcdClient.Mutex.Unlock()
portString := getPortString(d.Get("port").(int))
trlateportString := portString // default
Copy link
Member

Choose a reason for hiding this comment

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

Can we make this variable a little easier to read? translatedPortString isn't much longer.

Copy link
Author

Choose a reason for hiding this comment

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

sure, change committed.

Check: resource.ComposeTestCheckFunc(
testAccCheckVcdDNATExists("vcd_dnat.bar", &e),
resource.TestCheckResourceAttr(
"vcd_dnat.bar", "external_ip", os.Getenv("VCD_EXTERNAL_IP")),
resource.TestCheckResourceAttr(
"vcd_dnat.bar", "port", "77"),
"vcd_dnat.bar", "port", "7777"),
Copy link
Member

Choose a reason for hiding this comment

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

Since existing configs are still valid, I'd rather leave the existing test and add a new test case with a translated port.

@Boran
Copy link
Author

Boran commented Jun 1, 2017

@bobbydeveaux I merged the latest terraform master + govcloudair before starting acceptance tests. On compiling now getting

Stderr: # github.com/hashicorp/terraform/vendor/github.com/ukcloud/govcloudair/types/v56
vendor/github.com/ukcloud/govcloudair/types/v56/types.go:69: undefined: LinkList

Any idea where govair is expecting that type to come from?

@bobbydeveaux
Copy link
Contributor

bobbydeveaux commented Jun 1, 2017

@Boran I had this before.. it's a pain and I'm unsure why go vendor requires this step, but you need to fetch all 3 directories in govcloudair:

govendor fetch github.com/ukcloud/govcloudair
govendor fetch github.com/ukcloud/govcloudair/types
govendor fetch github.com/ukcloud/govcloudair/types/v56

I'm guessing you only did the first one, as the LinkList is in types/v56/link.go

HTH! :)

@Boran
Copy link
Author

Boran commented Jun 1, 2017

Hmm. It took 20mins to get those, but it helped thanks!
are there other types to get ?

vendor/github.com/ukcloud/govcloudair/api_vcd.go:15: undefined: Org
vendor/github.com/ukcloud/govcloudair/vdc.go:17: undefined: Client

@bobbydeveaux
Copy link
Contributor

Very odd. You've done all three?

@Boran
Copy link
Author

Boran commented Jun 1, 2017

yes, and doing a "grep -R Client github.com/hashicorp/terraform/vendor/github.com/ukcloud/govcloudair" I do not see where Client is defined.
(and Govendor take 30 minutes).

13:11 $ govendor fetch github.com/UKCloud/govcloudair && govendor fetch github.com/ukcloud/govcloudair/types && govendor fetch github.com/ukcloud/govcloudair/types/v56

13:39 $ XC_OS="darwin" XC_ARCH="amd64" make bin
==> Checking that code complies with gofmt requirements...
go generate $(go list ./... | grep -v /terraform/vendor/)
2017/06/01 13:39:33 Generated command/internal_plugin_list.go
==> Removing old directory...
==> Building...
Number of parallel builds: 7
-->    darwin/amd64: github.com/hashicorp/terraform
1 errors occurred:
--> darwin/amd64 error: exit status 2
Stderr: # github.com/hashicorp/terraform/vendor/github.com/ukcloud/govcloudair
vendor/github.com/ukcloud/govcloudair/api_vcd.go:15: undefined: Org
vendor/github.com/ukcloud/govcloudair/vdc.go:17: undefined: Client

@bobbydeveaux
Copy link
Contributor

terraform/vendor/github.com/ukcloud/govcloudair/api.go:19

// Client provides a client to vCloud Air, values can be populated automatically using the Authenticate method.
type Client struct {
APIVersion string // The API version required
VCDToken string // Access Token (authorization header)
VCDAuthHeader string // Authorization header
VCDVDCHREF url.URL // HREF of the backend VDC you're using
Http http.Client // HttpClient is the client to use. Default will be used if not provided.
}

@bobbydeveaux
Copy link
Contributor

Does make plugin-dev PLUGIN=provider-vcd work for you?

Personally, I use; make dev

@Boran
Copy link
Author

Boran commented Jun 1, 2017

There is no api.go
ls vendor/github.com/ukcloud/govcloudair/
LICENSE Makefile api_vcd.go edgegateway.go types vapp.go vdc.go

I realise now how I did this before:
mv vendor/github.com/ukcloud/govcloudair vendor/github.com/ukcloud/govcloudair.$$
and checkout govcloudair into ~/gocode/src/github.com/UKCloud/govcloudair. (in that folder I can see api.go and terraform compile just fine)
So govendor is probably not picking up the right (latest) version... maybe you have an idea why?

@Boran
Copy link
Author

Boran commented Jun 1, 2017

I understand that one uses "make plugin-dev" to build only the plugin and link it in dynamically on startup. I prefer to build the full binary.

@jbardin, @catsby: So I have now been able to run acceptance tests and as requested, have separated the TestAccVcdDNAT_Basic into TestAccVcdDNAT_Basic and TestAccVcdDNAT_tlate.

14:47 $ make testacc TEST=./builtin/providers/vcd
==> Checking that code complies with gofmt requirements...
go generate $(go list ./... | grep -v /terraform/vendor/)
2017/06/01 14:47:37 Generated command/internal_plugin_list.go
TF_ACC=1 go test ./builtin/providers/vcd -v -timeout 120m
=== RUN TestProvider
--- PASS: TestProvider (0.00s)
=== RUN TestProvider_impl
--- PASS: TestProvider_impl (0.00s)
=== RUN TestAccVcdDNAT_Basic
--- PASS: TestAccVcdDNAT_Basic (134.08s)
=== RUN TestAccVcdDNAT_tlate
--- PASS: TestAccVcdDNAT_tlate (287.34s)
=== RUN TestAccVcdFirewallRules_basic
--- PASS: TestAccVcdFirewallRules_basic (236.37s)
=== RUN TestAccVcdNetwork_Basic
--- PASS: TestAccVcdNetwork_Basic (137.87s)
=== RUN TestAccVcdSNAT_Basic
--- PASS: TestAccVcdSNAT_Basic (172.24s)

There is one fail, but not related to this PR
=== RUN TestAccVcdVApp_PowerOff
--- FAIL: TestAccVcdVApp_PowerOff (201.88s)
testing.go:280: Step 0 error: Error applying: 1 error(s) occurred:
* vcd_vapp.foobar: 1 error(s) occurred:
* vcd_vapp.foobar: Error finding catalog: &errors.errorString{s:"can't find catalog: NubesLab"}
FAIL

@pasikarkkainen
Copy link

@Boran : Thanks a lot! Sounds like this PR is ready to go then?

@bobbydeveaux
Copy link
Contributor

bobbydeveaux commented Jun 7, 2017

Sorry @Boran didn't see your other replies. Glad you're up and running and this LGTM!

@Boran
Copy link
Author

Boran commented Jun 9, 2017

@catsby : have you had a chance to review/look? :-)

@Boran
Copy link
Author

Boran commented Jun 16, 2017

Move this PR to the new vcd provider repo.
https://github.com/terraform-providers/terraform-provider-vcd/pull/19

@Boran Boran closed this Jun 16, 2017
@ghost
Copy link

ghost commented Apr 8, 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 8, 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.

8 participants