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

Add ability to import existing VPC peering networks #4291

Conversation

austenLacy
Copy link

This PR implements the schema.ResourceImporter for the google_compute_network_peering resource. It also adds a minimal test step for importing per the testing guidelines and updates the documentation with an example of how to import.

@slevenick
Copy link
Collaborator

Hey @austenLacy
Sorry for the long delay on reviewing this!

Are you able to get the test to work? I'm not, and I think it has to do with the importer setting the id as {{name}} instead of {{network}}/{{name}} like the normal create method does.

@austenLacy
Copy link
Author

@slevenick it seems to be passing for me, but I could definitely be doing something wrong.

from VS code "run test" click

Running tool: /usr/local/go/bin/go test -timeout 30s github.com/terraform-providers/terraform-provider-google/google -run ^(TestAccComputeNetworkPeering_basic)$

ok  	github.com/terraform-providers/terraform-provider-google/google	(cached)
Success: Tests passed.

using make test

➜ make test
==> Checking source code against gofmt...
==> Checking that code complies with gofmt requirements...
go test -i $(go list ./... |grep -v 'vendor') || exit 1
echo $(go list ./... |grep -v 'vendor') | \
		xargs -t -n4 go test  -timeout=30s -parallel=4
go test -timeout=30s -parallel=4 github.com/terraform-providers/terraform-provider-google github.com/terraform-providers/terraform-provider-google/google github.com/terraform-providers/terraform-provider-google/scripts/affectedtests github.com/terraform-providers/terraform-provider-google/version
?   	github.com/terraform-providers/terraform-provider-google	[no test files]
ok  	github.com/terraform-providers/terraform-provider-google/google	(cached)
?   	github.com/terraform-providers/terraform-provider-google/scripts/affectedtests	[no test files]
?   	github.com/terraform-providers/terraform-provider-google/version	[no test files]

from terminal (using -count=1 hack to avoid using go cache in 1.12)

➜ go test ./... -count=1
?   	github.com/terraform-providers/terraform-provider-google	[no test files]
ok  	github.com/terraform-providers/terraform-provider-google/google	13.125s
?   	github.com/terraform-providers/terraform-provider-google/scripts/affectedtests	[no test files]
?   	github.com/terraform-providers/terraform-provider-google/version	[no test files]

@slevenick
Copy link
Collaborator

I believe you are only running the unit tests, not the acceptance tests. Instructions are found here: https://github.com/terraform-providers/terraform-provider-google/blob/master/.github/CONTRIBUTING.md#tests

I believe you want to run make testacc TEST=./google TESTARGS='-run= TestAccComputeNetworkPeering_basic'

This actually creates the infrastructure and tests the import against it

@austenLacy
Copy link
Author

@slevenick That makes sense now. My fault.

However, I can't seem to get past a go modules error. Grr

➜ make testacc TEST=./google TESTARGS='-run= TestAccComputeNetworkPeering_basic'
==> Checking source code against gofmt...
==> Checking that code complies with gofmt requirements...
TF_ACC=1 TF_SCHEMA_PANIC_ON_ERROR=1 go test ./google -v -run= TestAccComputeNetworkPeering_basic -timeout 240m -ldflags="-X=github.com/terraform-providers/terraform-provider-google/version.ProviderVersion=acc"
# github.com/terraform-providers/terraform-provider-google/google
package github.com/terraform-providers/terraform-provider-google/google (test)
	imports github.com/hashicorp/terraform-plugin-sdk/helper/acctest
	imports golang.org/x/crypto/ssh
	imports golang.org/x/crypto/ed25519
	imports crypto/ed25519: malformed module path "crypto/ed25519": missing dot in first path element
FAIL	github.com/terraform-providers/terraform-provider-google/google [setup failed]
FAIL
make: *** [testacc] Error 1

I've tried all of the go mod and google tricks I could find, but without success. Have you seen this before?

@slevenick
Copy link
Collaborator

@slevenick That makes sense now. My fault.

However, I can't seem to get past a go modules error. Grr

➜ make testacc TEST=./google TESTARGS='-run= TestAccComputeNetworkPeering_basic'
==> Checking source code against gofmt...
==> Checking that code complies with gofmt requirements...
TF_ACC=1 TF_SCHEMA_PANIC_ON_ERROR=1 go test ./google -v -run= TestAccComputeNetworkPeering_basic -timeout 240m -ldflags="-X=github.com/terraform-providers/terraform-provider-google/version.ProviderVersion=acc"
# github.com/terraform-providers/terraform-provider-google/google
package github.com/terraform-providers/terraform-provider-google/google (test)
	imports github.com/hashicorp/terraform-plugin-sdk/helper/acctest
	imports golang.org/x/crypto/ssh
	imports golang.org/x/crypto/ed25519
	imports crypto/ed25519: malformed module path "crypto/ed25519": missing dot in first path element
FAIL	github.com/terraform-providers/terraform-provider-google/google [setup failed]
FAIL
make: *** [testacc] Error 1

I've tried all of the go mod and google tricks I could find, but without success. Have you seen this before?

Possibly upgrading to 1.13 would help? (Assuming you are on a lower version) micro/go-micro#748

Also check that GOROOT and GOPATH are defined and correct, and that the google provider repo is within GOROOT. I'm afraid I'm not too familiar with go modules, so I won't be too much help

@austenLacy
Copy link
Author

@slevenick That makes sense now. My fault.
However, I can't seem to get past a go modules error. Grr

➜ make testacc TEST=./google TESTARGS='-run= TestAccComputeNetworkPeering_basic'
==> Checking source code against gofmt...
==> Checking that code complies with gofmt requirements...
TF_ACC=1 TF_SCHEMA_PANIC_ON_ERROR=1 go test ./google -v -run= TestAccComputeNetworkPeering_basic -timeout 240m -ldflags="-X=github.com/terraform-providers/terraform-provider-google/version.ProviderVersion=acc"
# github.com/terraform-providers/terraform-provider-google/google
package github.com/terraform-providers/terraform-provider-google/google (test)
	imports github.com/hashicorp/terraform-plugin-sdk/helper/acctest
	imports golang.org/x/crypto/ssh
	imports golang.org/x/crypto/ed25519
	imports crypto/ed25519: malformed module path "crypto/ed25519": missing dot in first path element
FAIL	github.com/terraform-providers/terraform-provider-google/google [setup failed]
FAIL
make: *** [testacc] Error 1

I've tried all of the go mod and google tricks I could find, but without success. Have you seen this before?

Possibly upgrading to 1.13 would help? (Assuming you are on a lower version) micro/go-micro#748

Also check that GOROOT and GOPATH are defined and correct, and that the google provider repo is within GOROOT. I'm afraid I'm not too familiar with go modules, so I won't be too much help

I'm on 1.13.1, but I'll keep digging. Sorry for the complications. Thanks for your help so far

}

// Replace import id for the resource id
id, err := replaceVars(d, config, "{{name}}")
Copy link

@mllu mllu Nov 25, 2019

Choose a reason for hiding this comment

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

randomly pass by, (also looking for this feature), it appears to me the format of id for google_compute_network_peering is network/name from my other self-managed resources.

I tried to checkout to this branch and was able to import my resource google_compute_network_peering, but the generated id seems only contains name.

Dunno if that matters, but wanna bring it up to discuss. Thanks in advance.

@slevenick
Copy link
Collaborator

This feature will be available via GoogleCloudPlatform/magic-modules#2751

Closing this

@slevenick slevenick closed this Nov 26, 2019
@ghost
Copy link

ghost commented Mar 29, 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. If you feel I made an error 🤖 🙉 , please reach out to my human friends 👉 [email protected]. Thanks!

@ghost ghost locked and limited conversation to collaborators Mar 29, 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