Skip to content

Commit

Permalink
feat: Added submodule for cloud memorystore (memcache) (#22)
Browse files Browse the repository at this point in the history
  • Loading branch information
pkatsovich authored Jul 28, 2020
1 parent 2bdf5f3 commit 6067568
Show file tree
Hide file tree
Showing 22 changed files with 593 additions and 13 deletions.
12 changes: 12 additions & 0 deletions .kitchen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,15 @@ suites:
backend: local
provisioner:
name: terraform
- name: "memcache"
driver:
name: "terraform"
command_timeout: 1800
root_module_directory: test/fixtures/memcache
verifier:
name: terraform
systems:
- name: memcache
backend: local
provisioner:
name: terraform
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
# Make will use bash instead of sh
SHELL := /usr/bin/env bash

DOCKER_TAG_VERSION_DEVELOPER_TOOLS := 0.4.6
DOCKER_TAG_VERSION_DEVELOPER_TOOLS := 0.11.6
DOCKER_IMAGE_DEVELOPER_TOOLS := cft/developer-tools
REGISTRY_URL := gcr.io/cloud-foundation-cicd

Expand Down
2 changes: 1 addition & 1 deletion build/int.cloudbuild.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,4 @@ tags:
- 'integration'
substitutions:
_DOCKER_IMAGE_DEVELOPER_TOOLS: 'cft/developer-tools'
_DOCKER_TAG_VERSION_DEVELOPER_TOOLS: '0.4.6'
_DOCKER_TAG_VERSION_DEVELOPER_TOOLS: '0.11.6'
2 changes: 1 addition & 1 deletion build/lint.cloudbuild.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ tags:
- 'lint'
substitutions:
_DOCKER_IMAGE_DEVELOPER_TOOLS: 'cft/developer-tools'
_DOCKER_TAG_VERSION_DEVELOPER_TOOLS: '0.4.6'
_DOCKER_TAG_VERSION_DEVELOPER_TOOLS: '0.11.6'
36 changes: 36 additions & 0 deletions examples/memcache/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/**
* Copyright 2019 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.
*/

provider "google-beta" {
version = "~> 3.31.0"
}

module "private-service-access" {
source = "GoogleCloudPlatform/sql-db/google//modules/private_service_access"
version = "3.2.0"
project_id = var.project
vpc_network = "default"
}

module "memcache" {
source = "../../modules/memcache"
name = var.name
project = can(module.private-service-access.peering_completed) ? var.project : ""
memory_size_mb = var.memory_size_mb
enable_apis = var.enable_apis
cpu_count = var.cpu_count
region = var.region
}
44 changes: 44 additions & 0 deletions examples/memcache/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/**
* Copyright 2019 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 "project_id" {
value = var.project
}

output "name" {
value = var.name
}

output "region" {
value = var.region
}

output "cpu_count" {
value = var.cpu_count
}

output "memory_size_mb" {
value = var.memory_size_mb
}

output "output_id" {
value = module.memcache.id
}

output "output_region" {
value = module.memcache.region
}
50 changes: 50 additions & 0 deletions examples/memcache/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/**
* Copyright 2019 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 "project" {
description = "The ID of the project in which the resource belongs to."
type = string
}

variable "name" {
description = "Name of memcache instance."
type = string
default = "example-memcache"
}

variable "region" {
description = "Region to create test instance."
type = string
default = "us-east1"
}

variable "memory_size_mb" {
description = "Memory size of test instance."
type = number
default = 1024
}

variable "cpu_count" {
description = "Number of cpu's for test instance."
type = number
default = 1
}

variable "enable_apis" {
description = "Flag for enabling memcache.googleapis.com in your project"
type = bool
default = true
}
23 changes: 23 additions & 0 deletions examples/memcache/versions.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/**
* Copyright 2019 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.
*/

terraform {
required_version = ">= 0.12"
required_providers {
google = ">= 3.14.0"
google-beta = ">= 3.31.0"
}
}
31 changes: 31 additions & 0 deletions modules/memcache/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# [Google Cloud Memorystore Terraform Module](https://registry.terraform.io/modules/terraform-google-modules/memorystore/google/)

A Terraform module for creating a fully functional Google Memorystore (memcache) instance.

<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
## Inputs

| Name | Description | Type | Default | Required |
|------|-------------|:----:|:-----:|:-----:|
| authorized\_network | The full name of the Google Compute Engine network to which the instance is connected. If left unspecified, the default network will be used. | string | `"null"` | no |
| cpu\_count | Number of CPUs per node | number | `"1"` | no |
| display\_name | An arbitrary and optional user-provided name for the instance. | string | `"null"` | no |
| enable\_apis | Flag for enabling memcache.googleapis.com in your project | bool | `"true"` | no |
| labels | The resource labels to represent user provided metadata. | map(string) | `<map>` | no |
| memory\_size\_mb | Memcache memory size in MiB. Defaulted to 1024 | number | `"1024"` | no |
| name | The ID of the instance or a fully qualified identifier for the instance. | string | n/a | yes |
| node\_count | Number of nodes in the memcache instance. | number | `"1"` | no |
| params | Parameters for the memcache process | map(string) | `"null"` | no |
| project | The ID of the project in which the resource belongs to. | string | n/a | yes |
| region | The GCP region to use. | string | n/a | yes |
| reserved\_ip\_range | The CIDR range of internal addresses that are reserved for this instance. | string | `"null"` | no |
| zones | Zones where memcache nodes should be provisioned. If not provided, all zones will be used. | list(string) | `"null"` | no |

## Outputs

| Name | Description |
|------|-------------|
| id | The memorystore instance ID. |
| region | The region the instance lives in. |

<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
54 changes: 54 additions & 0 deletions modules/memcache/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/**
* Copyright 2019 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.
*/

resource "google_memcache_instance" "self" {
depends_on = [module.enable_apis]
provider = google-beta
project = var.project
zones = var.zones
name = var.name
region = var.region
authorized_network = var.authorized_network
node_count = var.node_count
display_name = var.display_name == null ? var.display_name : var.name
labels = var.labels

node_config {
cpu_count = var.cpu_count
memory_size_mb = var.memory_size_mb
}

dynamic "memcache_parameters" {
for_each = var.params == null ? [] : [var.params]
content {
params = memcache_parameters.value
}
}

}


module "enable_apis" {
source = "terraform-google-modules/project-factory/google//modules/project_services"
version = "8.0.1"

project_id = var.project
enable_apis = var.enable_apis

activate_apis = [
"memcache.googleapis.com",
]
}
25 changes: 25 additions & 0 deletions modules/memcache/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/**
* Copyright 2019 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 "id" {
description = "The memorystore instance ID."
value = google_memcache_instance.self.id
}

output "region" {
description = "The region the instance lives in."
value = google_memcache_instance.self.region
}
90 changes: 90 additions & 0 deletions modules/memcache/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
/**
* Copyright 2019 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 "region" {
description = "The GCP region to use."
type = string
}

variable "project" {
description = "The ID of the project in which the resource belongs to."
type = string
}

variable "enable_apis" {
description = "Flag for enabling memcache.googleapis.com in your project"
type = bool
default = true
}

variable "name" {
description = "The ID of the instance or a fully qualified identifier for the instance."
type = string
}

variable "authorized_network" {
description = "The full name of the Google Compute Engine network to which the instance is connected. If left unspecified, the default network will be used."
type = string
default = null
}

variable "node_count" {
description = "Number of nodes in the memcache instance."
type = number
default = 1
}

variable "cpu_count" {
description = "Number of CPUs per node"
type = number
default = 1
}

variable "memory_size_mb" {
description = "Memcache memory size in MiB. Defaulted to 1024"
type = number
default = 1024
}

variable "zones" {
description = "Zones where memcache nodes should be provisioned. If not provided, all zones will be used."
type = list(string)
default = null
}

variable "display_name" {
description = "An arbitrary and optional user-provided name for the instance."
type = string
default = null
}

variable "reserved_ip_range" {
description = "The CIDR range of internal addresses that are reserved for this instance."
type = string
default = null
}

variable "labels" {
description = "The resource labels to represent user provided metadata."
type = map(string)
default = {}
}

variable "params" {
description = "Parameters for the memcache process"
type = map(string)
default = null
}
Loading

0 comments on commit 6067568

Please sign in to comment.