Skip to content

Commit 84d0b8c

Browse files
committed
Add test for simple instance template with sa craetion
1 parent 99db651 commit 84d0b8c

File tree

18 files changed

+414
-308
lines changed

18 files changed

+414
-308
lines changed

build/int.cloudbuild.yaml

Lines changed: 239 additions & 224 deletions
Large diffs are not rendered by default.

examples/instance_template/simple_with_sa_creation/README.md

Lines changed: 0 additions & 25 deletions
This file was deleted.

examples/instance_template/simple_with_sa_creation/main.tf

Lines changed: 0 additions & 47 deletions
This file was deleted.
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# instance-template-simple
2+
3+
This is a simple, minimal example of how to use the instance_template module.
4+
5+
<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
6+
## Inputs
7+
8+
| Name | Description | Type | Default | Required |
9+
|------|-------------|------|---------|:--------:|
10+
| project\_id | The GCP project to use for integration tests | `string` | n/a | yes |
11+
12+
## Outputs
13+
14+
| Name | Description |
15+
|------|-------------|
16+
| name | Name of the instance templates |
17+
| project\_id | The GCP project to use for integration tests |
18+
| self\_link | Self-link to the instance template |
19+
20+
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
/**
2+
* Copyright 2025 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
provider "google" {
18+
19+
project = var.project_id
20+
region = "us-central1"
21+
}
22+
23+
resource "google_compute_address" "ip_address" {
24+
name = "external-ip"
25+
}
26+
27+
locals {
28+
access_config = {
29+
nat_ip = google_compute_address.ip_address.address
30+
network_tier = "PREMIUM"
31+
}
32+
}
33+
34+
resource "random_string" "suffix" {
35+
length = 4
36+
special = "false"
37+
upper = "false"
38+
}
39+
40+
resource "google_compute_network" "main" {
41+
project = var.project_id
42+
name = "cft-vm-test-${random_string.suffix.result}"
43+
auto_create_subnetworks = "false"
44+
}
45+
46+
resource "google_compute_subnetwork" "main" {
47+
project = var.project_id
48+
region = "us-central1"
49+
name = "cft-vm-test-${random_string.suffix.result}"
50+
ip_cidr_range = "10.128.0.0/20"
51+
network = google_compute_network.main.self_link
52+
}
53+
54+
module "instance_template" {
55+
source = "terraform-google-modules/vm/google//modules/instance_template"
56+
version = "~> 13.0"
57+
58+
project_id = var.project_id
59+
region = "us-central1"
60+
subnetwork = google_compute_subnetwork.main.self_link
61+
stack_type = "IPV4_ONLY"
62+
name_prefix = "it-simple-sa"
63+
tags = ["foo", "bar", "sa"]
64+
labels = {
65+
environment = "dev"
66+
}
67+
access_config = [local.access_config]
68+
enable_nested_virtualization = false
69+
threads_per_core = null
70+
service_account_project_roles = ["roles/compute.admin"]
71+
}

examples/instance_template/simple_with_sa_creation/outputs.tf renamed to examples/it_simple_with_sa_creation/outputs.tf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,7 @@ output "name" {
2424
value = module.instance_template.name
2525
}
2626

27+
output "project_id" {
28+
description = "The GCP project to use for integration tests"
29+
value = var.project_id
30+
}

examples/instance_template/simple_with_sa_creation/variables.tf renamed to examples/it_simple_with_sa_creation/variables.tf

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,3 @@ variable "project_id" {
2020
description = "The GCP project to use for integration tests"
2121
type = string
2222
}
23-
24-
variable "tags" {
25-
type = list(string)
26-
description = "Network tags, provided as a list"
27-
}
28-
29-
variable "labels" {
30-
type = map(string)
31-
description = "Labels, provided as a map"
32-
}

metadata.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ spec:
6464
location: examples/umig/full
6565
- name: healthcheck
6666
location: examples/mig/healthcheck
67+
- name: it_simple_with_sa_creation
68+
location: examples/it_simple_with_sa_creation
6769
- name: mig_stateful
6870
location: examples/mig_stateful
6971
- name: multiple_interfaces
@@ -96,7 +98,9 @@ spec:
9698
- roles/compute.admin
9799
- roles/compute.networkAdmin
98100
- roles/iam.serviceAccountUser
101+
- roles/iam.serviceAccountAdmin
99102
- roles/compute.instanceAdmin
103+
- roles/resourcemanager.projectIamAdmin
100104
services:
101105
- cloudresourcemanager.googleapis.com
102106
- storage-api.googleapis.com

modules/compute_disk_snapshot/metadata.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ spec:
5454
location: examples/umig/full
5555
- name: healthcheck
5656
location: examples/mig/healthcheck
57+
- name: it_simple_with_sa_creation
58+
location: examples/it_simple_with_sa_creation
5759
- name: mig_stateful
5860
location: examples/mig_stateful
5961
- name: multiple_interfaces
@@ -162,7 +164,9 @@ spec:
162164
- roles/compute.admin
163165
- roles/compute.networkAdmin
164166
- roles/iam.serviceAccountUser
167+
- roles/iam.serviceAccountAdmin
165168
- roles/compute.instanceAdmin
169+
- roles/resourcemanager.projectIamAdmin
166170
services:
167171
- cloudresourcemanager.googleapis.com
168172
- storage-api.googleapis.com

modules/compute_instance/metadata.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ spec:
5454
location: examples/umig/full
5555
- name: healthcheck
5656
location: examples/mig/healthcheck
57+
- name: it_simple_with_sa_creation
58+
location: examples/it_simple_with_sa_creation
5759
- name: mig_stateful
5860
location: examples/mig_stateful
5961
- name: multiple_interfaces
@@ -173,7 +175,9 @@ spec:
173175
- roles/compute.admin
174176
- roles/compute.networkAdmin
175177
- roles/iam.serviceAccountUser
178+
- roles/iam.serviceAccountAdmin
176179
- roles/compute.instanceAdmin
180+
- roles/resourcemanager.projectIamAdmin
177181
services:
178182
- cloudresourcemanager.googleapis.com
179183
- storage-api.googleapis.com

0 commit comments

Comments
 (0)