Skip to content

Commit 9cd4934

Browse files
authored
feat: Add CMEK support to create_environment submodule by setting kms_key_name variable (#16)
BREAKING CHANGE: `create_environment` submodule now uses the `google-beta` provider.
1 parent f440422 commit 9cd4934

File tree

5 files changed

+29
-0
lines changed

5 files changed

+29
-0
lines changed

modules/create_environment/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ module "composer" {
3535
| enable\_private\_endpoint | Configure public access to the cluster endpoint. | `bool` | `false` | no |
3636
| env\_variables | Variables of the airflow environment. | `map(string)` | `{}` | no |
3737
| image\_version | The version of the aiflow running in the cloud composer environment. | `string` | `null` | no |
38+
| kms\_key\_name | Customer-managed Encryption Key fully qualified resource name, i.e. projects/project-id/locations/location/keyRings/keyring/cryptoKeys/key. | `string` | `null` | no |
3839
| labels | The resource labels (a map of key/value pairs) to be applied to the Cloud Composer. | `map(string)` | `{}` | no |
3940
| machine\_type | Machine type of Cloud Composer nodes. | `string` | `"n1-standard-8"` | no |
4041
| master\_ipv4\_cidr | The CIDR block from which IP range in tenant project will be reserved for the master. | `string` | `null` | no |

modules/create_environment/main.tf

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ locals {
2020
}
2121

2222
resource "google_composer_environment" "composer_env" {
23+
provider = google-beta
24+
2325
project = var.project_id
2426
name = var.composer_env_name
2527
region = var.region
@@ -81,5 +83,15 @@ resource "google_composer_environment" "composer_env" {
8183
python_version = software_config.value["python_version"]
8284
}
8385
}
86+
87+
dynamic "encryption_config" {
88+
for_each = var.kms_key_name != null ? [
89+
{
90+
kms_key_name = var.kms_key_name
91+
}] : []
92+
content {
93+
kms_key_name = encryption_config.value["kms_key_name"]
94+
}
95+
}
8496
}
8597
}

modules/create_environment/variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,3 +171,9 @@ variable "enable_private_endpoint" {
171171
type = bool
172172
default = false
173173
}
174+
175+
variable "kms_key_name" {
176+
description = "Customer-managed Encryption Key fully qualified resource name, i.e. projects/project-id/locations/location/keyRings/keyring/cryptoKeys/key."
177+
type = string
178+
default = null
179+
}

modules/create_environment/versions.tf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ terraform {
2222
source = "hashicorp/google"
2323
version = "~> 3.53"
2424
}
25+
26+
google-beta = {
27+
source = "hashicorp/google-beta"
28+
version = "~> 3.53"
29+
}
2530
}
2631

2732
provider_meta "google" {

versions.tf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ terraform {
2222
source = "hashicorp/google"
2323
version = "~> 3.53"
2424
}
25+
26+
google-beta = {
27+
source = "hashicorp/google-beta"
28+
version = "~> 3.53"
29+
}
2530
}
2631

2732
provider_meta "google" {

0 commit comments

Comments
 (0)