Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
avinava-mycelium committed Jul 16, 2022
0 parents commit 1c639d5
Show file tree
Hide file tree
Showing 7 changed files with 164 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/.DS_Store
/.history
38 changes: 38 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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


<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
## Inputs

| Name | Description | Type | Default | Required |
|------|-------------|------|---------|:--------:|
| access\_config | Access configurations, i.e. IPs via which the VM instance can be accessed via the Internet. | <pre>list(object({<br> nat_ip = string<br> network_tier = string<br> }))</pre> | `[]` | 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 |

<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
11 changes: 11 additions & 0 deletions data.tf
Original file line number Diff line number Diff line change
@@ -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
}
36 changes: 36 additions & 0 deletions main.tf
Original file line number Diff line number Diff line change
@@ -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]
}
}
9 changes: 9 additions & 0 deletions outputs.tf
Original file line number Diff line number Diff line change
@@ -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.*
}
10 changes: 10 additions & 0 deletions private_address.tf
Original file line number Diff line number Diff line change
@@ -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
}
58 changes: 58 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
@@ -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"
}

0 comments on commit 1c639d5

Please sign in to comment.