Skip to content

Commit

Permalink
Fixes terraform-google-modules#180: Add tests for beta submodules/exa…
Browse files Browse the repository at this point in the history
…mples

terraform-google-modules#180

Added tests for the beta private cluster.
  • Loading branch information
bohdanyurov-gl committed Nov 8, 2019
1 parent 03f0931 commit 836c69b
Show file tree
Hide file tree
Showing 11 changed files with 538 additions and 2 deletions.
13 changes: 13 additions & 0 deletions .kitchen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,19 @@ suites:
systems:
- name: workload_metadata_config
backend: local
- name: "beta_cluster"
driver:
root_module_directory: test/fixtures/beta_cluster
verifier:
systems:
- name: gcloud
backend: local
controls:
- gcloud
- name: gcp
backend: gcp
controls:
- gcp
- name: "deploy_service"
driver:
root_module_directory: test/fixtures/deploy_service
Expand Down
24 changes: 22 additions & 2 deletions build/int.cloudbuild.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,26 @@ steps:
- verify workload-metadata-config-local
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
args: ['/bin/bash', '-c', 'source /usr/local/bin/task_helper_functions.sh && kitchen_do destroy workload-metadata-config-local']
- id: create beta-cluster-local
waitFor:
- prepare
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
args: ['/bin/bash', '-c', 'source /usr/local/bin/task_helper_functions.sh && kitchen_do create beta-cluster-local']
- id: converge beta-cluster-local
waitFor:
- create beta-cluster-local
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
args: ['/bin/bash', '-c', 'source /usr/local/bin/task_helper_functions.sh && kitchen_do converge beta-cluster-local']
- id: verify beta-cluster-local
waitFor:
- converge beta-cluster-local
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
args: ['/bin/bash', '-c', 'source /usr/local/bin/task_helper_functions.sh && kitchen_do verify beta-cluster-local']
#- id: destroy beta-cluster-local
# waitFor:
# - verify beta-cluster-local
# name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
# args: ['/bin/bash', '-c', 'source /usr/local/bin/task_helper_functions.sh && kitchen_do destroy beta-cluster-local']
- id: create deploy-service-local
waitFor:
- prepare
Expand Down Expand Up @@ -304,8 +324,8 @@ steps:
tags:
- 'ci'
- 'integration'
options:
machineType: 'N1_HIGHCPU_8'
substitutions:
_DOCKER_IMAGE_DEVELOPER_TOOLS: 'cft/developer-tools'
_DOCKER_TAG_VERSION_DEVELOPER_TOOLS: '0.4.6'
options:
machineType: 'N1_HIGHCPU_8'
18 changes: 18 additions & 0 deletions test/ci/beta-cluster.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---

platform: linux

inputs:
- name: pull-request
path: terraform-google-kubernetes-engine

run:
path: make
args: ['test_integration']
dir: terraform-google-kubernetes-engine

params:
SUITE: "beta-cluster-local"
COMPUTE_ENGINE_SERVICE_ACCOUNT: ""
REGION: "us-east4"
ZONES: '["us-east4-a", "us-east4-b", "us-east4-c"]'
78 changes: 78 additions & 0 deletions test/fixtures/beta_cluster/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/**
* Copyright 2018 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" {
version = "~> 2.18.0"
project = var.project_id
region = var.region
}

provider "google-beta" {
version = "~> 2.18.0"
project = var.project_id
region = var.region
}

locals {
name = "beta-cluster-${random_string.suffix.result}"
}

resource "google_kms_key_ring" "db" {
location = var.region
name = "${local.name}-db"
}

resource "google_kms_crypto_key" "db" {
name = local.name
key_ring = google_kms_key_ring.db.self_link
}

module "this" {
source = "../../../modules/beta-public-cluster"

name = local.name
project_id = var.project_id
regional = false
region = var.region
zones = slice(var.zones, 0, 1)
network = google_compute_network.main.name
subnetwork = google_compute_subnetwork.main.name
ip_range_pods = google_compute_subnetwork.main.secondary_ip_range[0].range_name
ip_range_services = google_compute_subnetwork.main.secondary_ip_range[1].range_name
service_account = "create"

// Beta features
istio = true

database_encryption = [{
state = "ENCRYPTED"
key_name = google_kms_crypto_key.db.self_link
}]

cloudrun = true

enable_binary_authorization = true

pod_security_policy_config = [{
enabled = true
}]

node_metadata = "EXPOSE"
}

data "google_client_config" "default" {
}
44 changes: 44 additions & 0 deletions test/fixtures/beta_cluster/network.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/**
* Copyright 2018 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 "random_string" "suffix" {
length = 4
special = false
upper = false
}

resource "google_compute_network" "main" {
name = "cft-gke-test-${random_string.suffix.result}"
auto_create_subnetworks = false
}

resource "google_compute_subnetwork" "main" {
name = "cft-gke-test-${random_string.suffix.result}"
ip_cidr_range = "10.0.0.0/17"
region = var.region
network = google_compute_network.main.self_link

secondary_ip_range {
range_name = "cft-gke-test-pods-${random_string.suffix.result}"
ip_cidr_range = "192.168.0.0/18"
}

secondary_ip_range {
range_name = "cft-gke-test-services-${random_string.suffix.result}"
ip_cidr_range = "192.168.64.0/18"
}
}

84 changes: 84 additions & 0 deletions test/fixtures/beta_cluster/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
/**
* Copyright 2018 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_id
}

output "region" {
value = module.this.region
}

output "cluster_name" {
description = "Cluster name"
value = module.this.name
}

output "network" {
value = google_compute_network.main.name
}

output "subnetwork" {
value = google_compute_subnetwork.main.name
}

output "location" {
value = module.this.location
}

output "ip_range_pods" {
description = "The secondary IP range used for pods"
value = google_compute_subnetwork.main.secondary_ip_range[0].range_name
}

output "ip_range_services" {
description = "The secondary IP range used for services"
value = google_compute_subnetwork.main.secondary_ip_range[1].range_name
}

output "zones" {
description = "List of zones in which the cluster resides"
value = module.this.zones
}

output "master_kubernetes_version" {
description = "The master Kubernetes version"
value = module.this.master_version
}

output "kubernetes_endpoint" {
sensitive = true
value = module.this.endpoint
}

output "client_token" {
sensitive = true
value = base64encode(data.google_client_config.default.access_token)
}

output "ca_certificate" {
description = "The cluster CA certificate"
value = module.this.ca_certificate
}

output "service_account" {
description = "The service account to default running nodes as if not overridden in `node_pools`."
value = module.this.service_account
}

output "database_encryption_key_name" {
value = google_kms_crypto_key.db.self_link
}
1 change: 1 addition & 0 deletions test/fixtures/beta_cluster/variables.tf
Loading

0 comments on commit 836c69b

Please sign in to comment.