-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
compute: added numeric_id
to google_compute_subnetwork
#12285
compute: added numeric_id
to google_compute_subnetwork
#12285
Conversation
Hello! I am a robot. Tests will require approval from a repository maintainer to run. @BBBmau, a repository maintainer, has been assigned to review your changes. If you have not received review feedback within 2 business days, please leave a comment on this PR asking them to take a look. You can help make sure that review is quick by doing a self-review and by running impacted tests locally. |
a5e00b1
to
3312a35
Compare
@@ -100,6 +105,10 @@ func dataSourceGoogleComputeSubnetworkRead(d *schema.ResourceData, meta interfac | |||
return transport_tpg.HandleDataSourceNotFoundError(err, d, fmt.Sprintf("Subnetwork Not Found : %s", name), id) | |||
} | |||
|
|||
if err := d.Set("numeric_id", strconv.Itoa(int(subnetwork.Id))); err != 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.
I am assuming this is pretty reliably an int64
; not sure if this is the right place to do the conversion and / or if any more error checking is needed here, but it seems to work and tests pass.
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.
if we mark numericId as an integer we shouldn't need to do this extra conversion unless there's something that's preventing integer to be used over string
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.
See comment above; as best I could tell, other similar fields (in particular, the one in google_compute_network
that this is based on) are implemented as strings… I could make it a number in terraform if you can confirm that’s the right thing to do, but would be nice to understand why so many of them are already implemented as strings.
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.
Google project number, org ID, etc. also seems to be implemented as strings vs. int
magic-modules/mmv1/third_party/terraform/services/resourcemanager/resource_google_project.go
Line 104 in 8179902
Type: schema.TypeString, |
Hi there, I'm the Modular magician. I've detected the following information about your changes: Diff reportYour PR generated some diffs in downstreams - here they are.
|
Tests analyticsTotal tests: 1061 Click here to see the affected service packages
Action takenFound 1 affected test(s) by replaying old test recordings. Starting RECORDING based on the most recent commit. Click here to see the affected tests
|
@SarahFrench @melinath either of you have any background / perspective on what things should be implemented as strings vs numbers within the provider? |
in general, it should match the API type. I don't know why the other field you mentioned is a string instead. |
So then I guess the question is whether we should follow the other examples within this resource type for consistency, or update it to be a number. I’m happy to do whatever is preferred. I can test, but is there any type conversion needed if one were interpolating the number value within a string in terraform itself? |
the only reason I can think of to use a string would be if a user needed to be able to set "0" on an optional + computed field - but I would still hesitate doing that since it would be a hacky workaround, and this isn't an optional + computed field so that wouldn't apply anyway. I'd say just go with matching the API. |
Added `numeric_id` to `google_compute_subnetwork` resource and data source. Since Terraform uses `id` internally, follow the example of `google_compute_network`, and make `numeric_id` contain the `id` field from the API. Part of hashicorp/terraform-provider-google#20223
293a0a5
to
06cf7a4
Compare
@BBBmau Updated to be an integer. Tests seem to pass, and also functionally tested against the built provider. Might be smart to switch over |
Add `numeric_id` to `google_compute_network` data source, matching the resource. Switch `numeric_id` to to be an integer internally within the `google_compute_network` resource for consistency with the API and with `google_compute_subnetwork`. Followup to GoogleCloudPlatform#12285 Part of hashicorp/terraform-provider-google#20223
Add `numeric_id` to `google_compute_network` data source, matching the resource. Switch `numeric_id` to to be an integer internally within the `google_compute_network` resource for consistency with the API and with `google_compute_subnetwork`. Followup to GoogleCloudPlatform#12285 Part of hashicorp/terraform-provider-google#20223
Created #12339 to update this for the |
Is it expected that the "awaiting approval" labels aren't seeming to get applied / removed? |
{ | ||
Config: testAccComputeSubnetwork_numericId(cnName, subnetworkName), | ||
Check: resource.ComposeTestCheckFunc( | ||
resource.TestMatchResourceAttr("google_compute_subnetwork.numeric_id_test", "numeric_id", regexp.MustCompile("^\\d{16,48}$")), |
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.
There's no builtin check on type here, right? Like to assert that it's an int or that it's a string?
@@ -100,6 +104,10 @@ func dataSourceGoogleComputeSubnetworkRead(d *schema.ResourceData, meta interfac | |||
return transport_tpg.HandleDataSourceNotFoundError(err, d, fmt.Sprintf("Subnetwork Not Found : %s", name), id) | |||
} | |||
|
|||
if err := d.Set("numeric_id", subnetwork.Id); err != 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.
I didn't seem to need to convert from int64
to int
here, even though I did when I was doing string conversion. Let me know if there should be an int(subnetwork.Id)
here.
Hi there, I'm the Modular magician. I've detected the following information about your changes: Diff reportYour PR generated some diffs in downstreams - here they are.
|
Tests analyticsTotal tests: 1065 Click here to see the affected service packages
Action takenFound 1 affected test(s) by replaying old test recordings. Starting RECORDING based on the most recent commit. Click here to see the affected tests
|
🔴 Tests failed during RECORDING mode: 🔴 Errors occurred during RECORDING mode. Please fix them to complete your PR. |
@SarahFrench pointed out https://googlecloudplatform.github.io/magic-modules/develop/field-reference/#api_name in the docs, which might be simpler than the custom templates if it works? I think the test failure is unrelated? |
Maybe not needed after #12351? |
I will look at it again in a week or two. Opened #12339 a bit back for compute_network as well |
Add `numeric_id` to `google_compute_network` data source, matching the resource. Switch `numeric_id` to to be an integer internally within the `google_compute_network` resource for consistency with the API and with `google_compute_subnetwork`. Followup to GoogleCloudPlatform#12285 Part of hashicorp/terraform-provider-google#20223
Added `subnetwork_id` to `google_compute_subnetwork` data source Picked from GoogleCloudPlatform#12285 Followup to GoogleCloudPlatform#12351 Related to hashicorp/terraform-provider-google#20223
@ScottSuarez Thanks. Seems like your changes used I made a followup PR for adding the data source only (basically cherry-picking part of this PR): #12461 Also made hashicorp/terraform-provider-google#20530 to track some of the inconsistencies of name / type that might be breaking changes. |
subnetwork_id
to compute subnet data source
hashicorp/terraform-provider-google#20666
Added
numeric_id
togoogle_compute_subnetwork
resource and data source.Since Terraform uses
id
internally, follow the example ofgoogle_compute_network
, and makenumeric_id
contain theid
field from the API.As mentioned in the issue below, it would be very nice if there were a simpler way to just say "map
id
in the API tonumericId
here", but guessing that's not possible?Part of hashicorp/terraform-provider-google#20223
Release Note Template for Downstream PRs (will be copied)
See Write release notes for guidance.