Merge pull request #1138 from GoogleCloudPlatform/jccb/compute-vm-examples

New compute-vm examples and tests
This commit is contained in:
Julio Castillo
2023-02-07 17:48:30 +01:00
committed by GitHub
108 changed files with 967 additions and 648 deletions

View File

@@ -17,11 +17,11 @@ terraform {
required_providers {
google = {
source = "hashicorp/google"
version = ">= 4.48.0" # tftest
version = ">= 4.50.0" # tftest
}
google-beta = {
source = "hashicorp/google-beta"
version = ">= 4.48.0" # tftest
version = ">= 4.50.0" # tftest
}
}
}

View File

@@ -17,11 +17,11 @@ terraform {
required_providers {
google = {
source = "hashicorp/google"
version = ">= 4.48.0" # tftest
version = ">= 4.50.0" # tftest
}
google-beta = {
source = "hashicorp/google-beta"
version = ">= 4.48.0" # tftest
version = ">= 4.50.0" # tftest
}
}
}

View File

@@ -17,11 +17,11 @@ terraform {
required_providers {
google = {
source = "hashicorp/google"
version = ">= 4.48.0" # tftest
version = ">= 4.50.0" # tftest
}
google-beta = {
source = "hashicorp/google-beta"
version = ">= 4.48.0" # tftest
version = ">= 4.50.0" # tftest
}
}
}

View File

@@ -17,11 +17,11 @@ terraform {
required_providers {
google = {
source = "hashicorp/google"
version = ">= 4.48.0" # tftest
version = ">= 4.50.0" # tftest
}
google-beta = {
source = "hashicorp/google-beta"
version = ">= 4.48.0" # tftest
version = ">= 4.50.0" # tftest
}
}
}

View File

@@ -17,11 +17,11 @@ terraform {
required_providers {
google = {
source = "hashicorp/google"
version = ">= 4.48.0" # tftest
version = ">= 4.50.0" # tftest
}
google-beta = {
source = "hashicorp/google-beta"
version = ">= 4.48.0" # tftest
version = ">= 4.50.0" # tftest
}
}
}

View File

@@ -17,11 +17,11 @@ terraform {
required_providers {
google = {
source = "hashicorp/google"
version = ">= 4.48.0" # tftest
version = ">= 4.50.0" # tftest
}
google-beta = {
source = "hashicorp/google-beta"
version = ">= 4.48.0" # tftest
version = ">= 4.50.0" # tftest
}
}
}

View File

@@ -17,11 +17,11 @@ terraform {
required_providers {
google = {
source = "hashicorp/google"
version = ">= 4.48.0" # tftest
version = ">= 4.50.0" # tftest
}
google-beta = {
source = "hashicorp/google-beta"
version = ">= 4.48.0" # tftest
version = ">= 4.50.0" # tftest
}
}
}

View File

@@ -17,11 +17,11 @@ terraform {
required_providers {
google = {
source = "hashicorp/google"
version = ">= 4.48.0" # tftest
version = ">= 4.50.0" # tftest
}
google-beta = {
source = "hashicorp/google-beta"
version = ">= 4.48.0" # tftest
version = ">= 4.50.0" # tftest
}
}
}

View File

@@ -17,11 +17,11 @@ terraform {
required_providers {
google = {
source = "hashicorp/google"
version = ">= 4.48.0" # tftest
version = ">= 4.50.0" # tftest
}
google-beta = {
source = "hashicorp/google-beta"
version = ">= 4.48.0" # tftest
version = ">= 4.50.0" # tftest
}
}
}

View File

@@ -17,11 +17,11 @@ terraform {
required_providers {
google = {
source = "hashicorp/google"
version = ">= 4.48.0" # tftest
version = ">= 4.50.0" # tftest
}
google-beta = {
source = "hashicorp/google-beta"
version = ">= 4.48.0" # tftest
version = ">= 4.50.0" # tftest
}
}
}

View File

@@ -17,11 +17,11 @@ terraform {
required_providers {
google = {
source = "hashicorp/google"
version = ">= 4.48.0" # tftest
version = ">= 4.50.0" # tftest
}
google-beta = {
source = "hashicorp/google-beta"
version = ">= 4.48.0" # tftest
version = ">= 4.50.0" # tftest
}
}
}

View File

@@ -17,11 +17,11 @@ terraform {
required_providers {
google = {
source = "hashicorp/google"
version = ">= 4.48.0" # tftest
version = ">= 4.50.0" # tftest
}
google-beta = {
source = "hashicorp/google-beta"
version = ">= 4.48.0" # tftest
version = ">= 4.50.0" # tftest
}
}
}

View File

@@ -17,11 +17,11 @@ terraform {
required_providers {
google = {
source = "hashicorp/google"
version = ">= 4.48.0" # tftest
version = ">= 4.50.0" # tftest
}
google-beta = {
source = "hashicorp/google-beta"
version = ">= 4.48.0" # tftest
version = ">= 4.50.0" # tftest
}
}
}

View File

@@ -17,11 +17,11 @@ terraform {
required_providers {
google = {
source = "hashicorp/google"
version = ">= 4.48.0" # tftest
version = ">= 4.50.0" # tftest
}
google-beta = {
source = "hashicorp/google-beta"
version = ">= 4.48.0" # tftest
version = ">= 4.50.0" # tftest
}
}
}

View File

@@ -17,11 +17,11 @@ terraform {
required_providers {
google = {
source = "hashicorp/google"
version = ">= 4.48.0" # tftest
version = ">= 4.50.0" # tftest
}
google-beta = {
source = "hashicorp/google-beta"
version = ">= 4.48.0" # tftest
version = ">= 4.50.0" # tftest
}
}
}

View File

@@ -17,11 +17,11 @@ terraform {
required_providers {
google = {
source = "hashicorp/google"
version = ">= 4.48.0" # tftest
version = ">= 4.50.0" # tftest
}
google-beta = {
source = "hashicorp/google-beta"
version = ">= 4.48.0" # tftest
version = ">= 4.50.0" # tftest
}
}
}

View File

@@ -17,11 +17,11 @@ terraform {
required_providers {
google = {
source = "hashicorp/google"
version = ">= 4.48.0" # tftest
version = ">= 4.50.0" # tftest
}
google-beta = {
source = "hashicorp/google-beta"
version = ">= 4.48.0" # tftest
version = ">= 4.50.0" # tftest
}
}
}

View File

@@ -17,11 +17,11 @@ terraform {
required_providers {
google = {
source = "hashicorp/google"
version = ">= 4.48.0" # tftest
version = ">= 4.50.0" # tftest
}
google-beta = {
source = "hashicorp/google-beta"
version = ">= 4.48.0" # tftest
version = ">= 4.50.0" # tftest
}
}
}

View File

@@ -17,11 +17,11 @@ terraform {
required_providers {
google = {
source = "hashicorp/google"
version = ">= 4.48.0" # tftest
version = ">= 4.50.0" # tftest
}
google-beta = {
source = "hashicorp/google-beta"
version = ">= 4.48.0" # tftest
version = ">= 4.50.0" # tftest
}
}
}

View File

@@ -17,11 +17,11 @@ terraform {
required_providers {
google = {
source = "hashicorp/google"
version = ">= 4.48.0" # tftest
version = ">= 4.50.0" # tftest
}
google-beta = {
source = "hashicorp/google-beta"
version = ">= 4.48.0" # tftest
version = ">= 4.50.0" # tftest
}
}
}

View File

@@ -17,11 +17,11 @@ terraform {
required_providers {
google = {
source = "hashicorp/google"
version = ">= 4.48.0" # tftest
version = ">= 4.50.0" # tftest
}
google-beta = {
source = "hashicorp/google-beta"
version = ">= 4.48.0" # tftest
version = ">= 4.50.0" # tftest
}
}
}

View File

@@ -17,11 +17,11 @@ terraform {
required_providers {
google = {
source = "hashicorp/google"
version = ">= 4.48.0" # tftest
version = ">= 4.50.0" # tftest
}
google-beta = {
source = "hashicorp/google-beta"
version = ">= 4.48.0" # tftest
version = ">= 4.50.0" # tftest
}
}
}

View File

@@ -17,11 +17,11 @@ terraform {
required_providers {
google = {
source = "hashicorp/google"
version = ">= 4.48.0" # tftest
version = ">= 4.50.0" # tftest
}
google-beta = {
source = "hashicorp/google-beta"
version = ">= 4.48.0" # tftest
version = ">= 4.50.0" # tftest
}
}
}

View File

@@ -17,11 +17,11 @@ terraform {
required_providers {
google = {
source = "hashicorp/google"
version = ">= 4.48.0" # tftest
version = ">= 4.50.0" # tftest
}
google-beta = {
source = "hashicorp/google-beta"
version = ">= 4.48.0" # tftest
version = ">= 4.50.0" # tftest
}
}
}

View File

@@ -17,11 +17,11 @@ terraform {
required_providers {
google = {
source = "hashicorp/google"
version = ">= 4.48.0" # tftest
version = ">= 4.50.0" # tftest
}
google-beta = {
source = "hashicorp/google-beta"
version = ">= 4.48.0" # tftest
version = ">= 4.50.0" # tftest
}
}
}

View File

@@ -17,11 +17,11 @@ terraform {
required_providers {
google = {
source = "hashicorp/google"
version = ">= 4.48.0" # tftest
version = ">= 4.50.0" # tftest
}
google-beta = {
source = "hashicorp/google-beta"
version = ">= 4.48.0" # tftest
version = ">= 4.50.0" # tftest
}
}
}

View File

@@ -17,11 +17,11 @@ terraform {
required_providers {
google = {
source = "hashicorp/google"
version = ">= 4.48.0" # tftest
version = ">= 4.50.0" # tftest
}
google-beta = {
source = "hashicorp/google-beta"
version = ">= 4.48.0" # tftest
version = ">= 4.50.0" # tftest
}
}
}

View File

@@ -17,11 +17,11 @@ terraform {
required_providers {
google = {
source = "hashicorp/google"
version = ">= 4.48.0" # tftest
version = ">= 4.50.0" # tftest
}
google-beta = {
source = "hashicorp/google-beta"
version = ">= 4.48.0" # tftest
version = ">= 4.50.0" # tftest
}
}
}

View File

@@ -17,11 +17,11 @@ terraform {
required_providers {
google = {
source = "hashicorp/google"
version = ">= 4.48.0" # tftest
version = ">= 4.50.0" # tftest
}
google-beta = {
source = "hashicorp/google-beta"
version = ">= 4.48.0" # tftest
version = ">= 4.50.0" # tftest
}
}
}

View File

@@ -17,11 +17,11 @@ terraform {
required_providers {
google = {
source = "hashicorp/google"
version = ">= 4.48.0" # tftest
version = ">= 4.50.0" # tftest
}
google-beta = {
source = "hashicorp/google-beta"
version = ">= 4.48.0" # tftest
version = ">= 4.50.0" # tftest
}
}
}

View File

@@ -17,11 +17,11 @@ terraform {
required_providers {
google = {
source = "hashicorp/google"
version = ">= 4.48.0" # tftest
version = ">= 4.50.0" # tftest
}
google-beta = {
source = "hashicorp/google-beta"
version = ">= 4.48.0" # tftest
version = ">= 4.50.0" # tftest
}
}
}

View File

@@ -17,11 +17,11 @@ terraform {
required_providers {
google = {
source = "hashicorp/google"
version = ">= 4.48.0" # tftest
version = ">= 4.50.0" # tftest
}
google-beta = {
source = "hashicorp/google-beta"
version = ">= 4.48.0" # tftest
version = ">= 4.50.0" # tftest
}
}
}

View File

@@ -17,11 +17,11 @@ terraform {
required_providers {
google = {
source = "hashicorp/google"
version = ">= 4.48.0" # tftest
version = ">= 4.50.0" # tftest
}
google-beta = {
source = "hashicorp/google-beta"
version = ">= 4.48.0" # tftest
version = ">= 4.50.0" # tftest
}
}
}

View File

@@ -17,11 +17,11 @@ terraform {
required_providers {
google = {
source = "hashicorp/google"
version = ">= 4.48.0" # tftest
version = ">= 4.50.0" # tftest
}
google-beta = {
source = "hashicorp/google-beta"
version = ">= 4.48.0" # tftest
version = ">= 4.50.0" # tftest
}
}
}

View File

@@ -17,11 +17,11 @@ terraform {
required_providers {
google = {
source = "hashicorp/google"
version = ">= 4.48.0" # tftest
version = ">= 4.50.0" # tftest
}
google-beta = {
source = "hashicorp/google-beta"
version = ">= 4.48.0" # tftest
version = ">= 4.50.0" # tftest
}
}
}

View File

@@ -17,11 +17,11 @@ terraform {
required_providers {
google = {
source = "hashicorp/google"
version = ">= 4.48.0" # tftest
version = ">= 4.50.0" # tftest
}
google-beta = {
source = "hashicorp/google-beta"
version = ">= 4.48.0" # tftest
version = ">= 4.50.0" # tftest
}
}
}

View File

@@ -17,11 +17,11 @@ terraform {
required_providers {
google = {
source = "hashicorp/google"
version = ">= 4.48.0" # tftest
version = ">= 4.50.0" # tftest
}
google-beta = {
source = "hashicorp/google-beta"
version = ">= 4.48.0" # tftest
version = ">= 4.50.0" # tftest
}
}
}

View File

@@ -17,11 +17,11 @@ terraform {
required_providers {
google = {
source = "hashicorp/google"
version = ">= 4.48.0" # tftest
version = ">= 4.50.0" # tftest
}
google-beta = {
source = "hashicorp/google-beta"
version = ">= 4.48.0" # tftest
version = ">= 4.50.0" # tftest
}
}
}

View File

@@ -17,11 +17,11 @@ terraform {
required_providers {
google = {
source = "hashicorp/google"
version = ">= 4.48.0" # tftest
version = ">= 4.50.0" # tftest
}
google-beta = {
source = "hashicorp/google-beta"
version = ">= 4.48.0" # tftest
version = ">= 4.50.0" # tftest
}
}
}

View File

@@ -17,11 +17,11 @@ terraform {
required_providers {
google = {
source = "hashicorp/google"
version = ">= 4.48.0" # tftest
version = ">= 4.50.0" # tftest
}
google-beta = {
source = "hashicorp/google-beta"
version = ">= 4.48.0" # tftest
version = ">= 4.50.0" # tftest
}
}
}

View File

@@ -17,11 +17,11 @@ terraform {
required_providers {
google = {
source = "hashicorp/google"
version = ">= 4.48.0" # tftest
version = ">= 4.50.0" # tftest
}
google-beta = {
source = "hashicorp/google-beta"
version = ">= 4.48.0" # tftest
version = ">= 4.50.0" # tftest
}
}
}

View File

@@ -17,11 +17,11 @@ terraform {
required_providers {
google = {
source = "hashicorp/google"
version = ">= 4.48.0" # tftest
version = ">= 4.50.0" # tftest
}
google-beta = {
source = "hashicorp/google-beta"
version = ">= 4.48.0" # tftest
version = ">= 4.50.0" # tftest
}
}
}

View File

@@ -17,11 +17,11 @@ terraform {
required_providers {
google = {
source = "hashicorp/google"
version = ">= 4.48.0" # tftest
version = ">= 4.50.0" # tftest
}
google-beta = {
source = "hashicorp/google-beta"
version = ">= 4.48.0" # tftest
version = ">= 4.50.0" # tftest
}
}
}

View File

@@ -17,11 +17,11 @@ terraform {
required_providers {
google = {
source = "hashicorp/google"
version = ">= 4.48.0" # tftest
version = ">= 4.50.0" # tftest
}
google-beta = {
source = "hashicorp/google-beta"
version = ">= 4.48.0" # tftest
version = ">= 4.50.0" # tftest
}
}
}

View File

@@ -17,11 +17,11 @@ terraform {
required_providers {
google = {
source = "hashicorp/google"
version = ">= 4.48.0" # tftest
version = ">= 4.50.0" # tftest
}
google-beta = {
source = "hashicorp/google-beta"
version = ">= 4.48.0" # tftest
version = ">= 4.50.0" # tftest
}
}
}

View File

@@ -17,11 +17,11 @@ terraform {
required_providers {
google = {
source = "hashicorp/google"
version = ">= 4.48.0" # tftest
version = ">= 4.50.0" # tftest
}
google-beta = {
source = "hashicorp/google-beta"
version = ">= 4.48.0" # tftest
version = ">= 4.50.0" # tftest
}
}
}

View File

@@ -17,11 +17,11 @@ terraform {
required_providers {
google = {
source = "hashicorp/google"
version = ">= 4.48.0" # tftest
version = ">= 4.50.0" # tftest
}
google-beta = {
source = "hashicorp/google-beta"
version = ">= 4.48.0" # tftest
version = ">= 4.50.0" # tftest
}
}
}

View File

@@ -17,11 +17,11 @@ terraform {
required_providers {
google = {
source = "hashicorp/google"
version = ">= 4.48.0" # tftest
version = ">= 4.50.0" # tftest
}
google-beta = {
source = "hashicorp/google-beta"
version = ">= 4.48.0" # tftest
version = ">= 4.50.0" # tftest
}
}
}

View File

@@ -17,11 +17,11 @@ terraform {
required_providers {
google = {
source = "hashicorp/google"
version = ">= 4.48.0" # tftest
version = ">= 4.50.0" # tftest
}
google-beta = {
source = "hashicorp/google-beta"
version = ">= 4.48.0" # tftest
version = ">= 4.50.0" # tftest
}
}
}

View File

@@ -17,11 +17,11 @@ terraform {
required_providers {
google = {
source = "hashicorp/google"
version = ">= 4.48.0" # tftest
version = ">= 4.50.0" # tftest
}
google-beta = {
source = "hashicorp/google-beta"
version = ">= 4.48.0" # tftest
version = ">= 4.50.0" # tftest
}
}
}

View File

@@ -8,6 +8,23 @@ This module can operate in two distinct modes:
In both modes, an optional service account can be created and assigned to either instances or template. If you need a managed instance group when using the module in template mode, refer to the [`compute-mig`](../compute-mig) module.
## Examples
- [Instance using defaults](#instance-using-defaults)
- [Service account management](#service-account-management)
- [Disk management](#disk-management)
- [Disk sources](#disk-sources)
- [Disk types and options](#disk-types-and-options)
- [Network interfaces](#network-interfaces)
- [Internal and external IPs](#internal-and-external-ips)
- [Using Alias IPs](#using-alias-ips)
- [Using gVNIC](#using-gvnic)
- [Metadata](#metadata)
- [IAM](#iam)
- [Spot VM](#spot-vm)
- [Confidential compute](#confidential-compute)
- [Disk encryption with Cloud KMS](#disk-encryption-with-cloud-kms)
- [Instance template](#instance-template)
- [Instance group](#instance-group)
### Instance using defaults
@@ -25,47 +42,73 @@ module "simple-vm-example" {
}]
service_account_create = true
}
# tftest modules=1 resources=2
# tftest modules=1 resources=2 inventory=simple.yaml
```
### Spot VM
### Service account management
[Spot VMs](https://cloud.google.com/compute/docs/instances/spot) are ephemeral compute instances suitable for batch jobs and fault-tolerant workloads. Spot VMs provide new features that [preemptible instances](https://cloud.google.com/compute/docs/instances/preemptible) do not support, such as the absence of a maximum runtime.
VM service accounts can be managed in three different ways:
- You can let the module create a service account for you by settting `service_account_create = true`
- You can use an existing service account by setting `service_account_create = false` (the default value) and passing the full email address of the service account to the `service_account` variable. This is useful, for example, if you want to reuse the service account from another previously created instance, or if you want to create the service account manually with the `iam-service-account` module. In this case, you probably also want to set `service_account_scopes` to `cloud-platform`.
- Lastly, you can use the default compute service account by setting `service_account_crate = false`. Please note that using the default compute service account is not recommended.
```hcl
module "spot-vm-example" {
module "vm-managed-sa-example" {
source = "./fabric/modules/compute-vm"
project_id = var.project_id
zone = "europe-west1-b"
name = "test"
options = {
spot = true
termination_action = "STOP"
}
name = "test1"
network_interfaces = [{
network = var.vpc.self_link
subnetwork = var.subnet.self_link
}]
service_account_create = true
}
# tftest modules=1 resources=2
module "vm-managed-sa-example2" {
source = "./fabric/modules/compute-vm"
project_id = var.project_id
zone = "europe-west1-b"
name = "test2"
network_interfaces = [{
network = var.vpc.self_link
subnetwork = var.subnet.self_link
}]
service_account = module.vm-managed-sa-example.service_account_email
service_account_scopes = ["cloud-platform"]
}
# not recommended
module "vm-default-sa-example2" {
source = "./fabric/modules/compute-vm"
project_id = var.project_id
zone = "europe-west1-b"
name = "test3"
network_interfaces = [{
network = var.vpc.self_link
subnetwork = var.subnet.self_link
}]
service_account_create = false
}
# tftest modules=3 resources=4 inventory=sas.yaml
```
### Disk sources
### Disk management
#### Disk sources
Attached disks can be created and optionally initialized from a pre-existing source, or attached to VMs when pre-existing. The `source` and `source_type` attributes of the `attached_disks` variable allows several modes of operation:
- `source_type = "image"` can be used with zonal disks in instances and templates, set `source` to the image name or link
- `source_type = "snapshot"` can be used with instances only, set `source` to the snapshot name or link
- `source_type = "attach"` can be used for both instances and templates to attach an existing disk, set source to the name (for zonal disks) or link (for regional disks) of the existing disk to attach; no disk will be created
- `source_type = "image"` can be used with zonal disks in instances and templates, set `source` to the image name or self link
- `source_type = "snapshot"` can be used with instances only, set `source` to the snapshot name or self link
- `source_type = "attach"` can be used for both instances and templates to attach an existing disk, set source to the name (for zonal disks) or self link (for regional disks) of the existing disk to attach; no disk will be created
- `source_type = null` can be used where an empty disk is needed, `source` becomes irrelevant and can be left null
This is an example of attaching a pre-existing regional PD to a new instance:
```hcl
module "simple-vm-example" {
module "vm-disks-example" {
source = "./fabric/modules/compute-vm"
project_id = var.project_id
zone = "${var.region}-b"
@@ -91,7 +134,7 @@ module "simple-vm-example" {
And the same example for an instance template (where not using the full self link of the disk triggers recreation of the template)
```hcl
module "simple-vm-example" {
module "vm-disks-example" {
source = "./fabric/modules/compute-vm"
project_id = var.project_id
zone = "${var.region}-b"
@@ -115,39 +158,82 @@ module "simple-vm-example" {
# tftest modules=1 resources=2
```
### Disk encryption with Cloud KMS
#### Disk types and options
This example shows how to control disk encryption via the the `encryption` variable, in this case the self link to a KMS CryptoKey that will be used to encrypt boot and attached disk. Managing the key with the `../kms` module is of course possible, but is not shown here.
The `attached_disks` variable exposes an `option` attribute that can be used to fine tune the configuration of each disk. The following example shows a VM with multiple disks
```hcl
module "kms-vm-example" {
module "vm-disk-options-example" {
source = "./fabric/modules/compute-vm"
project_id = var.project_id
zone = "europe-west1-b"
name = "kms-test"
name = "test"
network_interfaces = [{
network = var.vpc.self_link
subnetwork = var.subnet.self_link
}]
attached_disks = [
{
name = "attached-disk"
size = 10
name = "data1"
size = "10"
source_type = "image"
source = "image-1"
options = {
auto_delete = false
replica_zone = "europe-west1-c"
}
},
{
name = "data2"
size = "20"
source_type = "snapshot"
source = "snapshot-2"
options = {
type = "pd-ssd"
mode = "READ_ONLY"
}
}
]
service_account_create = true
boot_disk = {
image = "projects/debian-cloud/global/images/family/debian-10"
}
encryption = {
encrypt_boot = true
kms_key_self_link = var.kms_key.self_link
}
}
# tftest modules=1 resources=3
# tftest modules=1 resources=4 inventory=disk-options.yaml
```
### Using Alias IPs
### Network interfaces
#### Internal and external IPs
By default VNs are create with an automatically assigned IP addresses, but you can change it through the `addreses` and `nat` attributes of the `network_interfaces` variable:
```hcl
module "vm-internal-ip" {
source = "./fabric/modules/compute-vm"
project_id = "my-project"
zone = "europe-west1-b"
name = "vm-internal-ip"
network_interfaces = [{
network = var.vpc.self_link
subnetwork = var.subnet.self_link
addresses = { external = null, internal = "10.0.0.2" }
}]
}
module "vm-external-ip" {
source = "./fabric/modules/compute-vm"
project_id = "my-project"
zone = "europe-west1-b"
name = "vm-external-ip"
network_interfaces = [{
network = var.vpc.self_link
subnetwork = var.subnet.self_link
nat = true
addresses = { external = "8.8.8.8", internal = null }
}]
}
# tftest modules=2 resources=2 inventory=ips.yaml
```
#### Using Alias IPs
This example shows how to add additional [Alias IPs](https://cloud.google.com/vpc/docs/alias-ip) to your VM.
@@ -164,12 +250,11 @@ module "vm-with-alias-ips" {
alias1 = "10.16.0.10/32"
}
}]
service_account_create = true
}
# tftest modules=1 resources=2
# tftest modules=1 resources=1 inventory=alias-ips.yaml
```
### Using gVNIC
#### Using gVNIC
This example shows how to enable [gVNIC](https://cloud.google.com/compute/docs/networking/using-gvnic) on your VM by customizing a `cos` image. Given that gVNIC needs to be enabled as an instance configuration and as a guest os configuration, you'll need to supply a bootable disk with `guest_os_features=GVNIC`. `SEV_CAPABLE`, `UEFI_COMPATIBLE` and `VIRTIO_SCSI_MULTIQUEUE` are enabled implicitly in the `cos`, `rhel`, `centos` and other images.
@@ -210,9 +295,151 @@ module "vm-with-gvnic" {
}]
service_account_create = true
}
# tftest modules=1 resources=3
# tftest modules=1 resources=3 inventory=gvnic.yaml
```
### Metadata
You can define labels and custom metadata values. Metadata can be leveraged, for example, to define a custom startup script.
```hcl
module "vm-metadata-example" {
source = "./fabric/modules/compute-vm"
project_id = var.project_id
zone = "europe-west1-b"
name = "nginx-server"
network_interfaces = [{
network = var.vpc.self_link
subnetwork = var.subnet.self_link
}]
labels = {
env = "dev"
system = "crm"
}
metadata = {
startup-script = <<-EOF
#! /bin/bash
apt-get update
apt-get install -y nginx
EOF
}
service_account_create = true
}
# tftest modules=1 resources=2 inventory=metadata.yaml
```
### IAM
Like most modules, you can assign IAM roles to the instance using the `iam` variable.
```hcl
module "vm-iam-example" {
source = "./fabric/modules/compute-vm"
project_id = var.project_id
zone = "europe-west1-b"
name = "webserver"
network_interfaces = [{
network = var.vpc.self_link
subnetwork = var.subnet.self_link
}]
iam = {
"roles/compute.instanceAdmin" = [
"group:webserver@example.com",
"group:admin@example.com"
]
}
}
# tftest modules=1 resources=2 inventory=iam.yaml
```
### Spot VM
[Spot VMs](https://cloud.google.com/compute/docs/instances/spot) are ephemeral compute instances suitable for batch jobs and fault-tolerant workloads. Spot VMs provide new features that [preemptible instances](https://cloud.google.com/compute/docs/instances/preemptible) do not support, such as the absence of a maximum runtime.
```hcl
module "spot-vm-example" {
source = "./fabric/modules/compute-vm"
project_id = var.project_id
zone = "europe-west1-b"
name = "test"
options = {
spot = true
termination_action = "STOP"
}
network_interfaces = [{
network = var.vpc.self_link
subnetwork = var.subnet.self_link
}]
}
# tftest modules=1 resources=1 inventory=spot.yaml
```
### Confidential compute
You can enable confidential compute with the `confidential_compute` variable, which can be used for standalone instances or for instance templates.
```hcl
module "vm-confidential-example" {
source = "./fabric/modules/compute-vm"
project_id = var.project_id
zone = "europe-west1-b"
name = "confidential-vm"
confidential_compute = true
network_interfaces = [{
network = var.vpc.self_link
subnetwork = var.subnet.self_link
}]
}
module "template-confidential-example" {
source = "./fabric/modules/compute-vm"
project_id = var.project_id
zone = "europe-west1-b"
name = "confidential-template"
confidential_compute = true
create_template = true
network_interfaces = [{
network = var.vpc.self_link
subnetwork = var.subnet.self_link
}]
}
# tftest modules=2 resources=2 inventory=confidential.yaml
```
### Disk encryption with Cloud KMS
This example shows how to control disk encryption via the the `encryption` variable, in this case the self link to a KMS CryptoKey that will be used to encrypt boot and attached disk. Managing the key with the `../kms` module is of course possible, but is not shown here.
```hcl
module "kms-vm-example" {
source = "./fabric/modules/compute-vm"
project_id = var.project_id
zone = "europe-west1-b"
name = "kms-test"
network_interfaces = [{
network = var.vpc.self_link
subnetwork = var.subnet.self_link
}]
attached_disks = [{
name = "attached-disk"
size = 10
}]
service_account_create = true
boot_disk = {
image = "projects/debian-cloud/global/images/family/debian-10"
}
encryption = {
encrypt_boot = true
kms_key_self_link = var.kms_key.self_link
}
}
# tftest modules=1 resources=3 inventory=cmek.yaml
```
### Instance template
This example shows how to use the module to manage an instance template that defines an additional attached disk for each instance, and overrides defaults for the boot disk image and service account.
@@ -239,7 +466,7 @@ module "cos-test" {
service_account = "vm-default@my-project.iam.gserviceaccount.com"
create_template = true
}
# tftest modules=1 resources=1
# tftest modules=1 resources=1 inventory=template.yaml
```
### Instance group
@@ -270,7 +497,7 @@ module "instance-group" {
}
group = { named_ports = {} }
}
# tftest modules=1 resources=2
# tftest modules=1 resources=2 inventory=group.yaml
```
<!-- BEGIN TFDOC -->

View File

@@ -17,11 +17,11 @@ terraform {
required_providers {
google = {
source = "hashicorp/google"
version = ">= 4.48.0" # tftest
version = ">= 4.50.0" # tftest
}
google-beta = {
source = "hashicorp/google-beta"
version = ">= 4.48.0" # tftest
version = ">= 4.50.0" # tftest
}
}
}

View File

@@ -17,11 +17,11 @@ terraform {
required_providers {
google = {
source = "hashicorp/google"
version = ">= 4.48.0" # tftest
version = ">= 4.50.0" # tftest
}
google-beta = {
source = "hashicorp/google-beta"
version = ">= 4.48.0" # tftest
version = ">= 4.50.0" # tftest
}
}
}

View File

@@ -17,11 +17,11 @@ terraform {
required_providers {
google = {
source = "hashicorp/google"
version = ">= 4.48.0" # tftest
version = ">= 4.50.0" # tftest
}
google-beta = {
source = "hashicorp/google-beta"
version = ">= 4.48.0" # tftest
version = ">= 4.50.0" # tftest
}
}
}

View File

@@ -17,11 +17,11 @@ terraform {
required_providers {
google = {
source = "hashicorp/google"
version = ">= 4.48.0" # tftest
version = ">= 4.50.0" # tftest
}
google-beta = {
source = "hashicorp/google-beta"
version = ">= 4.48.0" # tftest
version = ">= 4.50.0" # tftest
}
}
}

View File

@@ -17,11 +17,11 @@ terraform {
required_providers {
google = {
source = "hashicorp/google"
version = ">= 4.48.0" # tftest
version = ">= 4.50.0" # tftest
}
google-beta = {
source = "hashicorp/google-beta"
version = ">= 4.48.0" # tftest
version = ">= 4.50.0" # tftest
}
}
}

View File

@@ -17,11 +17,11 @@ terraform {
required_providers {
google = {
source = "hashicorp/google"
version = ">= 4.48.0" # tftest
version = ">= 4.50.0" # tftest
}
google-beta = {
source = "hashicorp/google-beta"
version = ">= 4.48.0" # tftest
version = ">= 4.50.0" # tftest
}
}
}

View File

@@ -17,11 +17,11 @@ terraform {
required_providers {
google = {
source = "hashicorp/google"
version = ">= 4.48.0" # tftest
version = ">= 4.50.0" # tftest
}
google-beta = {
source = "hashicorp/google-beta"
version = ">= 4.48.0" # tftest
version = ">= 4.50.0" # tftest
}
}
}

View File

@@ -17,11 +17,11 @@ terraform {
required_providers {
google = {
source = "hashicorp/google"
version = ">= 4.48.0" # tftest
version = ">= 4.50.0" # tftest
}
google-beta = {
source = "hashicorp/google-beta"
version = ">= 4.48.0" # tftest
version = ">= 4.50.0" # tftest
}
}
}

View File

@@ -17,11 +17,11 @@ terraform {
required_providers {
google = {
source = "hashicorp/google"
version = ">= 4.48.0" # tftest
version = ">= 4.50.0" # tftest
}
google-beta = {
source = "hashicorp/google-beta"
version = ">= 4.48.0" # tftest
version = ">= 4.50.0" # tftest
}
}
}

View File

@@ -17,11 +17,11 @@ terraform {
required_providers {
google = {
source = "hashicorp/google"
version = ">= 4.48.0" # tftest
version = ">= 4.50.0" # tftest
}
google-beta = {
source = "hashicorp/google-beta"
version = ">= 4.48.0" # tftest
version = ">= 4.50.0" # tftest
}
}
}

View File

@@ -17,11 +17,11 @@ terraform {
required_providers {
google = {
source = "hashicorp/google"
version = ">= 4.48.0" # tftest
version = ">= 4.50.0" # tftest
}
google-beta = {
source = "hashicorp/google-beta"
version = ">= 4.48.0" # tftest
version = ">= 4.50.0" # tftest
}
}
}

View File

@@ -17,11 +17,11 @@ terraform {
required_providers {
google = {
source = "hashicorp/google"
version = ">= 4.48.0" # tftest
version = ">= 4.50.0" # tftest
}
google-beta = {
source = "hashicorp/google-beta"
version = ">= 4.48.0" # tftest
version = ">= 4.50.0" # tftest
}
}
}

View File

@@ -17,11 +17,11 @@ terraform {
required_providers {
google = {
source = "hashicorp/google"
version = ">= 4.48.0" # tftest
version = ">= 4.50.0" # tftest
}
google-beta = {
source = "hashicorp/google-beta"
version = ">= 4.48.0" # tftest
version = ">= 4.50.0" # tftest
}
}
}

View File

@@ -17,11 +17,11 @@ terraform {
required_providers {
google = {
source = "hashicorp/google"
version = ">= 4.48.0" # tftest
version = ">= 4.50.0" # tftest
}
google-beta = {
source = "hashicorp/google-beta"
version = ">= 4.48.0" # tftest
version = ">= 4.50.0" # tftest
}
}
}

View File

@@ -17,11 +17,11 @@ terraform {
required_providers {
google = {
source = "hashicorp/google"
version = ">= 4.48.0" # tftest
version = ">= 4.50.0" # tftest
}
google-beta = {
source = "hashicorp/google-beta"
version = ">= 4.48.0" # tftest
version = ">= 4.50.0" # tftest
}
}
}

View File

@@ -17,11 +17,11 @@ terraform {
required_providers {
google = {
source = "hashicorp/google"
version = ">= 4.48.0" # tftest
version = ">= 4.50.0" # tftest
}
google-beta = {
source = "hashicorp/google-beta"
version = ">= 4.48.0" # tftest
version = ">= 4.50.0" # tftest
}
}
}

View File

@@ -17,11 +17,11 @@ terraform {
required_providers {
google = {
source = "hashicorp/google"
version = ">= 4.48.0" # tftest
version = ">= 4.50.0" # tftest
}
google-beta = {
source = "hashicorp/google-beta"
version = ">= 4.48.0" # tftest
version = ">= 4.50.0" # tftest
}
}
}

View File

@@ -17,11 +17,11 @@ terraform {
required_providers {
google = {
source = "hashicorp/google"
version = ">= 4.48.0" # tftest
version = ">= 4.50.0" # tftest
}
google-beta = {
source = "hashicorp/google-beta"
version = ">= 4.48.0" # tftest
version = ">= 4.50.0" # tftest
}
}
}

View File

@@ -17,11 +17,11 @@ terraform {
required_providers {
google = {
source = "hashicorp/google"
version = ">= 4.48.0" # tftest
version = ">= 4.50.0" # tftest
}
google-beta = {
source = "hashicorp/google-beta"
version = ">= 4.48.0" # tftest
version = ">= 4.50.0" # tftest
}
}
}

View File

@@ -17,11 +17,11 @@ terraform {
required_providers {
google = {
source = "hashicorp/google"
version = ">= 4.48.0" # tftest
version = ">= 4.50.0" # tftest
}
google-beta = {
source = "hashicorp/google-beta"
version = ">= 4.48.0" # tftest
version = ">= 4.50.0" # tftest
}
}
}

View File

@@ -17,11 +17,11 @@ terraform {
required_providers {
google = {
source = "hashicorp/google"
version = ">= 4.48.0" # tftest
version = ">= 4.50.0" # tftest
}
google-beta = {
source = "hashicorp/google-beta"
version = ">= 4.48.0" # tftest
version = ">= 4.50.0" # tftest
}
}
}

View File

@@ -17,11 +17,11 @@ terraform {
required_providers {
google = {
source = "hashicorp/google"
version = ">= 4.48.0" # tftest
version = ">= 4.50.0" # tftest
}
google-beta = {
source = "hashicorp/google-beta"
version = ">= 4.48.0" # tftest
version = ">= 4.50.0" # tftest
}
}
}

View File

@@ -17,11 +17,11 @@ terraform {
required_providers {
google = {
source = "hashicorp/google"
version = ">= 4.48.0" # tftest
version = ">= 4.50.0" # tftest
}
google-beta = {
source = "hashicorp/google-beta"
version = ">= 4.48.0" # tftest
version = ">= 4.50.0" # tftest
}
}
}

View File

@@ -17,11 +17,11 @@ terraform {
required_providers {
google = {
source = "hashicorp/google"
version = ">= 4.48.0" # tftest
version = ">= 4.50.0" # tftest
}
google-beta = {
source = "hashicorp/google-beta"
version = ">= 4.48.0" # tftest
version = ">= 4.50.0" # tftest
}
}
}

View File

@@ -17,11 +17,11 @@ terraform {
required_providers {
google = {
source = "hashicorp/google"
version = ">= 4.48.0" # tftest
version = ">= 4.50.0" # tftest
}
google-beta = {
source = "hashicorp/google-beta"
version = ">= 4.48.0" # tftest
version = ">= 4.50.0" # tftest
}
}
}

View File

@@ -17,11 +17,11 @@ terraform {
required_providers {
google = {
source = "hashicorp/google"
version = ">= 4.48.0" # tftest
version = ">= 4.50.0" # tftest
}
google-beta = {
source = "hashicorp/google-beta"
version = ">= 4.48.0" # tftest
version = ">= 4.50.0" # tftest
}
}
}

View File

@@ -17,11 +17,11 @@ terraform {
required_providers {
google = {
source = "hashicorp/google"
version = ">= 4.48.0" # tftest
version = ">= 4.50.0" # tftest
}
google-beta = {
source = "hashicorp/google-beta"
version = ">= 4.48.0" # tftest
version = ">= 4.50.0" # tftest
}
}
}

View File

@@ -17,11 +17,11 @@ terraform {
required_providers {
google = {
source = "hashicorp/google"
version = ">= 4.48.0" # tftest
version = ">= 4.50.0" # tftest
}
google-beta = {
source = "hashicorp/google-beta"
version = ">= 4.48.0" # tftest
version = ">= 4.50.0" # tftest
}
}
}

View File

@@ -17,11 +17,11 @@ terraform {
required_providers {
google = {
source = "hashicorp/google"
version = ">= 4.48.0" # tftest
version = ">= 4.50.0" # tftest
}
google-beta = {
source = "hashicorp/google-beta"
version = ">= 4.48.0" # tftest
version = ">= 4.50.0" # tftest
}
}
}

View File

@@ -17,11 +17,11 @@ terraform {
required_providers {
google = {
source = "hashicorp/google"
version = ">= 4.48.0" # tftest
version = ">= 4.50.0" # tftest
}
google-beta = {
source = "hashicorp/google-beta"
version = ">= 4.48.0" # tftest
version = ">= 4.50.0" # tftest
}
}
}

View File

@@ -17,11 +17,11 @@ terraform {
required_providers {
google = {
source = "hashicorp/google"
version = ">= 4.48.0" # tftest
version = ">= 4.50.0" # tftest
}
google-beta = {
source = "hashicorp/google-beta"
version = ">= 4.48.0" # tftest
version = ">= 4.50.0" # tftest
}
}
}

View File

@@ -17,11 +17,11 @@ terraform {
required_providers {
google = {
source = "hashicorp/google"
version = ">= 4.48.0" # tftest
version = ">= 4.50.0" # tftest
}
google-beta = {
source = "hashicorp/google-beta"
version = ">= 4.48.0" # tftest
version = ">= 4.50.0" # tftest
}
}
}

View File

@@ -17,11 +17,11 @@ terraform {
required_providers {
google = {
source = "hashicorp/google"
version = ">= 4.48.0" # tftest
version = ">= 4.50.0" # tftest
}
google-beta = {
source = "hashicorp/google-beta"
version = ">= 4.48.0" # tftest
version = ">= 4.50.0" # tftest
}
}
}

View File

@@ -17,11 +17,11 @@ terraform {
required_providers {
google = {
source = "hashicorp/google"
version = ">= 4.48.0" # tftest
version = ">= 4.50.0" # tftest
}
google-beta = {
source = "hashicorp/google-beta"
version = ">= 4.48.0" # tftest
version = ">= 4.50.0" # tftest
}
}
}

View File

@@ -1,4 +1,4 @@
# Copyright 2022 Google LLC
# Copyright 2023 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@@ -11,3 +11,26 @@
# 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.
values:
module.vm-with-alias-ips.google_compute_instance.default[0]:
name: test
network_interface:
- access_config: []
alias_ip_range:
- ip_cidr_range: 10.16.0.10/32
subnetwork_range_name: alias1
ipv6_access_config: []
network: projects/xxx/global/networks/aaa
nic_type: null
queue_count: null
subnetwork: subnet_self_link
project: my-project
zone: europe-west1-b
counts:
google_compute_instance: 1
modules: 1
resources: 1
outputs: {}

View File

@@ -0,0 +1,57 @@
# Copyright 2023 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.
values:
module.kms-vm-example.google_compute_disk.disks["attached-disk"]:
disk_encryption_key:
- kms_key_self_link: kms_key_self_link
kms_key_service_account: null
raw_key: null
labels:
disk_name: attached-disk
disk_type: pd-balanced
name: kms-test-attached-disk
project: project-id
size: 10
type: pd-balanced
zone: europe-west1-b
module.kms-vm-example.google_compute_instance.default[0]:
attached_disk:
- device_name: attached-disk
disk_encryption_key_raw: null
mode: READ_WRITE
source: kms-test-attached-disk
boot_disk:
- auto_delete: true
disk_encryption_key_raw: null
initialize_params:
- image: projects/debian-cloud/global/images/family/debian-10
size: 10
type: pd-balanced
kms_key_self_link: kms_key_self_link
mode: READ_WRITE
name: kms-test
zone: europe-west1-b
module.kms-vm-example.google_service_account.service_account[0]:
account_id: tf-vm-kms-test
description: null
disabled: false
display_name: Terraform VM kms-test.
project: project-id
timeouts: null
counts:
google_compute_disk: 1
google_compute_instance: 1
google_service_account: 1

View File

@@ -0,0 +1,31 @@
# Copyright 2023 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.
values:
module.template-confidential-example.google_compute_instance_template.default[0]:
confidential_instance_config:
- enable_confidential_compute: true
name_prefix: confidential-template-
project: project-id
region: europe-west1
module.vm-confidential-example.google_compute_instance.default[0]:
confidential_instance_config:
- enable_confidential_compute: true
name: confidential-vm
project: project-id
zone: europe-west1-b
counts:
google_compute_instance: 1
google_compute_instance_template: 1

View File

@@ -0,0 +1,59 @@
# Copyright 2023 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.
values:
module.vm-disk-options-example.google_compute_disk.disks["data2"]:
name: test-data2
project: project-id
size: 20
snapshot: snapshot-2
type: pd-ssd
zone: europe-west1-b
module.vm-disk-options-example.google_compute_instance.default[0]:
attached_disk:
- device_name: data2
disk_encryption_key_raw: null
mode: READ_ONLY
source: test-data2
- device_name: data1
disk_encryption_key_raw: null
mode: READ_WRITE
source: test-data1
boot_disk:
- auto_delete: true
disk_encryption_key_raw: null
initialize_params:
- image: projects/debian-cloud/global/images/family/debian-11
size: 10
type: pd-balanced
mode: READ_WRITE
description: Managed by the compute-vm Terraform module.
name: test
project: project-id
zone: europe-west1-b
module.vm-disk-options-example.google_compute_region_disk.disks["data1"]:
name: test-data1
project: project-id
region: europe-west1
replica_zones:
- europe-west1-b
- europe-west1-c
size: 10
type: pd-balanced
counts:
google_compute_disk: 1
google_compute_instance: 1
google_compute_region_disk: 1
google_service_account: 1

View File

@@ -1,4 +1,4 @@
# Copyright 2022 Google LLC
# Copyright 2023 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@@ -11,3 +11,17 @@
# 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.
values:
module.instance-group.google_compute_instance.default[0]: {}
module.instance-group.google_compute_instance_group.unmanaged[0]:
name: ilb-test
named_port: []
network: projects/xxx/global/networks/aaa
project: my-project
timeouts: null
zone: europe-west1-b
counts:
google_compute_instance: 1
google_compute_instance_group: 1

View File

@@ -0,0 +1,43 @@
# Copyright 2023 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.
values:
google_compute_image.cos-gvnic:
guest_os_features:
- type: GVNIC
- type: SEV_CAPABLE
- type: UEFI_COMPATIBLE
- type: VIRTIO_SCSI_MULTIQUEUE
name: my-image
project: my-project
source_image: https://www.googleapis.com/compute/v1/projects/cos-cloud/global/images/cos-89-16108-534-18
module.vm-with-gvnic.google_compute_instance.default[0]:
name: test
network_interface:
- access_config: []
alias_ip_range: []
ipv6_access_config: []
network: projects/xxx/global/networks/aaa
nic_type: GVNIC
queue_count: null
subnetwork: subnet_self_link
project: my-project
zone: europe-west1-b
counts:
google_compute_image: 1
google_compute_instance: 1
google_service_account: 1
modules: 1
resources: 3

View File

@@ -0,0 +1,34 @@
# Copyright 2023 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.
values:
module.vm-iam-example.google_compute_instance.default[0]:
name: webserver
module.vm-iam-example.google_compute_instance_iam_binding.default["roles/compute.instanceAdmin"]:
condition: []
instance_name: webserver
members:
- group:admin@example.com
- group:webserver@example.com
project: project-id
role: roles/compute.instanceAdmin
zone: europe-west1-b
counts:
google_compute_instance: 1
google_compute_instance_iam_binding: 1
modules: 1
resources: 2
outputs: {}

View File

@@ -0,0 +1,45 @@
# Copyright 2023 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.
values:
module.vm-external-ip.google_compute_instance.default[0]:
name: vm-external-ip
network_interface:
- access_config:
- nat_ip: 8.8.8.8
public_ptr_domain_name: null
alias_ip_range: []
ipv6_access_config: []
network: projects/xxx/global/networks/aaa
nic_type: null
queue_count: null
subnetwork: subnet_self_link
project: my-project
zone: europe-west1-b
module.vm-internal-ip.google_compute_instance.default[0]:
name: vm-internal-ip
network_interface:
- access_config: []
alias_ip_range: []
ipv6_access_config: []
network: projects/xxx/global/networks/aaa
network_ip: 10.0.0.2
nic_type: null
queue_count: null
subnetwork: subnet_self_link
project: my-project
zone: europe-west1-b
counts:
google_compute_instance: 2

View File

@@ -1,4 +1,4 @@
# Copyright 2022 Google LLC
# Copyright 2023 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@@ -11,3 +11,22 @@
# 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.
values:
module.vm-metadata-example.google_compute_instance.default[0]:
metadata:
startup-script: |
#! /bin/bash
apt-get update
apt-get install -y nginx
name: nginx-server
project: project-id
zone: europe-west1-b
labels:
env: dev
system: crm
module.vm-metadata-example.google_service_account.service_account[0]: {}
counts:
google_compute_instance: 1
google_service_account: 1

View File

@@ -0,0 +1,49 @@
# Copyright 2023 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.
values:
module.vm-default-sa-example2.google_compute_instance.default[0]:
name: test3
project: project-id
service_account:
- scopes:
- https://www.googleapis.com/auth/devstorage.read_only
- https://www.googleapis.com/auth/logging.write
- https://www.googleapis.com/auth/monitoring.write
zone: europe-west1-b
module.vm-managed-sa-example.google_compute_instance.default[0]:
name: test1
project: project-id
service_account:
- scopes:
- https://www.googleapis.com/auth/cloud-platform
- https://www.googleapis.com/auth/userinfo.email
zone: europe-west1-b
module.vm-managed-sa-example.google_service_account.service_account[0]:
account_id: tf-vm-test1
display_name: Terraform VM test1.
project: project-id
module.vm-managed-sa-example2.google_compute_instance.default[0]:
name: test2
project: project-id
service_account:
- scopes:
- https://www.googleapis.com/auth/cloud-platform
zone: europe-west1-b
counts:
google_compute_instance: 3
google_service_account: 1
modules: 3
resources: 4

View File

@@ -0,0 +1,72 @@
# Copyright 2023 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.
values:
module.simple-vm-example.google_compute_instance.default[0]:
advanced_machine_features: []
allow_stopping_for_update: true
attached_disk: []
boot_disk:
- auto_delete: true
disk_encryption_key_raw: null
initialize_params:
- image: projects/debian-cloud/global/images/family/debian-11
size: 10
type: pd-balanced
mode: READ_WRITE
can_ip_forward: false
deletion_protection: false
description: Managed by the compute-vm Terraform module.
enable_display: false
hostname: null
labels: null
machine_type: f1-micro
metadata: null
metadata_startup_script: null
name: test
network_interface:
- access_config: []
alias_ip_range: []
ipv6_access_config: []
network: projects/xxx/global/networks/aaa
nic_type: null
queue_count: null
subnetwork: subnet_self_link
project: project-id
scheduling:
- automatic_restart: true
instance_termination_action: null
max_run_duration: []
min_node_cpus: null
node_affinities: []
on_host_maintenance: MIGRATE
preemptible: false
provisioning_model: STANDARD
scratch_disk: []
service_account:
- scopes:
- https://www.googleapis.com/auth/cloud-platform
- https://www.googleapis.com/auth/userinfo.email
shielded_instance_config: []
tags: null
zone: europe-west1-b
module.simple-vm-example.google_service_account.service_account[0]:
account_id: tf-vm-test
display_name: Terraform VM test.
project: project-id
counts:
google_compute_instance: 1
google_service_account: 1

View File

@@ -1,4 +1,4 @@
# Copyright 2022 Google LLC
# Copyright 2023 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@@ -11,3 +11,21 @@
# 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.
values:
module.spot-vm-example.google_compute_instance.default[0]:
name: test
project: project-id
scheduling:
- automatic_restart: false
instance_termination_action: STOP
max_run_duration: []
min_node_cpus: null
node_affinities: []
on_host_maintenance: TERMINATE
preemptible: true
provisioning_model: SPOT
zone: europe-west1-b
counts:
google_compute_instance: 1

View File

@@ -0,0 +1,65 @@
# Copyright 2023 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.
values:
module.cos-test.google_compute_instance_template.default[0]:
disk:
- auto_delete: true
boot: true
disk_encryption_key: []
disk_name: null
disk_size_gb: 10
disk_type: pd-balanced
labels: null
resource_policies: null
source: null
source_image: projects/cos-cloud/global/images/family/cos-stable
source_image_encryption_key: []
source_snapshot: null
source_snapshot_encryption_key: []
- auto_delete: true
device_name: disk-1
disk_encryption_key: []
disk_name: disk-1
disk_size_gb: 10
disk_type: pd-balanced
labels: null
mode: READ_WRITE
resource_policies: null
source: null
source_image_encryption_key: []
source_snapshot: null
source_snapshot_encryption_key: []
type: PERSISTENT
name_prefix: test-
network_interface:
- access_config: []
alias_ip_range: []
ipv6_access_config: []
network: projects/xxx/global/networks/aaa
network_ip: null
nic_type: null
queue_count: null
subnetwork: subnet_self_link
project: my-project
region: europe-west1
service_account:
- email: vm-default@my-project.iam.gserviceaccount.com
scopes:
- https://www.googleapis.com/auth/devstorage.read_only
- https://www.googleapis.com/auth/logging.write
- https://www.googleapis.com/auth/monitoring.write
counts:
google_compute_instance_template: 1

View File

@@ -1,31 +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.
*/
module "test" {
source = "../../../../modules/compute-vm"
project_id = "my-project"
zone = "europe-west1-b"
name = "test"
attached_disks = var.attached_disks
attached_disk_defaults = var.attached_disk_defaults
create_template = var.create_template
confidential_compute = var.confidential_compute
group = var.group
iam = var.iam
metadata = var.metadata
network_interfaces = var.network_interfaces
service_account_create = var.service_account_create
}

View File

@@ -1,70 +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 "attached_disks" {
description = "Additional disks, if options is null defaults will be used in its place. Source type is one of 'image' (zonal disks in vms and template), 'snapshot' (vm), 'existing', and null."
type = any
default = []
}
variable "attached_disk_defaults" {
description = "Defaults for attached disks options."
type = any
default = {
auto_delete = true
mode = "READ_WRITE"
replica_zone = null
type = "pd-balanced"
}
}
variable "confidential_compute" {
type = bool
default = false
}
variable "create_template" {
type = bool
default = false
}
variable "group" {
type = any
default = null
}
variable "iam" {
type = map(set(string))
default = {}
}
variable "metadata" {
type = map(string)
default = {}
}
variable "network_interfaces" {
type = any
default = [{
network = "https://www.googleapis.com/compute/v1/projects/my-project/global/networks/default",
subnetwork = "https://www.googleapis.com/compute/v1/projects/my-project/regions/europe-west1/subnetworks/default-default",
}]
}
variable "service_account_create" {
type = bool
default = false
}

Some files were not shown because too many files have changed in this diff Show More