Skip to content

Conversation

@apeabody
Copy link
Contributor

@apeabody apeabody commented Apr 16, 2025

Description

Fixes b/401371689

  • add hcledit step for tf resource fixup
  • migrate deletion_protection = false for non-quickstart google_container_cluster.default

Checklist

Readiness

  • Yes, merge this PR after it is approved
  • No, don't merge this PR after it is approved

Style

Testing

Intended location

  • Yes, this sample will be (or already is) included on cloud.google.com
    Location(s):

  • No, this sample won't be included on cloud.google.com
    Reason:

API enablement

  • If the sample needs an API enabled to pass testing, I have added the service to the Test setup file

Review

  • If this sample adds a new directory, I have added codeowners to the CODEOWNERS file

@apeabody apeabody force-pushed the ap/hcledit branch 3 times, most recently from fc3e307 to f63322f Compare April 16, 2025 00:20
@apeabody apeabody force-pushed the ap/hcledit branch 4 times, most recently from a3c8b80 to c22a1cd Compare April 16, 2025 17:03
@apeabody apeabody marked this pull request as ready for review April 16, 2025 17:08
@apeabody apeabody requested review from a team as code owners April 16, 2025 17:08
@apeabody apeabody requested a review from glasnt April 16, 2025 17:25
go install github.com/minamijoyo/[email protected]
# Add `deletion_protection = false` to google_container_cluste.default resources
find . -name "*.tf" -print | xargs -t -I {} $$GOPATH/bin/hcledit attribute append resource.google_container_cluster.default.deletion_protection 'false' -u -f {} || true
Copy link
Contributor

Choose a reason for hiding this comment

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

This outputs the command for every tf file in the repo. For this resource, is it more useful to stick to gke/? Could it also report what was changed?

After this change is merged, it would also be useful to add this for google_sql_database_instance, so in it's current form, there would be a lot of log noise if this line is copied for other settings.

Copy link
Contributor

Choose a reason for hiding this comment

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

Also: this will not affect the resources in gke/standard/zonal/no-channel-to-release-channel/main.tf (multiple instances declared with custom names),
gke/standard/regional/binary-authorization/main.tf or
gke/standard/regional/ray/main.tf (they should use 'default', but don't.)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

gke/

Yes, I've rescoped it to ./gke. Currently the only option appears to log if it doesn't succeed (for example the attribute is already defined).

google_sql_database_instance

Yup, we should just need to add a line similar to #76 for google_sql_database_instance

this will not affect the resources in

Correct, I noticed some google_container_cluster are using non-standard names and will address in a follow-up PR as I need to validate options to address (particularly the multiple instances examples). Unfortunately hcledit doesn't support wildcard for resource names.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Here is the updated behavior with example of 2 "error":

Step #1 - "resource specific fixups": /go/bin/hcledit attribute append resource.google_container_cluster.default.deletion_protection false -u -f ./gke/quickstart/multitenant/main.tf
Step #1 - "resource specific fixups": attribute already exists: resource.google_container_cluster.default.deletion_protection
Step #1 - "resource specific fixups": /go/bin/hcledit attribute append resource.google_container_cluster.default.deletion_protection false -u -f ./gke/quickstart/autopilot/cluster.tf
Step #1 - "resource specific fixups": attribute already exists: resource.google_container_cluster.default.deletion_protection
Step #1 - "resource specific fixups": /go/bin/hcledit attribute append resource.google_container_cluster.default.deletion_protection false -u -f ./gke/quickstart/autopilot/app.tf
Step #1 - "resource specific fixups": /go/bin/hcledit attribute append resource.google_container_cluster.default.deletion_protection false -u -f ./gke/enterprise/mesh/main.tf
Step #1 - "resource specific fixups": /go/bin/hcledit attribute append resource.google_container_cluster.default.deletion_protection false -u -f ./gke/enterprise/policycontroller/main.tf
Step #1 - "resource specific fixups": /go/bin/hcledit attribute append resource.google_container_cluster.default.deletion_protection false -u -f ./gke/enterprise/config_sync/git/main.tf
Step #1 - "resource specific fixups": /go/bin/hcledit attribute append resource.google_container_cluster.default.deletion_protection false -u -f ./gke/enterprise/config_sync/oci/main.tf
Step #1 - "resource specific fixups": /go/bin/hcledit attribute append resource.google_container_cluster.default.deletion_protection false -u -f ./gke/enterprise/enable/main.tf
Step #1 - "resource specific fixups": /go/bin/hcledit attribute append resource.google_container_cluster.default.deletion_protection false -u -f ./gke/autopilot/mesh/main.tf
Step #1 - "resource specific fixups": /go/bin/hcledit attribute append resource.google_container_cluster.default.deletion_protection false -u -f ./gke/autopilot/labels/main.tf
Step #1 - "resource specific fixups": /go/bin/hcledit attribute append resource.google_container_cluster.default.deletion_protection false -u -f ./gke/autopilot/policycontroller/main.tf
Step #1 - "resource specific fixups": /go/bin/hcledit attribute append resource.google_container_cluster.default.deletion_protection false -u -f ./gke/autopilot/iap/main.tf
Step #1 - "resource specific fixups": /go/bin/hcledit attribute append resource.google_container_cluster.default.deletion_protection false -u -f ./gke/autopilot/basic/main.tf
Step #1 - "resource specific fixups": /go/bin/hcledit attribute append resource.google_container_cluster.default.deletion_protection false -u -f ./gke/autopilot/release_channel/main.tf
Step #1 - "resource specific fixups": /go/bin/hcledit attribute append resource.google_container_cluster.default.deletion_protection false -u -f ./gke/autopilot/reservation/main.tf
Step #1 - "resource specific fixups": /go/bin/hcledit attribute append resource.google_container_cluster.default.deletion_protection false -u -f ./gke/autopilot/config_sync/git/main.tf
Step #1 - "resource specific fixups": /go/bin/hcledit attribute append resource.google_container_cluster.default.deletion_protection false -u -f ./gke/autopilot/config_sync/oci/main.tf
Step #1 - "resource specific fixups": /go/bin/hcledit attribute append resource.google_container_cluster.default.deletion_protection false -u -f ./gke/autopilot/tag/main.tf
Step #1 - "resource specific fixups": /go/bin/hcledit attribute append resource.google_container_cluster.default.deletion_protection false -u -f ./gke/standard/zonal/node_image/main.tf
Step #1 - "resource specific fixups": /go/bin/hcledit attribute append resource.google_container_cluster.default.deletion_protection false -u -f ./gke/standard/zonal/secondary-boot-disk/main.tf
Step #1 - "resource specific fixups": /go/bin/hcledit attribute append resource.google_container_cluster.default.deletion_protection false -u -f ./gke/standard/zonal/gpu/main.tf
Step #1 - "resource specific fixups": /go/bin/hcledit attribute append resource.google_container_cluster.default.deletion_protection false -u -f ./gke/standard/zonal/arm/main.tf
Step #1 - "resource specific fixups": /go/bin/hcledit attribute append resource.google_container_cluster.default.deletion_protection false -u -f ./gke/standard/zonal/single-zone/main.tf
Step #1 - "resource specific fixups": /go/bin/hcledit attribute append resource.google_container_cluster.default.deletion_protection false -u -f ./gke/standard/zonal/multi-zone/main.tf
Step #1 - "resource specific fixups": /go/bin/hcledit attribute append resource.google_container_cluster.default.deletion_protection false -u -f ./gke/standard/zonal/no-channel-to-release-channel/main.tf
Step #1 - "resource specific fixups": /go/bin/hcledit attribute append resource.google_container_cluster.default.deletion_protection false -u -f ./gke/standard/zonal/reservation/main.tf
Step #1 - "resource specific fixups": /go/bin/hcledit attribute append resource.google_container_cluster.default.deletion_protection false -u -f ./gke/standard/regional/node_pool/main.tf
Step #1 - "resource specific fixups": /go/bin/hcledit attribute append resource.google_container_cluster.default.deletion_protection false -u -f ./gke/standard/regional/hpa-logs/main.tf
Step #1 - "resource specific fixups": /go/bin/hcledit attribute append resource.google_container_cluster.default.deletion_protection false -u -f ./gke/standard/regional/ray/main.tf
Step #1 - "resource specific fixups": /go/bin/hcledit attribute append resource.google_container_cluster.default.deletion_protection false -u -f ./gke/standard/regional/labels/main.tf
Step #1 - "resource specific fixups": /go/bin/hcledit attribute append resource.google_container_cluster.default.deletion_protection false -u -f ./gke/standard/regional/node_system_config/main.tf
Step #1 - "resource specific fixups": /go/bin/hcledit attribute append resource.google_container_cluster.default.deletion_protection false -u -f ./gke/standard/regional/gemma-tgi/main.tf
Step #1 - "resource specific fixups": /go/bin/hcledit attribute append resource.google_container_cluster.default.deletion_protection false -u -f ./gke/standard/regional/single-zone/main.tf
Step #1 - "resource specific fixups": /go/bin/hcledit attribute append resource.google_container_cluster.default.deletion_protection false -u -f ./gke/standard/regional/windows/main.tf
Step #1 - "resource specific fixups": /go/bin/hcledit attribute append resource.google_container_cluster.default.deletion_protection false -u -f ./gke/standard/regional/loadbalancer/main.tf
Step #1 - "resource specific fixups": /go/bin/hcledit attribute append resource.google_container_cluster.default.deletion_protection false -u -f ./gke/standard/regional/binary-authorization/main.tf
Step #1 - "resource specific fixups": /go/bin/hcledit attribute append resource.google_container_cluster.default.deletion_protection false -u -f ./gke/standard/regional/multi-zone/main.tf

Copy link
Contributor

@glasnt glasnt left a comment

Choose a reason for hiding this comment

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

Approval, comments can be addressed in future PRs to unblock

@apeabody apeabody merged commit 221b7e6 into main Apr 17, 2025
8 of 9 checks passed
@apeabody apeabody deleted the ap/hcledit branch April 17, 2025 23:18
niharika-98 pushed a commit to niharika-98/terraform-docs-samples that referenced this pull request Sep 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants