diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..38d3073 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +/.DS_Store +/.history \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..77d8b5a --- /dev/null +++ b/README.md @@ -0,0 +1,38 @@ +# Compute Instance + +This module is used to create compute instances (and only compute instances) using +[google_compute_instance_from_template](https://www.terraform.io/docs/providers/google/r/compute_instance_from_template.html), with no instance groups. + +## Usage + +See the [simple](https://github.com/terraform-google-modules/terraform-google-vm/tree/master/examples/compute_instance/simple) for a usage example. + +## Testing + + + +## Inputs + +| Name | Description | Type | Default | Required | +|------|-------------|------|---------|:--------:| +| access\_config | Access configurations, i.e. IPs via which the VM instance can be accessed via the Internet. |
list(object({
nat_ip = string
network_tier = string
}))
| `[]` | no | +| add\_hostname\_suffix | Adds a suffix to the hostname | `bool` | `true` | no | +| hostname | Hostname of instances | `string` | `""` | no | +| instance\_template | Instance template self\_link used to create compute instances | `any` | n/a | yes | +| network | Network to deploy to. Only one of network or subnetwork should be specified. | `string` | `""` | no | +| num\_instances | Number of instances to create. This value is ignored if static\_ips is provided. | `string` | `"1"` | no | +| region | Region where the instances should be created. | `string` | `null` | no | +| static\_ips | List of static IPs for VM instances | `list(string)` | `[]` | no | +| subnetwork | Subnet to deploy to. Only one of network or subnetwork should be specified. | `string` | `""` | no | +| subnetwork\_project | The project that subnetwork belongs to | `string` | `""` | no | +| zone | Zone where the instances should be created. If not specified, instances will be spread across available zones in the region. | `string` | `null` | no | + +## Outputs + +| Name | Description | +|------|-------------| +| available\_zones | List of available zones in region | +| instances\_details | List of all details for compute instances | +| instances\_self\_links | List of self-links for compute instances | + + diff --git a/data.tf b/data.tf new file mode 100644 index 0000000..478c650 --- /dev/null +++ b/data.tf @@ -0,0 +1,11 @@ +data "google_compute_image" "cos_image" { + family = var.image_family + project = var.image_project +} + +data "google_secret_manager_secret_version" "sa" { + provider = google-beta + secret = var.service_account_name + version = var.service_account_version + project = var.project_id +} \ No newline at end of file diff --git a/main.tf b/main.tf new file mode 100644 index 0000000..1636f88 --- /dev/null +++ b/main.tf @@ -0,0 +1,36 @@ +resource "google_compute_instance" "this" { + name = "${var.node_source}-${var.node_name}-${var.node_type}-${var.node_count}" + machine_type = var.machine_type + zone = var.zone + + tags = [var.network_tag] + + boot_disk { + device_name = "pd-${var.node_source}-${var.node_name}-${var.node_type}-${var.node_count}" + initialize_params { + size = var.boot_disk_size + type = var.boot_disk_type + image = data.google_compute_image.cos_image.self_link + } + } + + network_interface { + network = var.network + subnetwork = var.subnetwork + network_ip = module.address.addresses[0] + access_config { + } + } + + metadata = { + node = var.node_name + type = var.node_type + source = var.node_source + startup-script-url = "${var.startup_script_prefix}${var.node_name}-${var.node_type}-${var.startup_script_suffix}" + } + + service_account { + email = data.google_secret_manager_secret_version.sa.secret_data + scopes = [var.service_account_scope] + } +} diff --git a/outputs.tf b/outputs.tf new file mode 100644 index 0000000..f86bf2d --- /dev/null +++ b/outputs.tf @@ -0,0 +1,9 @@ +output "instances_details" { + description = "List of all details for compute instances" + value = google_compute_instance.this.* +} + +output "static_internal_ip" { + description = "List of all details for the internal IP" + value = module.address.* +} diff --git a/private_address.tf b/private_address.tf new file mode 100644 index 0000000..912a45b --- /dev/null +++ b/private_address.tf @@ -0,0 +1,10 @@ +module "address" { + source = "terraform-google-modules/address/google" + version = "3.0.0" + project_id = var.project_id # Replace this with your project ID in quotes + region = var.region + subnetwork = var.subnetwork + names = ["ip-int-${var.node_source}-${var.node_name}-${var.node_type}-${var.node_count}"] + address_type = var.address_type + network_tier = var.address_tier +} \ No newline at end of file diff --git a/variables.tf b/variables.tf new file mode 100644 index 0000000..c75d3aa --- /dev/null +++ b/variables.tf @@ -0,0 +1,58 @@ +variable "project_id" { + default = "avian-direction-235610" +} +variable "region" {} +variable "zone" {} +variable "subnetwork" { + default = "sb-nodes-chainlink" +} +variable "network_tag" { + default = "fw-sb-node-chainlink" +} +variable "machine_type" {} +variable "boot_disk_size" { + default = "50" +} +variable "boot_disk_type" { + default = "pd-ssd" +} +variable "network" { + default = "default" +} +variable "service_account_scope" { + default = "cloud-platform" +} +variable "image_family" { + default = "cos-stable" +} +variable "image_project" { + default = "cos-cloud" +} +variable "service_account_name" { + default = "CL_Service_Account" +} +variable "service_account_version" { + default = "1" +} +variable "address_type" { + default = "INTERNAL" +} +variable "address_tier" { + default = "PREMIUM" +} +variable "node_name" { +} +variable "node_type" { +} +variable "node_count" { + default = "1" +} +variable "node_source" { + default = "cl" +} +variable "startup_script_prefix" { + default = "gs://myc-node/cl/cl-metadata-script/" +} +variable "startup_script_suffix" { + default = "startup.sh" +}