Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Fix condition in forceNewIfNetworkIPNotUpdatableFunc #11395

Merged
merged 5 commits into from
Aug 14, 2024

Conversation

karolgorc
Copy link
Contributor

@karolgorc karolgorc commented Aug 8, 2024

Resolves issue #16494

This function didn't work before.

d.HasChange will always return true in this condition because of this comparasion on the network field

https://www.googleapis.com/compute/v1/projects/iac-poc-krakow/global/networks/default
against
default

Release Note Template for Downstream PRs (will be copied)

compute: fixed force diff replacement logic for `network_ip` on resource `google_compute_instance`

@github-actions github-actions bot requested a review from ScottSuarez August 8, 2024 10:55
Copy link

github-actions bot commented Aug 8, 2024

Hello! I am a robot. Tests will require approval from a repository maintainer to run.

@ScottSuarez, 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.

@modular-magician modular-magician added the awaiting-approval Pull requests that need reviewer's approval to run presubmit tests label Aug 8, 2024
@ScottSuarez ScottSuarez removed the awaiting-approval Pull requests that need reviewer's approval to run presubmit tests label Aug 12, 2024
Copy link
Contributor

@ScottSuarez ScottSuarez left a comment

Choose a reason for hiding this comment

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

Is there a way to add a testcase for this to validate behavior going forward?

Overall the change makes sense to me.

@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 ( 1 file changed, 2 insertions(+), 1 deletion(-))
google-beta provider: Diff ( 1 file changed, 2 insertions(+), 1 deletion(-))

@modular-magician
Copy link
Collaborator

Tests analytics

Total tests: 979
Passed tests: 906
Skipped tests: 72
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
  • TestAccComputeInstance_subnetworkUpdate

Get to know how VCR tests work

@modular-magician
Copy link
Collaborator

$\textcolor{green}{\textsf{Tests passed during RECORDING mode:}}$
TestAccComputeInstance_subnetworkUpdate[Debug log]

$\textcolor{green}{\textsf{No issues found for passed tests after REPLAYING rerun.}}$


$\textcolor{green}{\textsf{All tests passed!}}$

View the build log or the debug log for each test

@karolgorc
Copy link
Contributor Author

Is there a way to add a testcase for this to validate behavior going forward?

Yup, will add 2 configs that change the network IP and expect a non-empty plan. Because before the terraform apply succeded but this function was never executed causing a change in every terraform plan as shown in the Issue

@github-actions github-actions bot requested a review from ScottSuarez August 13, 2024 07:22
@modular-magician modular-magician added the awaiting-approval Pull requests that need reviewer's approval to run presubmit tests label Aug 13, 2024
@karolgorc
Copy link
Contributor Author

karolgorc commented Aug 13, 2024

--- PASS: TestAccComputeInstance_networkIpUpdate (575.26s)
PASS
ok      github.com/hashicorp/terraform-provider-google/google/services/compute  575.285s

case 1:

  • Create an instance with network_ip 10.3.0.3
  • Check if instance exists and address matches

case 2:

  • Creating an instance with network_ip 10.3.0.4 forces replacement
  • Instance gets replaced
  • Check if instance exists and address matches

case 3:

  • Same as case 2 but uses google_compute_address instead of a hardcoded string value

This would previously fail and produce a non-empty plan before the changes

@modular-magician modular-magician removed the awaiting-approval Pull requests that need reviewer's approval to run presubmit tests label Aug 13, 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 ( 2 files changed, 180 insertions(+), 1 deletion(-))
google-beta provider: Diff ( 2 files changed, 180 insertions(+), 1 deletion(-))

@modular-magician
Copy link
Collaborator

Tests analytics

Total tests: 980
Passed tests: 907
Skipped tests: 72
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
  • TestAccComputeInstance_networkIpUpdate

Get to know how VCR tests work

@modular-magician
Copy link
Collaborator

$\textcolor{green}{\textsf{Tests passed during RECORDING mode:}}$
TestAccComputeInstance_networkIpUpdate[Debug log]

$\textcolor{green}{\textsf{No issues found for passed tests after REPLAYING rerun.}}$


$\textcolor{green}{\textsf{All tests passed!}}$

View the build log or the debug log for each test

@ScottSuarez
Copy link
Contributor

Looks like there are unit test failures.

2024/08/13 16:45:14 [DEBUG] Attributes before migration: map[string]string{"allow.#":"1", "allow.0.ports.#":"4", "allow.0.ports.1693978638":"8080", "allow.0.ports.172152165":"8081", "allow.0.ports.299962681":"7072", "allow.0.ports.3435931483":"4044", "allow.0.protocol":"udp"}
2024/08/13 16:45:14 [DEBUG] Attributes after migration: map[string]string{"allow.#":"1", "allow.0.ports.#":"4", "allow.0.ports.0":"8080", "allow.0.ports.1":"8081", "allow.0.ports.2":"7072", "allow.0.ports.3":"4044", "allow.0.protocol":"udp"}
2024/08/13 16:45:14 [DEBUG] Empty InstanceState; nothing to migrate.
2024/08/13 16:45:14 [DEBUG] Empty InstanceState; nothing to migrate.
2024/08/13 16:45:14 [INFO] Found Compute Instance Group State v1; migrating to v2
2024/08/13 16:45:14 [DEBUG] Attributes before migration: map[string]string{"name":"instancegroup-test", "zone":"us-central1-c"}
2024/08/13 16:45:14 [INFO] Found Compute Instance Group State v0; migrating to v1
2024/08/13 16:45:14 [DEBUG] Attributes before migration: map[string]string{"instances.#":"1", "instances.0":"https://www.googleapis.com/compute/v1/projects/project_name/zones/zone_name/instances/instancegroup-test-1", "instances.1":"https://www.googleapis.com/compute/v1/projects/project_name/zones/zone_name/instances/instancegroup-test-0", "name":"instancegroup-test", "zone":"us-central1-c"}
2024/08/13 16:45:14 [DEBUG] Attributes after migration: map[string]string{"instances.#":"1", "instances.1519187872":"https://www.googleapis.com/compute/v1/projects/project_name/zones/zone_name/instances/instancegroup-test-0", "instances.7[64](https://github.com/GoogleCloudPlatform/magic-modules/actions/runs/10373770092/job/28719655211?pr=11395#step:8:65)135222":"https://www.googleapis.com/compute/v1/projects/project_name/zones/zone_name/instances/instancegroup-test-1", "name":"instancegroup-test", "zone":"us-central1-c"}
2024/08/13 16:45:14 [INFO] Found Compute Instance Group State v1; migrating to v2
2024/08/13 16:45:14 [DEBUG] Attributes before migration: map[string]string{"instances.#":"1", "instances.1519187872":"https://www.googleapis.com/compute/v1/projects/project_name/zones/zone_name/instances/instancegroup-test-0", "instances.764135222":"https://www.googleapis.com/compute/v1/projects/project_name/zones/zone_name/instances/instancegroup-test-1", "name":"instancegroup-test", "zone":"us-central1-c"}
2024/08/13 16:45:14 [DEBUG] Empty InstanceState; nothing to migrate.
2024/08/13 16:45:14 [DEBUG] Empty InstanceState; nothing to migrate.
2024/08/13 16:45:14 [DEBUG] Empty InstanceState; nothing to migrate.
2024/08/13 16:45:14 [DEBUG] Empty InstanceState; nothing to migrate.
2024/08/13 16:45:14 [INFO] Found Compute Instance Template State v0; migrating to v1
2024/08/13 16:45:14 [DEBUG] Attributes before migration: map[string]string{"automatic_restart":"true", "scheduling.#":"0"}
2024/08/13 16:45:14 [DEBUG] Attributes after migration: map[string]string{"scheduling.#":"1", "scheduling.0.automatic_restart":"true"}
2024/08/13 16:45:14 [INFO] Found Compute Instance Template State v0; migrating to v1
2024/08/13 16:45:14 [DEBUG] Attributes before migration: map[string]string{"automatic_restart":"true", "scheduling.#":"2", "scheduling.0.automatic_restart":"true", "scheduling.1.automatic_restart":"true"}
2024/08/13 16:45:14 [INFO] Found Compute Instance Template State v0; migrating to v1
2024/08/13 16:45:14 [DEBUG] Attributes before migration: map[string]string{"automatic_restart":"true", "scheduling.#":"1", "scheduling.0.automatic_restart":"false"}
2024/08/13 16:45:14 [INFO] Found Compute Instance Template State v0; migrating to v1
2024/08/13 16:45:14 [DEBUG] Attributes before migration: map[string]string{"automatic_restart":"true", "scheduling.#":"1", "scheduling.0.automatic_restart":"true"}
2024/08/13 16:45:14 [DEBUG] Attributes after migration: map[string]string{"scheduling.#":"1", "scheduling.0.automatic_restart":"true"}
2024/08/13 16:45:14 [INFO] Found Compute Instance Template State v0; migrating to v1
2024/08/13 16:45:14 [DEBUG] Attributes before migration: map[string]string{"automatic_restart":"true", "on_host_maintenance":"MIGRATE", "scheduling.#":"1", "scheduling.0.automatic_restart":"true"}
2024/08/13 16:45:14 [DEBUG] Attributes after migration: map[string]string{"scheduling.#":"1", "scheduling.0.automatic_restart":"true"}
2024/08/13 16:45:14 [INFO] Found Compute Instance Template State v0; migrating to v1
2024/08/13 16:45:14 [DEBUG] Attributes before migration: map[string]string{"automatic_restart":"true"}
2024/08/13 16:45:14 [DEBUG] Attributes after migration: map[string]string{"scheduling.#":"1", "scheduling.0.automatic_restart":"true"}
2024/08/13 16:45:14 [DEBUG] Empty InstanceState; nothing to migrate.
2024/08/13 16:45:14 [DEBUG] Empty InstanceState; nothing to migrate.
--- FAIL: TestComputeInstance_networkIPCustomizedDiff (0.00s)
    resource_compute_instance_internal_test.go:134: NetworkIP and Subnetwork change: expected d.IsForceNew to be false, but was true
    resource_compute_instance_internal_test.go:134: NetworkIP and SubnetworkProject change: expected d.IsForceNew to be false, but was true
FAIL

TestComputeInstance_networkIPCustomizedDiff

@karolgorc
Copy link
Contributor Author

--- PASS: TestComputeInstance_networkIPCustomizedDiff (0.00s)
PASS
ok      github.com/hashicorp/terraform-provider-google/google/services/compute   0.035s

Failed due to the OR statement that i added just in case. This is more restrictive and passing the unit test

@modular-magician modular-magician added awaiting-approval Pull requests that need reviewer's approval to run presubmit tests and removed awaiting-approval Pull requests that need reviewer's approval to run presubmit tests labels Aug 14, 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 ( 2 files changed, 181 insertions(+), 1 deletion(-))
google-beta provider: Diff ( 2 files changed, 181 insertions(+), 1 deletion(-))

@modular-magician
Copy link
Collaborator

Tests analytics

Total tests: 981
Passed tests: 908
Skipped tests: 72
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
  • TestAccComputeInstance_subnetworkUpdate

Get to know how VCR tests work

@modular-magician
Copy link
Collaborator

$\textcolor{green}{\textsf{Tests passed during RECORDING mode:}}$
TestAccComputeInstance_subnetworkUpdate[Debug log]

$\textcolor{green}{\textsf{No issues found for passed tests after REPLAYING rerun.}}$


$\textcolor{green}{\textsf{All tests passed!}}$

View the build log or the debug log for each test

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

Successfully merging this pull request may close these issues.

google_compute_instance update network_interface.network_ip with google_compute_address
3 participants