Skip to content
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

Feat: Encrypt bucket with CMEK #325

Merged

Conversation

ps-occrp
Copy link
Contributor

@ps-occrp ps-occrp commented Jul 1, 2024

This PR encrypts bucket using CMEK if default_kms_key_name is set to null in encryption block for simple_bucket submodule

@ps-occrp ps-occrp requested a review from a team as a code owner July 1, 2024 16:17
@ps-occrp
Copy link
Contributor Author

ps-occrp commented Jul 1, 2024

@apeabody Can you please review this PR?

@apeabody
Copy link
Contributor

apeabody commented Jul 1, 2024

/gcbrun

@apeabody
Copy link
Contributor

apeabody commented Jul 1, 2024

        	Error:      	Received unexpected error:
        	            	FatalError{Underlying: error while running command: exit status 1; 
        	            	Error: no project value set. `project_id` must be set at the resource level, or a default `project` value must be specified on the provider
        	            	
        	            	  with module.bucket.data.google_project.project,
        	            	  on ../../modules/simple_bucket/main.tf line 123, in data "google_project" "project":
        	            	 123: data "google_project" "project" {
        	            	}
        	Test:       	TestAll/examples/simple_bucket
@ps-occrp
Copy link
Contributor Author

ps-occrp commented Jul 2, 2024

Can you trigger gcbrun again?

@apeabody
Copy link
Contributor

apeabody commented Jul 2, 2024

/gcbrun

@ps-occrp
Copy link
Contributor Author

ps-occrp commented Jul 2, 2024

assuming last run was successful, can you trigger it again? I just fixed a bug

@apeabody
Copy link
Contributor

apeabody commented Jul 2, 2024

/gcbrun

@apeabody
Copy link
Contributor

apeabody commented Jul 2, 2024

        	Error:      	Received unexpected error:
        	            	FatalError{Underlying: error while running command: exit status 1; 
        	            	Error: Error applying IAM policy for KMS CryptoKey "projects/ci-cloud-storage-0583/locations/us/keyRings/ci-cloud-storage-0583-bucket/cryptoKeys/ci-cloud-storage-0583-bucket": Error setting IAM policy for KMS CryptoKey "projects/ci-cloud-storage-0583/locations/us/keyRings/ci-cloud-storage-0583-bucket/cryptoKeys/ci-cloud-storage-0583-bucket": googleapi: Error 400: Service account service-443806032995@gs-project-accounts.iam.gserviceaccount.com does not exist., badRequest
        	            	
        	            	  with module.bucket.module.encryption_key[0].google_kms_crypto_key_iam_binding.decrypters[0],
        	            	  on .terraform/modules/bucket.encryption_key/main.tf line 76, in resource "google_kms_crypto_key_iam_binding" "decrypters":
        	            	  76: resource "google_kms_crypto_key_iam_binding" "decrypters" {
        	            	
        	            	
        	            	Error: Error applying IAM policy for KMS CryptoKey "projects/ci-cloud-storage-0583/locations/us/keyRings/ci-cloud-storage-0583-bucket/cryptoKeys/ci-cloud-storage-0583-bucket": Error setting IAM policy for KMS CryptoKey "projects/ci-cloud-storage-0583/locations/us/keyRings/ci-cloud-storage-0583-bucket/cryptoKeys/ci-cloud-storage-0583-bucket": googleapi: Error 400: Service account service-443806032995@gs-project-accounts.iam.gserviceaccount.com does not exist., badRequest
        	            	
        	            	  with module.bucket.module.encryption_key[0].google_kms_crypto_key_iam_binding.encrypters[0],
        	            	  on .terraform/modules/bucket.encryption_key/main.tf line 83, in resource "google_kms_crypto_key_iam_binding" "encrypters":
        	            	  83: resource "google_kms_crypto_key_iam_binding" "encrypters" {
        	            	}
        	Test:       	TestAll/examples/simple_bucket
@ps-occrp
Copy link
Contributor Author

ps-occrp commented Jul 3, 2024

This looks very similar to this issue hashicorp/terraform-provider-google#7611

Basically service account doesn't get created until api is used and in this case we want to use api after creating keys.

I'm open to implement workaround but for most of actual users this will never be an issue. Do you have any suggestion on how to move forward here?

@ps-occrp
Copy link
Contributor Author

ps-occrp commented Jul 3, 2024

Latest commit should fix this issue. Please run gcbrun again :)

@apeabody
Copy link
Contributor

apeabody commented Jul 3, 2024

/gcbrun

@apeabody
Copy link
Contributor

apeabody commented Jul 3, 2024

/gcbrun

@apeabody
Copy link
Contributor

apeabody commented Jul 3, 2024

/gcbrun

@ps-occrp
Copy link
Contributor Author

ps-occrp commented Jul 5, 2024

Can this be merged?

@apeabody
Copy link
Contributor

apeabody commented Jul 9, 2024

/gcbrun

Copy link
Contributor

@apeabody apeabody left a 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 @ps-occrp!

@apeabody apeabody merged commit 07e3a4e into terraform-google-modules:master Jul 9, 2024
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants