-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Import for compute_address now requires region/name. Changed the ID format. #378
Conversation
…ormat. Also performed the migration to the new ID format for backward compatibility.
@rosbo What do you think about using the self_link here as the import id instead? Is that more/less confusing? |
I think having the user type `projects/MY-PROJECT/region/MY-REGION/address/MY-ADDRESS is very confusing for the user because it is different for the import for all the other resources. It also requires more typing. |
Right, but let's say a user wants to import a resource that's not within their provider's default project. Wouldn't they have the same problem as above re: zone? I think we all discussed the idea of using self-link as id here but I can't remember where we landed. Pinging @paddycarver for comments |
All resources are associated with a project. Right now, we don't support import from a project different than the default project. If we change it to support project. I think we should do it in one swoop to avoid having different resources working in different ways. We discussed using the relative part of the
|
Aren't these the same? Can you distinguish between the two during import? |
Yes you can distinguish between the two during import. You just need to write your own import function instead of using a pass through. See: Note: You can call SetId in this function to construct the self-link from the different parts received in the import ID. |
Thanks, I didn't know that! I think that if Id is the self-link, we should allow importing from the self-link as well; naturally the first thing a person will do when checking to see what the id is is look at their state file and copy/paste. Given what you've pasted above, maybe we could support importing fragments of the self link? E.g. if the id has no '/' symbols then use the default provider region/project, if it contains region/foo/address/bar then use the provided region, etc... What do you think? |
Good idea. I will create a generic ID class we can reuse for all the resources. Each resource will instantiate this class by specifying the parts of its id. It will then deal with the various import id format parsing, generating the id and so on. I suggest to do it in a separate PR. 4 import id format can be supported:
|
I added the project to the id for this PR to avoid having to do another id migration. |
make testacc TESTARGS="-run TestAccComputeAddress_" TEST="./google" |
I love the import idea. Just one last thing; the id here is not the self-link (or even a fragment of the self link as it's missing the projects, regions and addresses fragments). Wouldn't it be cleaner to just use the self-link? Customers can already see the self-link in gcloud which would make it easy to copy and paste. |
I had planned to support the 4 cases listed above in a different PRs but finally decided to do it in this one to avoid having to do multiple id migration. (this addresses your last comment about supporting self_link). I will generalize the |
TF_ACC=1 go test ./google -v -run TestAccComputeAddress_ -timeout 120m
=== RUN TestAccComputeAddress_importBasic
--- PASS: TestAccComputeAddress_importBasic (23.62s)
=== RUN TestAccComputeAddress_basic
--- PASS: TestAccComputeAddress_basic (23.54s)
PASS
ok github.com/terraform-providers/terraform-provider-google/google 47.321s
go test -i ./google || exit 1
echo ./google | \
xargs -t -n4 go test -run TestComputeAddressIdParsing -timeout=30s -parallel=4
go test -run TestComputeAddressIdParsing -timeout=30s -parallel=4 ./google
ok github.com/terraform-providers/terraform-provider-google/google 0.122s
/Users/rosbo/go/src/github.com/terraform-providers/terraform-provider-google |
google/resource_compute_address.go
Outdated
|
||
var ( | ||
computeAddressIdTemplate = "projects/%s/regions/%s/addresses/%s" | ||
computeAddressLinkRegex = regexp.MustCompile("projects/(.*)/regions/(.*)/addresses/(.*)$") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor quibble: using .+ is preferred to .* as it excludes a few invalid compute regexes that match (that probably won't ever occur but oh well)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Totally agree, fixed.
google/resource_compute_address.go
Outdated
if err != nil { | ||
return err | ||
} | ||
log.Println("[rosbo] resourceComputeAddressRead", addressId) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops this guy snuck in
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oupps. Removed.
google/resource_compute_address.go
Outdated
Region: parts[0], | ||
Name: parts[1], | ||
}, nil | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing one more case (only specifying name
, which is the current behavior), or was this not included on purpose?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It was on purpose but now that I think about it, I see no good reason for not supporting this case. Support added.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left some minor comments, but it looks great!
I think this will make importing a lot easier 👍
This allows to import address from region and project different than the default project.
This allows to import address from region and project different than the default project.
[Terraform] Gcloud scheduler
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! |
Fixes #374
Also performed the migration to the new ID format for backward compatibility.
@paddycarver We use this PR to discuss also including the project in the import string and the the relative part of the self link (anything right of the version) as the resource id.