Skip to content

Commit

Permalink
address comments; use private-service-access submodule, update test
Browse files Browse the repository at this point in the history
  • Loading branch information
pkatsovich committed Jul 28, 2020
1 parent cb37609 commit af2b67b
Show file tree
Hide file tree
Showing 8 changed files with 136 additions and 49 deletions.
37 changes: 37 additions & 0 deletions examples/memcache/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/**
* 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 = var.project
memory_size_mb = var.memory_size_mb
enable_apis = var.enable_apis
cpu_count = var.cpu_count
region = var.region
module_depends_on = [module.private-service-access.peering_completed]
}
34 changes: 25 additions & 9 deletions examples/memcache/memcache.tf → examples/memcache/outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,31 @@
* limitations under the License.
*/

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

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
}

module "memcache" {
source = "../../modules/memcache"
name = "memcache"
project = "memcache"
memory_size_mb = 1024
enable_apis = true
cpu_count = 1
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
}
1 change: 1 addition & 0 deletions modules/memcache/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ A Terraform module for creating a fully functional Google Memorystore (memcache)
| 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 |
| module\_depends\_on | Workaround to delay module initialization until private service access connection is available | list(any) | `<list>` | 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 |
Expand Down
6 changes: 5 additions & 1 deletion modules/memcache/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ variable "reserved_ip_range" {
default = null
}


variable "labels" {
description = "The resource labels to represent user provided metadata."
type = map(string)
Expand All @@ -90,3 +89,8 @@ variable "params" {
default = null
}

variable "module_depends_on" {
description = "Workaround to delay module initialization until private service access connection is available"
type = list(any)
default = []
}
30 changes: 2 additions & 28 deletions test/fixtures/memcache/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -14,33 +14,7 @@
* limitations under the License.
*/

data "google_compute_network" "peering_network" {
project = var.project_id
name = "default"
}

resource "google_compute_global_address" "private_ip_alloc" {
project = var.project_id
name = "private-ip-alloc"
purpose = "VPC_PEERING"
address_type = "INTERNAL"
prefix_length = 16
network = data.google_compute_network.peering_network.self_link
}

resource "google_service_networking_connection" "ci-memory-store" {
network = data.google_compute_network.peering_network.self_link
service = "servicenetworking.googleapis.com"
reserved_peering_ranges = [google_compute_global_address.private_ip_alloc.name]
}


module "memcache" {
source = "../../../examples/memcache"
name = "test-memcache"
project = var.project_id
region = "us-esast1"
memory_size_mb = 1024
cpu_count = 1
enable_apis = true
source = "../../../examples/memcache"
project = var.project_id
}
19 changes: 10 additions & 9 deletions test/fixtures/memcache/outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -14,30 +14,31 @@
* limitations under the License.
*/


output "project_id" {
value = var.project_id
}

output "name" {
value = var.name
value = module.memcache.name
}

output "region" {
value = var.region
value = module.memcache.region
}

output "memory_size_mb" {
value = var.memory_size_mb
output "cpu_count" {
value = module.memcache.cpu_count
}


output "cpu_count" {
value = var.cpu_count
output "memory_size_mb" {
value = module.memcache.memory_size_mb
}

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

output "output_region" {
value = module.memcache.region
value = module.memcache.output_region
}
8 changes: 6 additions & 2 deletions test/integration/memcache/controls/gcloud.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,12 @@
end
end

it { expect(metadata['nodeConfig']['cpuCount']).to eq(cpu_count) }
it { expect(metadata['nodeConfig']['memorySizeMb']).to eq(memory_size_mb) }
it "nodeConfig.cpucount matches var.cpu_count" do
expect(metadata['nodeConfig']['cpuCount']).to eq(cpu_count)
end
it "nodeConfig.memorySizeMb matches var.memory_size_mb" do
expect(metadata['nodeConfig']['memorySizeMb']).to eq(memory_size_mb)
end

end
end

0 comments on commit af2b67b

Please sign in to comment.