-
Notifications
You must be signed in to change notification settings - Fork 568
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
fix: create random suffix resource on demand #185
fix: create random suffix resource on demand #185
Conversation
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
@Tensho |
Could we have this merged please? |
@Tensho thank you for this PR - I'm looking forward to use it after the merge.
|
@tpolekhin I'm glad someone else is interested in this small change. I'm not sure that's necessary – |
@Tensho yes, sorry for not being more clear on that.
I want to create bucket conditionally and I want it to have a randomised suffix if we do create it
This will prevent the creation of the |
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.
Thanks for the PR @Tensho and apologies for the late reply. Just a question if there is any regression with this change.
examples/multiple_buckets/main.tf
Outdated
matches_storage_class = "MULTI_REGIONAL,STANDARD,DURABLE_REDUCED_AVAILABILITY" | ||
} | ||
}] | ||
# FIXME: This doesn't work: |
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 not sure why this would happen with the proposed code change in the module? Did this happen for you locally?
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 just wanted to flag the current example didn't work for me, hence I changed it. If you're fine with the proposed example I'm happy to drop the comment.
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.
Hi @Tensho - The INT tests also include assertions for the example which need to match: https://github.com/terraform-google-modules/terraform-google-cloud-storage/blob/master/test/integration/multiple_buckets/multiple_buckets_test.go#L56
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.
Fair enough, I'll make adjustments.
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.
@apeabody The test passes now:
[root@bb37621fcfea workspace]# cft test run all
ok github.com/terraform-google-modules/terraform-google-cloud-storage/test/integration 65.892s
ok github.com/terraform-google-modules/terraform-google-cloud-storage/test/integration/multiple_buckets 92.755s
@bharathkkb There is no regression. |
This PR is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 7 days |
Thanks for the contribution @Tensho! Can you please resolve the conflicts so I can trigger the INT tests. |
d11d7aa
to
89a7ac7
Compare
@apeabody Done |
/gcbrun |
/gcbrun |
Thanks @Tensho - From the LINT:
|
abf5d93
to
150cbb7
Compare
@apeabody Fixed. |
/gcbrun |
Error: Invalid index
150cbb7
to
ae55809
Compare
/gcbrun |
This PR is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 7 days |
@apeabody Hey 👋 Could we have some traction here please? 🙂 |
/gcbrun |
Pre-Req: #257 |
/gcbrun |
/gcbrun |
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.
Thanks for the contribution @Tensho!
It looks like this will be a breaking change for existing users, can you include how to migrate (details in the note below) called docs/upgrading_to_v4.0.md
similar to https://github.com/terraform-google-modules/terraform-google-cloud-storage/blob/master/docs/upgrading_to_v4.0.md
Alternatively the minimum terraform
version could be bumped (v1.1) to use https://developer.hashicorp.com/terraform/tutorials/configuration-language/move-config#move-your-resources-with-the-moved-configuration-block
byte_length = 2 | ||
} | ||
|
||
locals { | ||
suffix = var.randomize_suffix ? random_id.bucket_suffix.hex : "" | ||
suffix = var.randomize_suffix ? random_id.bucket_suffix[0].hex : "" |
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.
FYI: This will be a breaking change for existing users. Probably can use something like terraform state mv 'random_id.bucket_suffix.hex' 'random_id.bucket_suffix[0].hex'
to migrate the existing suffix to the new resource location.
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 specified it in the PR description "Note" section – it won't be a breaking change. Terraform implicitly modifies the state. Try to run the following experiment:
-
Draft a simple configuration without
count
and apply it:resource "random_id" "x" { byte_length = 1 }
$ terraform apply -auto-approve Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols: + create Terraform will perform the following actions: # random_id.x will be created + resource "random_id" "x" { + b64_std = (known after apply) + b64_url = (known after apply) + byte_length = 1 + dec = (known after apply) + hex = (known after apply) + id = (known after apply) } Plan: 1 to add, 0 to change, 0 to destroy. random_id.x: Creating... random_id.x: Creation complete after 0s [id=wA] Apply complete! Resources: 1 added, 0 changed, 0 destroyed.
-
Modify resource with
count
and apply it:resource "random_id" "x" { count = 1 byte_length = 1 }
$ terraform apply -auto-approve random_id.x[0]: Refreshing state... [id=wA] Terraform will perform the following actions: # random_id.x has moved to random_id.x[0] resource "random_id" "x" { id = "wA" # (5 unchanged attributes hidden) } Plan: 0 to add, 0 to change, 0 to destroy. Apply complete! Resources: 0 added, 0 changed, 0 destroyed.
Pay attention resource has been moved, no replacement happened.
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.
Thanks for explanation @Tensho!
I just confirmed this worked on TF 0.13 (https://github.com/terraform-google-modules/terraform-google-cloud-storage/blob/master/versions.tf#L18), although the messaging is not as clear:
./terraform apply
random_id.x[0]: Refreshing state... [id=9w]
Apply complete! Resources: 0 added, 0 changed, 0 destroyed.
/gcbrun |
There is no need to create
random_id.bucket_suffix
resource if user doesn't enable bucket suffix viarandomize_suffix
input variable.Before
randomize_suffix
is disabled.randomize_suffix
is enabled.After
randomize_suffix
is disabled.randomize_suffix
is enabled.Note
Resource moves to new location implicitly by Terraform: