-
Notifications
You must be signed in to change notification settings - Fork 104
feat!: Restricting autokey module to autokey configuration use case #163
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
bharathkkb
merged 39 commits into
terraform-google-modules:master
from
nb-goog:setup-only
Dec 31, 2024
Merged
Changes from all commits
Commits
Show all changes
39 commits
Select commit
Hold shift + click to select a range
852ac5a
Enabling autokey config setup in autokey submodule
nb-goog db065d1
updated comments
nb-goog 9ea551a
fmt change
nb-goog 4444348
fmt
nb-goog d96d2de
updating readme.md
nb-goog af032d9
fmt change
nb-goog fb4bd33
addressing review comments
nb-goog 19e7be4
fmt
nb-goog 6de0c29
correcting tests
nb-goog 74789db
fmt
nb-goog a220f62
renaming dir and updating test
nb-goog 1174f5a
compile time error resolution
nb-goog d63ea27
fmt
nb-goog 98715b3
correcting the test
nb-goog 9adbeca
correcting import key exa
nb-goog 0076c7a
correcting variables
nb-goog f328806
package name change
nb-goog ed731b9
fmt
nb-goog f0853bc
Merge branch 'master' into setup-only
nb-goog 7fc4a22
integrate test for bucket keyhandle
nb-goog 463052e
correcting autokey setup test
nb-goog fd4e5e1
fmt
nb-goog 3991e02
documentation
nb-goog 8d4b928
Removing redundant variable kms_project_id from setup
nb-goog 985eb3f
fmt
nb-goog c6a05cd
removing script and guidance file for migrating terraform-google-auto…
nb-goog c866361
correcting test
nb-goog 74ff65f
Documentation and version change
nb-goog 5f8b0aa
reverting autokey module reference to dir based in examples
nb-goog c478e59
restoring module path
nb-goog 1e225e5
adding version
nb-goog 6569373
fmt
nb-goog 6546bcc
renaming autokey_kms_project_id to key_project_id
nb-goog f2f1f5a
renaming kms_project_id to key_project_id
nb-goog d80f643
fmt
nb-goog 88dbadb
adding process to reimport the autokey config
nb-goog 1c1e42c
fmt
nb-goog 0124e61
addressing comments
nb-goog 4e2b03a
Update docs/upgrading_to_v4.0.md
bharathkkb File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Upgrading to v4.0 | ||
The v4.0 release of *kms* is a backwards incompatible release. | ||
|
||
### Autokey Submodule | ||
The current users of Autokey submodules needs to | ||
- Switch `project_id` to `key_project_id` | ||
- Stop using `autokey_handles` field to generate keyhandles, instead directly use `google_kms_key_handle` terraform resource to create keyhandles. For detailed example check [bucket_setup_using_autokey](../examples/bucket_setup_using_autokey/). | ||
|
||
|
||
### To Migrate from v3.0 to v4.0 | ||
Using V3.0 of Autokey modules if you have created keyhandles and wants to use them with V4.0 version then they need to be imported using below steps | ||
|
||
1. Retrieve the keyhandles created: | ||
- Run `terraform state list module.autokey.google_kms_key_handle.primary` to list all keyhandles created using v3.0 | ||
- For each item in the output of above CLI, run `terraform state show 'module.autokey.google_kms_key_handle.primary["<an id from the output of list>"]'` and copy the resulting `id` field from the cli output to notepad | ||
2. Delete all keyhandles from the state: run `terraform state rm module.autokey.google_kms_key_handle.primary` | ||
3. Update the main root module to use V4.0 version. Add the keyhandle config definition to the main root module for all the keyhandle found in step1. | ||
4. Import all the keyhandles configs using id copied in setp1 to the terraform state | ||
- for each keyhandle id found in step1, Run `terraform import resource.google_kms_key_handle.<key_handle_name_given_in_step3> "<paste corresponding keyhandle id copied in step 1>"` | ||
|
||
|
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# Autokey Example | ||
|
||
This example illustrates how to setup the `autokey` kms submodule for [KMS Autokey](https://cloud.google.com/kms/docs/autokey-overview) feature. | ||
|
||
<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK --> | ||
## Inputs | ||
|
||
| Name | Description | Type | Default | Required | | ||
|------|-------------|------|---------|:--------:| | ||
| folder\_id | The ID of the folder for which to configure and enable Autokey feature. | `string` | n/a | yes | | ||
| key\_project\_id | The ID of the project in which KMS keyring and KMS keys will be provisioned by autokey. | `string` | n/a | yes | | ||
|
||
## Outputs | ||
|
||
| Name | Description | | ||
|------|-------------| | ||
| autokey\_config\_id | An Autokey configuration identifier. | | ||
| key\_project\_id | The ID of the project in which kms keyring and kms keys will be provisioned by autokey. | | ||
|
||
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK --> | ||
|
||
To provision this example, run the following from within this directory: | ||
- `terraform init` to get the plugins | ||
- `terraform plan` to see the infrastructure plan | ||
- `terraform apply` to apply the infrastructure build | ||
- `terraform destroy` to destroy the built infrastructure |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/** | ||
* Copyright 2024 Google LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
module "autokey" { | ||
source = "terraform-google-modules/kms/google//modules/autokey" | ||
version = "~> 4.0" | ||
|
||
key_project_id = var.key_project_id | ||
autokey_folder_number = var.folder_id | ||
} | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/** | ||
* Copyright 2024 Google LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
output "autokey_config_id" { | ||
description = "An Autokey configuration identifier." | ||
value = module.autokey.autokey_config_id | ||
} | ||
|
||
output "key_project_id" { | ||
description = "The ID of the project in which kms keyring and kms keys will be provisioned by autokey." | ||
value = var.key_project_id | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/** | ||
* Copyright 2024 Google LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
variable "key_project_id" { | ||
description = "The ID of the project in which KMS keyring and KMS keys will be provisioned by autokey." | ||
type = string | ||
} | ||
|
||
variable "folder_id" { | ||
type = string | ||
description = "The ID of the folder for which to configure and enable Autokey feature." | ||
} | ||
|
14 changes: 7 additions & 7 deletions
14
examples/autokey_example/README.md → ...ples/bucket_setup_using_autokey/README.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/** | ||
* Copyright 2024 Google LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
nb-goog marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
module "autokey" { | ||
source = "terraform-google-modules/kms/google//modules/autokey" | ||
version = "~> 4.0" | ||
|
||
key_project_id = var.key_project_id | ||
autokey_folder_number = var.folder_id | ||
} | ||
|
||
# Wait delay for autokey configuration. | ||
resource "time_sleep" "wait_autokey_config" { | ||
create_duration = "20s" | ||
depends_on = [module.autokey] | ||
} | ||
|
||
resource "random_string" "suffix" { | ||
length = 4 | ||
special = false | ||
upper = false | ||
} | ||
|
||
resource "google_kms_key_handle" "bucket_keyhandle" { | ||
provider = google-beta | ||
name = "${var.resource_project_id}-keyhandle-${random_string.suffix.result}" | ||
project = var.resource_project_id | ||
location = var.bucket_location | ||
resource_type_selector = "storage.googleapis.com/Bucket" | ||
|
||
lifecycle { | ||
ignore_changes = [name] | ||
} | ||
depends_on = [time_sleep.wait_autokey_config] | ||
} | ||
|
||
module "bucket" { | ||
source = "terraform-google-modules/cloud-storage/google//modules/simple_bucket" | ||
version = "~> 9.0" | ||
|
||
name = "${var.resource_project_id}-bucket-${random_string.suffix.result}" | ||
project_id = var.resource_project_id | ||
location = var.bucket_location | ||
encryption = { | ||
default_kms_key_name = resource.google_kms_key_handle.bucket_keyhandle.kms_key | ||
nb-goog marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
depends_on = [resource.google_kms_key_handle.bucket_keyhandle] | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/** | ||
* Copyright 2024 Google LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
output "bucket_keyhandle" { | ||
description = "Keyhandle configuration created for the bucket." | ||
value = resource.google_kms_key_handle.bucket_keyhandle | ||
} | ||
|
||
output "bucket_name" { | ||
description = "Name of the bucket created." | ||
value = module.bucket.name | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/** | ||
* Copyright 2024 Google LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
variable "key_project_id" { | ||
description = "The ID of the project in which KMS keyring and KMS keys will be provisioned by autokey." | ||
type = string | ||
} | ||
|
||
variable "folder_id" { | ||
type = string | ||
description = "The ID of the folder for which to configure and enable Autokey feature." | ||
} | ||
|
||
variable "resource_project_id" { | ||
description = "The ID of the project in which to provision cloud storage bucket resource." | ||
type = string | ||
} | ||
|
||
variable "bucket_location" { | ||
type = string | ||
description = "The GCP location where storage bucket will be created" | ||
default = "us-central1" | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.