Merge branch 'master' into lcaggio/shieldedfolder
This commit is contained in:
commit
39ffdcf184
|
@ -1,8 +1,8 @@
|
||||||
# GCE and GCS CMEK via centralized Cloud KMS
|
# GCE and GCS CMEK via centralized Cloud KMS
|
||||||
|
|
||||||
This example creates a sample centralized [Cloud KMS](https://cloud.google.com/kms?hl=it) configuration, and uses it to implement CMEK for [Cloud Storage](https://cloud.google.com/storage/docs/encryption/using-customer-managed-keys) and [Compute Engine](https://cloud.google.com/compute/docs/disks/customer-managed-encryption) in a separate project.
|
This example creates a sample centralized [Cloud KMS](https://cloud.google.com/kms?hl=it) configuration, and uses it to implement CMEK for [Cloud Storage](https://cloud.google.com/storage/docs/encryption/using-customer-managed-keys) and [Compute Engine](https://cloud.google.com/compute/docs/disks/customer-managed-encryption) in a service project.
|
||||||
|
|
||||||
The example is designed to match real-world use cases with a minimum amount of resources, and be used as a starting point for scenarios where application projects implement CMEK using keys managed by a central team. It also includes the IAM wiring needed to make such scenarios work.
|
The example is designed to match real-world use cases with a minimum amount of resources, and be used as a starting point for scenarios where application projects implement CMEK using keys managed by a central team. It also includes the IAM wiring needed to make such scenarios work. Regional resources are used in this example, but the same logic will apply for 'dual regional', 'multi regional' or 'global' resources.
|
||||||
|
|
||||||
This is the high level diagram:
|
This is the high level diagram:
|
||||||
|
|
||||||
|
@ -35,12 +35,10 @@ This sample creates several distinct groups of resources:
|
||||||
|
|
||||||
| name | description | type | required | default |
|
| name | description | type | required | default |
|
||||||
|---|---|:---:|:---:|:---:|
|
|---|---|:---:|:---:|:---:|
|
||||||
| [billing_account](variables.tf#L16) | Billing account id used as default for new projects. | <code>string</code> | ✓ | |
|
| [prefix](variables.tf#L21) | Optional prefix used to generate resources names. | <code>string</code> | ✓ | |
|
||||||
| [root_node](variables.tf#L45) | The resource name of the parent Folder or Organization. Must be of the form folders/folder_id or organizations/org_id. | <code>string</code> | ✓ | |
|
| [project_config](variables.tf#L27) | Provide 'billing_account_id' and 'parent' values if project creation is needed, uses existing 'projects_id' if null. Parent is in 'folders/nnn' or 'organizations/nnn' format. | <code title="object({ billing_account_id = optional(string, null) parent = optional(string, null) project_ids = optional(object({ encryption = string service = string }), { encryption = "encryption", service = "service" } ) })">object({…})</code> | ✓ | |
|
||||||
| [location](variables.tf#L21) | The location where resources will be deployed. | <code>string</code> | | <code>"europe"</code> |
|
| [location](variables.tf#L15) | The location where resources will be deployed. | <code>string</code> | | <code>"europe"</code> |
|
||||||
| [project_kms_name](variables.tf#L27) | Name for the new KMS Project. | <code>string</code> | | <code>"my-project-kms-001"</code> |
|
| [region](variables.tf#L44) | The region where resources will be deployed. | <code>string</code> | | <code>"europe-west1"</code> |
|
||||||
| [project_service_name](variables.tf#L33) | Name for the new Service Project. | <code>string</code> | | <code>"my-project-service-001"</code> |
|
|
||||||
| [region](variables.tf#L39) | The region where resources will be deployed. | <code>string</code> | | <code>"europe-west1"</code> |
|
|
||||||
| [vpc_ip_cidr_range](variables.tf#L50) | Ip range used in the subnet deployef in the Service Project. | <code>string</code> | | <code>"10.0.0.0/20"</code> |
|
| [vpc_ip_cidr_range](variables.tf#L50) | Ip range used in the subnet deployef in the Service Project. | <code>string</code> | | <code>"10.0.0.0/20"</code> |
|
||||||
| [vpc_name](variables.tf#L56) | Name of the VPC created in the Service Project. | <code>string</code> | | <code>"local"</code> |
|
| [vpc_name](variables.tf#L56) | Name of the VPC created in the Service Project. | <code>string</code> | | <code>"local"</code> |
|
||||||
| [vpc_subnet_name](variables.tf#L62) | Name of the subnet created in the Service Project. | <code>string</code> | | <code>"subnet"</code> |
|
| [vpc_subnet_name](variables.tf#L62) | Name of the subnet created in the Service Project. | <code>string</code> | | <code>"subnet"</code> |
|
||||||
|
|
|
@ -12,33 +12,61 @@
|
||||||
# See the License for the specific language governing permissions and
|
# See the License for the specific language governing permissions and
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
|
locals {
|
||||||
|
# Needed when you create KMS keys and encrypted resources in the same terraform state but different projects.
|
||||||
|
kms_keys = {
|
||||||
|
gce = "projects/${module.project-kms.project_id}/locations/${var.region}/keyRings/${var.prefix}-${var.region}/cryptoKeys/key-gcs"
|
||||||
|
gcs = "projects/${module.project-kms.project_id}/locations/${var.region}/keyRings/${var.prefix}-${var.region}/cryptoKeys/key-gcs"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
###############################################################################
|
###############################################################################
|
||||||
# Projects #
|
# Projects #
|
||||||
###############################################################################
|
###############################################################################
|
||||||
|
|
||||||
module "project-service" {
|
module "project-service" {
|
||||||
source = "../../../modules/project"
|
source = "../../../modules/project"
|
||||||
name = var.project_service_name
|
name = var.project_config.project_ids.service
|
||||||
parent = var.root_node
|
parent = var.project_config.parent
|
||||||
billing_account = var.billing_account
|
billing_account = var.project_config.billing_account_id
|
||||||
|
project_create = var.project_config.billing_account_id != null
|
||||||
|
prefix = var.project_config.billing_account_id == null ? null : var.prefix
|
||||||
services = [
|
services = [
|
||||||
"compute.googleapis.com",
|
"compute.googleapis.com",
|
||||||
"servicenetworking.googleapis.com",
|
"servicenetworking.googleapis.com",
|
||||||
"storage-component.googleapis.com"
|
"storage.googleapis.com",
|
||||||
|
"storage-component.googleapis.com",
|
||||||
|
]
|
||||||
|
service_encryption_key_ids = {
|
||||||
|
compute = [
|
||||||
|
local.kms_keys.gce
|
||||||
|
]
|
||||||
|
storage = [
|
||||||
|
local.kms_keys.gcs
|
||||||
|
]
|
||||||
|
}
|
||||||
|
service_config = {
|
||||||
|
disable_on_destroy = false, disable_dependent_services = false
|
||||||
|
}
|
||||||
|
depends_on = [
|
||||||
|
module.kms
|
||||||
]
|
]
|
||||||
oslogin = true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
module "project-kms" {
|
module "project-kms" {
|
||||||
source = "../../../modules/project"
|
source = "../../../modules/project"
|
||||||
name = var.project_kms_name
|
name = var.project_config.project_ids.encryption
|
||||||
parent = var.root_node
|
parent = var.project_config.parent
|
||||||
billing_account = var.billing_account
|
billing_account = var.project_config.billing_account_id
|
||||||
|
project_create = var.project_config.billing_account_id != null
|
||||||
|
prefix = var.project_config.billing_account_id == null ? null : var.prefix
|
||||||
services = [
|
services = [
|
||||||
"cloudkms.googleapis.com",
|
"cloudkms.googleapis.com",
|
||||||
"servicenetworking.googleapis.com"
|
"servicenetworking.googleapis.com"
|
||||||
]
|
]
|
||||||
oslogin = true
|
service_config = {
|
||||||
|
disable_on_destroy = false, disable_dependent_services = false
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
###############################################################################
|
###############################################################################
|
||||||
|
@ -48,11 +76,11 @@ module "project-kms" {
|
||||||
module "vpc" {
|
module "vpc" {
|
||||||
source = "../../../modules/net-vpc"
|
source = "../../../modules/net-vpc"
|
||||||
project_id = module.project-service.project_id
|
project_id = module.project-service.project_id
|
||||||
name = var.vpc_name
|
name = "${var.prefix}-vpc"
|
||||||
subnets = [
|
subnets = [
|
||||||
{
|
{
|
||||||
ip_cidr_range = var.vpc_ip_cidr_range
|
ip_cidr_range = "10.0.0.0/20"
|
||||||
name = var.vpc_subnet_name
|
name = "${var.prefix}-${var.region}"
|
||||||
region = var.region
|
region = var.region
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
@ -63,7 +91,7 @@ module "vpc-firewall" {
|
||||||
project_id = module.project-service.project_id
|
project_id = module.project-service.project_id
|
||||||
network = module.vpc.name
|
network = module.vpc.name
|
||||||
default_rules_config = {
|
default_rules_config = {
|
||||||
admin_ranges = [var.vpc_ip_cidr_range]
|
admin_ranges = ["10.0.0.0/20"]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -75,22 +103,10 @@ module "kms" {
|
||||||
source = "../../../modules/kms"
|
source = "../../../modules/kms"
|
||||||
project_id = module.project-kms.project_id
|
project_id = module.project-kms.project_id
|
||||||
keyring = {
|
keyring = {
|
||||||
name = "my-keyring",
|
name = "${var.prefix}-${var.region}",
|
||||||
location = var.location
|
location = var.region
|
||||||
}
|
}
|
||||||
keys = { key-gce = null, key-gcs = null }
|
keys = { key-gce = null, key-gcs = null }
|
||||||
key_iam = {
|
|
||||||
key-gce = {
|
|
||||||
"roles/cloudkms.cryptoKeyEncrypterDecrypter" = [
|
|
||||||
"serviceAccount:${module.project-service.service_accounts.robots.compute}",
|
|
||||||
]
|
|
||||||
},
|
|
||||||
key-gcs = {
|
|
||||||
"roles/cloudkms.cryptoKeyEncrypterDecrypter" = [
|
|
||||||
"serviceAccount:${module.project-service.service_accounts.robots.storage}",
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
###############################################################################
|
###############################################################################
|
||||||
|
@ -101,10 +117,10 @@ module "vm_example" {
|
||||||
source = "../../../modules/compute-vm"
|
source = "../../../modules/compute-vm"
|
||||||
project_id = module.project-service.project_id
|
project_id = module.project-service.project_id
|
||||||
zone = "${var.region}-b"
|
zone = "${var.region}-b"
|
||||||
name = "kms-vm"
|
name = "${var.prefix}-vm"
|
||||||
network_interfaces = [{
|
network_interfaces = [{
|
||||||
network = module.vpc.self_link,
|
network = module.vpc.self_link,
|
||||||
subnetwork = module.vpc.subnet_self_links["${var.region}/subnet"],
|
subnetwork = module.vpc.subnet_self_links["${var.region}/${var.prefix}-${var.region}"],
|
||||||
nat = false,
|
nat = false,
|
||||||
addresses = null
|
addresses = null
|
||||||
}]
|
}]
|
||||||
|
@ -127,7 +143,7 @@ module "vm_example" {
|
||||||
encryption = {
|
encryption = {
|
||||||
encrypt_boot = true
|
encrypt_boot = true
|
||||||
disk_encryption_key_raw = null
|
disk_encryption_key_raw = null
|
||||||
kms_key_self_link = module.kms.key_ids.key-gce
|
kms_key_self_link = local.kms_keys.gce
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -138,7 +154,9 @@ module "vm_example" {
|
||||||
module "kms-gcs" {
|
module "kms-gcs" {
|
||||||
source = "../../../modules/gcs"
|
source = "../../../modules/gcs"
|
||||||
project_id = module.project-service.project_id
|
project_id = module.project-service.project_id
|
||||||
prefix = "my-bucket-001"
|
prefix = var.prefix
|
||||||
name = "kms-gcs"
|
name = "${var.prefix}-bucket"
|
||||||
encryption_key = module.kms.keys.key-gcs.id
|
location = var.region
|
||||||
|
storage_class = "REGIONAL"
|
||||||
|
encryption_key = local.kms_keys.gcs
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,28 +12,33 @@
|
||||||
# See the License for the specific language governing permissions and
|
# See the License for the specific language governing permissions and
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
|
|
||||||
variable "billing_account" {
|
|
||||||
description = "Billing account id used as default for new projects."
|
|
||||||
type = string
|
|
||||||
}
|
|
||||||
|
|
||||||
variable "location" {
|
variable "location" {
|
||||||
description = "The location where resources will be deployed."
|
description = "The location where resources will be deployed."
|
||||||
type = string
|
type = string
|
||||||
default = "europe"
|
default = "europe"
|
||||||
}
|
}
|
||||||
|
|
||||||
variable "project_kms_name" {
|
variable "prefix" {
|
||||||
description = "Name for the new KMS Project."
|
description = "Optional prefix used to generate resources names."
|
||||||
type = string
|
type = string
|
||||||
default = "my-project-kms-001"
|
nullable = false
|
||||||
}
|
}
|
||||||
|
|
||||||
variable "project_service_name" {
|
variable "project_config" {
|
||||||
description = "Name for the new Service Project."
|
description = "Provide 'billing_account_id' and 'parent' values if project creation is needed, uses existing 'projects_id' if null. Parent is in 'folders/nnn' or 'organizations/nnn' format."
|
||||||
type = string
|
type = object({
|
||||||
default = "my-project-service-001"
|
billing_account_id = optional(string, null)
|
||||||
|
parent = optional(string, null)
|
||||||
|
project_ids = optional(object({
|
||||||
|
encryption = string
|
||||||
|
service = string
|
||||||
|
}), {
|
||||||
|
encryption = "encryption",
|
||||||
|
service = "service"
|
||||||
|
}
|
||||||
|
)
|
||||||
|
})
|
||||||
|
nullable = false
|
||||||
}
|
}
|
||||||
|
|
||||||
variable "region" {
|
variable "region" {
|
||||||
|
@ -42,11 +47,6 @@ variable "region" {
|
||||||
default = "europe-west1"
|
default = "europe-west1"
|
||||||
}
|
}
|
||||||
|
|
||||||
variable "root_node" {
|
|
||||||
description = "The resource name of the parent Folder or Organization. Must be of the form folders/folder_id or organizations/org_id."
|
|
||||||
type = string
|
|
||||||
}
|
|
||||||
|
|
||||||
variable "vpc_ip_cidr_range" {
|
variable "vpc_ip_cidr_range" {
|
||||||
description = "Ip range used in the subnet deployef in the Service Project."
|
description = "Ip range used in the subnet deployef in the Service Project."
|
||||||
type = string
|
type = string
|
||||||
|
|
|
@ -15,7 +15,10 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
module "test" {
|
module "test" {
|
||||||
source = "../../../../../blueprints/data-solutions/cmek-via-centralized-kms/"
|
source = "../../../../../blueprints/data-solutions/cmek-via-centralized-kms/"
|
||||||
billing_account = var.billing_account
|
project_config = {
|
||||||
root_node = var.root_node
|
billing_account_id = "123456-123456-123456"
|
||||||
|
parent = "folders/12345678"
|
||||||
|
}
|
||||||
|
prefix = "prefix"
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,26 +0,0 @@
|
||||||
/**
|
|
||||||
* Copyright 2022 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 "billing_account" {
|
|
||||||
type = string
|
|
||||||
default = "123456-123456-123456"
|
|
||||||
}
|
|
||||||
|
|
||||||
variable "root_node" {
|
|
||||||
description = "The resource name of the parent Folder or Organization. Must be of the form folders/folder_id or organizations/org_id."
|
|
||||||
type = string
|
|
||||||
default = "folders/12345678"
|
|
||||||
}
|
|
Loading…
Reference in New Issue