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

compute: added numeric_id to google_compute_subnetwork #12285

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

wyardley
Copy link
Contributor

@wyardley wyardley commented Nov 8, 2024

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.

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 to numericId 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.

compute: added `numeric_id` to `google_compute_subnetwork` resource and data source

Copy link

github-actions bot commented Nov 8, 2024

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.

@github-actions github-actions bot requested a review from BBBmau November 8, 2024 17:32
@modular-magician modular-magician added the awaiting-approval Pull requests that needs reviewer's approval to run presubmit tests label Nov 8, 2024
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
@@ -73,6 +73,9 @@ iam_policy:
custom_code:
extra_schema_entry: 'templates/terraform/extra_schema_entry/subnetwork.tmpl'
constants: 'templates/terraform/constants/subnetwork.tmpl'
decoder: 'templates/terraform/decoders/compute_subnetwork.go.tmpl'
encoder: 'templates/terraform/encoders/compute_subnetwork.go.tmpl'
update_encoder: 'templates/terraform/update_encoder/compute_subnetwork.go.tmpl'
Copy link
Contributor Author

Choose a reason for hiding this comment

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

these are all identical to the ones for compute_network; I'm assuming there's still a preference to have these be copied / pasted vs. sharing a common file with a more generic name?

@@ -203,6 +206,10 @@ properties:
custom_expand: 'templates/terraform/custom_expand/resourceref_with_validation.go.tmpl'
resource: 'Network'
imports: 'selfLink'
- name: 'numericId'
type: String
Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's an integer in the API, but followed the example from google_compute_network of making it a string, so I assume that's preferred?

@@ -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 {
Copy link
Contributor Author

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.

Copy link
Collaborator

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

Copy link
Contributor Author

@wyardley wyardley Nov 12, 2024

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.

Copy link
Contributor Author

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

@modular-magician modular-magician added service/compute-vpc and removed awaiting-approval Pull requests that needs reviewer's approval to run presubmit tests labels Nov 8, 2024
@modular-magician
Copy link
Collaborator

Hi there, I'm the Modular magician. I've detected the following information about your changes:

Diff report

Your PR generated some diffs in downstreams - here they are.

google provider: Diff ( 6 files changed, 137 insertions(+))
google-beta provider: Diff ( 6 files changed, 137 insertions(+))
terraform-google-conversion: Diff ( 1 file changed, 5 insertions(+))

@modular-magician
Copy link
Collaborator

Tests analytics

Total tests: 1061
Passed tests: 987
Skipped tests: 73
Affected tests: 1

Click here to see the affected service packages
  • compute

Action taken

Found 1 affected test(s) by replaying old test recordings. Starting RECORDING based on the most recent commit. Click here to see the affected tests
  • TestAccComputeSubnetwork_numericId

Get to know how VCR tests work

@modular-magician
Copy link
Collaborator

🟢 Tests passed during RECORDING mode:
TestAccComputeSubnetwork_numericId [Debug log]

🟢 No issues found for passed tests after REPLAYING rerun.


🟢 All tests passed!

View the build log or the debug log for each test

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants