Skip to content

google_sql_user: Fixed import where host is an IPv4 CIDR #11523

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

Merged

Conversation

rickard-von-essen
Copy link
Contributor

@rickard-von-essen rickard-von-essen commented Aug 22, 2024

Previously it was not possible to import CloudSQL users for MySQL with host set to an IPv4 CIDR. The parsing of ID failed if host was a CIDR since it expected it to be on the form {project}/{instance}/{host}/{name} and an error was returned if there where more than three slashes in the ID.

With this fix if there are four slashes in the ID the third is considered part of the host argument.

sql: fixed importing `google_sql_user` where `host` is an IPv4 CIDR

Acceptance test run:

$ make testacc TEST=./google/services/sql TESTARGS='-run=TestAccSqlUser_mysql' 
TF_ACC=1 TF_SCHEMA_PANIC_ON_ERROR=1 go test ./google/services/sql -v -run=TestAccSqlUser_mysql -timeout 240m -ldflags="-X=github.com/hashicorp/terraform-provider-google/version.ProviderVersion=acc"
=== RUN   TestAccSqlUser_mysql
=== PAUSE TestAccSqlUser_mysql
=== RUN   TestAccSqlUser_mysqlPasswordPolicy
=== PAUSE TestAccSqlUser_mysqlPasswordPolicy
=== CONT  TestAccSqlUser_mysql
=== CONT  TestAccSqlUser_mysqlPasswordPolicy
--- PASS: TestAccSqlUser_mysql (770.89s)
--- PASS: TestAccSqlUser_mysqlPasswordPolicy (950.89s)
PASS
ok      github.com/hashicorp/terraform-provider-google/google/services/sql      952.219s

Previously a import would fail with the message shown bellow. After the change this import succeeds with host set to 10.0.0.0/24.

$ terraform import google_sql_user.admin my-project/my-instance/10.0.0.0/24/admin 
[...]
        Error: Invalid specifier. Expecting {project}/{instance}/{name} for postgres instance and {project}/{instance}/{host}/{name} for MySQL instance

Previously it was not possible to import CloudSQL users for MySQL with
host set to an IPv4 CIDR. The parsing of ID failed if host was a CIDR
since it expected it to be on the form {project}/{instance}/{host}/{name}
and an error was returned if there where more than three slashes in the
ID.

With this fix if there are four slashes in the ID the third is considered
part of the host argument.
@rickard-von-essen rickard-von-essen changed the title google_sql_user: Fixed import where host is a IPv4 CIDR google_sql_user: Fixed import where host is an IPv4 CIDR Aug 22, 2024
@github-actions github-actions bot requested a review from zli82016 August 22, 2024 07:07
Copy link

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

@zli82016, 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 22, 2024
@zli82016
Copy link
Member

/gcbrun

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

@modular-magician
Copy link
Collaborator

Tests analytics

Total tests: 96
Passed tests: 82
Skipped tests: 14
Affected tests: 0

Click here to see the affected service packages
  • sql

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

View the build log

@rickard-von-essen
Copy link
Contributor Author

terraform-google-conversion-build-and-unit-tests seems to fail in these test:

TestReadPlannedAssetsCoverage
TestReadPlannedAssetsCoverage/example_bigquery_dataset_iam_binding
TestReadPlannedAssetsCoverage/example_google_datastream_stream
TestReadPlannedAssetsCoverage/example_google_datastream_connection_profile
TestReadPlannedAssetsCoverage/example_google_datastream_private_connection
TestReadPlannedAssetsCoverage/example_gke_hub_feature
TestReadPlannedAssetsCoverage/example_filestore_instance
TestReadPlannedAssetsCoverage/example_dns_managed_zone
TestReadPlannedAssetsCoverage/example_compute_vpn_tunnel
TestReadPlannedAssetsCoverage/example_compute_snapshot
TestReadPlannedAssetsCoverage/full_sql_database_instance
TestReadPlannedAssetsCoverage/full_spanner_instance
TestReadPlannedAssetsCoverage/example_vertex_ai_dataset
TestReadPlannedAssetsCoverage/example_spanner_instance_iam_policy
TestReadPlannedAssetsCoverage/example_spanner_instance_iam_member
TestReadPlannedAssetsCoverage/example_spanner_instance_iam_binding
TestReadPlannedAssetsCoverage/example_spanner_database_iam_policy
TestReadPlannedAssetsCoverage/example_spanner_database_iam_member
TestReadPlannedAssetsCoverage/example_spanner_database_iam_binding
TestReadPlannedAssetsCoverage/example_spanner_database
TestReadPlannedAssetsCoverage/example_redis_instance
TestReadPlannedAssetsCoverage/example_pubsub_topic
TestReadPlannedAssetsCoverage/example_pubsub_subscription_iam_policy
TestReadPlannedAssetsCoverage/example_pubsub_subscription_iam_binding
TestReadPlannedAssetsCoverage/example_pubsub_subscription_iam_member
TestReadPlannedAssetsCoverage/example_pubsub_subscription
TestReadPlannedAssetsCoverage/example_bigquery_dataset
TestReadPlannedAssetsCoverage/example_artifact_registry_repository
TestReadPlannedAssetsCoverage/example_alloydb_instance
TestReadPlannedAssetsCoverage/disk
TestReadPlannedAssetsCoverage/example_compute_global_address
TestReadPlannedAssetsCoverage/example_compute_disk
TestReadPlannedAssetsCoverage/example_compute_disk_empty_image
TestReadPlannedAssetsCoverage/example_compute_address
TestReadPlannedAssetsCoverage/example_cloud_run_v2_job
TestReadPlannedAssetsCoverage/example_cloud_run_service
TestReadPlannedAssetsCoverage/example_cloud_run_mapping
TestReadPlannedAssetsCoverage/example_bigquery_dataset_iam_policy
TestReadPlannedAssetsCoverage/example_bigquery_dataset_iam_policy_empty_policy_data
TestReadPlannedAssetsCoverage/example_bigquery_dataset_iam_member
TestReadPlannedAssetsCoverage/example_kms_crypto_key
TestReadPlannedAssetsCoverage/example_kms_crypto_key_iam_policy
TestReadPlannedAssetsCoverage/example_kms_crypto_key_iam_member
TestReadPlannedAssetsCoverage/example_kms_crypto_key_iam_binding
TestReadPlannedAssetsCoverage/example_google_gke_hub_membership
TestReadPlannedAssetsCoverage/example_google_datastream_stream_append_only

Because of an unexpected goog-terraform-provisioned label. 🤔
Seems to unrelated to my change.

Copy link
Member

@zli82016 zli82016 left a comment

Choose a reason for hiding this comment

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

LGTM. Thanks.

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