Skip to content

Commit

Permalink
feat: Add CMEK support to create_environment submodule by setting `km…
Browse files Browse the repository at this point in the history
…s_key_name` variable (#16)

BREAKING CHANGE: `create_environment` submodule now uses the `google-beta` provider.
  • Loading branch information
averbuks authored Jun 22, 2021
1 parent f440422 commit 9cd4934
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 0 deletions.
1 change: 1 addition & 0 deletions modules/create_environment/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ module "composer" {
| enable\_private\_endpoint | Configure public access to the cluster endpoint. | `bool` | `false` | no |
| env\_variables | Variables of the airflow environment. | `map(string)` | `{}` | no |
| image\_version | The version of the aiflow running in the cloud composer environment. | `string` | `null` | no |
| 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 |
| labels | The resource labels (a map of key/value pairs) to be applied to the Cloud Composer. | `map(string)` | `{}` | no |
| machine\_type | Machine type of Cloud Composer nodes. | `string` | `"n1-standard-8"` | no |
| master\_ipv4\_cidr | The CIDR block from which IP range in tenant project will be reserved for the master. | `string` | `null` | no |
Expand Down
12 changes: 12 additions & 0 deletions modules/create_environment/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ locals {
}

resource "google_composer_environment" "composer_env" {
provider = google-beta

project = var.project_id
name = var.composer_env_name
region = var.region
Expand Down Expand Up @@ -81,5 +83,15 @@ resource "google_composer_environment" "composer_env" {
python_version = software_config.value["python_version"]
}
}

dynamic "encryption_config" {
for_each = var.kms_key_name != null ? [
{
kms_key_name = var.kms_key_name
}] : []
content {
kms_key_name = encryption_config.value["kms_key_name"]
}
}
}
}
6 changes: 6 additions & 0 deletions modules/create_environment/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -171,3 +171,9 @@ variable "enable_private_endpoint" {
type = bool
default = false
}

variable "kms_key_name" {
description = "Customer-managed Encryption Key fully qualified resource name, i.e. projects/project-id/locations/location/keyRings/keyring/cryptoKeys/key."
type = string
default = null
}
5 changes: 5 additions & 0 deletions modules/create_environment/versions.tf
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ terraform {
source = "hashicorp/google"
version = "~> 3.53"
}

google-beta = {
source = "hashicorp/google-beta"
version = "~> 3.53"
}
}

provider_meta "google" {
Expand Down
5 changes: 5 additions & 0 deletions versions.tf
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ terraform {
source = "hashicorp/google"
version = "~> 3.53"
}

google-beta = {
source = "hashicorp/google-beta"
version = "~> 3.53"
}
}

provider_meta "google" {
Expand Down

0 comments on commit 9cd4934

Please sign in to comment.