Skip to content

Commit

Permalink
Merge pull request #43 from omazin/public-ip
Browse files Browse the repository at this point in the history
[instance_template] Support public IPs.
  • Loading branch information
Aaron Lane authored Nov 28, 2019
2 parents bc002ef + 5a6058a commit dd199bc
Show file tree
Hide file tree
Showing 13 changed files with 68 additions and 10 deletions.
7 changes: 6 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ terraform.tfvars
**/account.json
**/credentials
.DS_Store
.kitchen
.terraform
.terraform.tfstate.d
*.pyc
Expand All @@ -16,3 +15,9 @@ __pycache__/
*.iml

*.json

# Kitchen files
**/inspec.lock
**/.kitchen
**/kitchen.local.yml
**/Gemfile.lock
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ project adheres to [Semantic Versioning](http://semver.org/).

## [Unreleased]

### Added

- Support for public IPs. Added `access_config` variable. [#43]

## [1.1.1] - 2019-10-25
### Fixed

Expand Down Expand Up @@ -57,3 +61,4 @@ project adheres to [Semantic Versioning](http://semver.org/).
[#26]: https://github.com/terraform-google-modules/terraform-google-vm/pull/26
[#37]: https://github.com/terraform-google-modules/terraform-google-vm/pull/37
[#38]: https://github.com/terraform-google-modules/terraform-google-vm/pull/38
[#43]: https://github.com/terraform-google-modules/terraform-google-vm/pull/43
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
# Make will use bash instead of sh
SHELL := /usr/bin/env bash

DOCKER_TAG_VERSION_DEVELOPER_TOOLS := 0.1.0
DOCKER_TAG_VERSION_DEVELOPER_TOOLS := 0
DOCKER_IMAGE_DEVELOPER_TOOLS := cft/developer-tools
REGISTRY_URL := gcr.io/cloud-foundation-cicd

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ See also the [project_services](modules/project_services) module (optional).
## Notes

`distribution_policy_zones` cannot be changed during use. If you have changed them yourself or
used to have a default value, then you'll have to force recreate a MIG group yourself.
used to have a default value, then you'll have to force recreate a MIG group yourself.

## Test Configuration

Expand Down
2 changes: 1 addition & 1 deletion build/int.cloudbuild.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,4 @@ tags:
- 'integration'
substitutions:
_DOCKER_IMAGE_DEVELOPER_TOOLS: 'cft/developer-tools'
_DOCKER_TAG_VERSION_DEVELOPER_TOOLS: '0.1.0'
_DOCKER_TAG_VERSION_DEVELOPER_TOOLS: '0'
2 changes: 1 addition & 1 deletion build/lint.cloudbuild.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ tags:
- 'lint'
substitutions:
_DOCKER_IMAGE_DEVELOPER_TOOLS: 'cft/developer-tools'
_DOCKER_TAG_VERSION_DEVELOPER_TOOLS: '0.1.0'
_DOCKER_TAG_VERSION_DEVELOPER_TOOLS: '0'
15 changes: 14 additions & 1 deletion examples/instance_template/simple/main.tf
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright 2018 Google LLC
* Copyright 2019 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -14,6 +14,18 @@
* limitations under the License.
*/


resource "google_compute_address" "ip_address" {
name = "external-ip"
}

locals {
access_config = {
nat_ip = google_compute_address.ip_address.address
network_tier = "PREMIUM"
}
}

provider "google" {
credentials = file(var.credentials_path)
project = var.project_id
Expand All @@ -29,5 +41,6 @@ module "instance_template" {
name_prefix = "simple"
tags = var.tags
labels = var.labels
access_config = [local.access_config]
}

1 change: 1 addition & 0 deletions modules/instance_template/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ See the [simple](../../examples/instance_template/simple) for a usage example.

| Name | Description | Type | Default | Required |
|------|-------------|:----:|:-----:|:-----:|
| access\_config | Access configurations, i.e. IPs via which the VM instance can be accessed via the Internet. | object | `<list>` | no |
| additional\_disks | List of maps of additional disks. See https://www.terraform.io/docs/providers/google/r/compute_instance_template.html#disk_name | object | `<list>` | no |
| auto\_delete | Whether or not the boot disk should be auto-deleted | string | `"true"` | no |
| can\_ip\_forward | Enable IP forwarding, for NAT instances for example | string | `"false"` | no |
Expand Down
9 changes: 8 additions & 1 deletion modules/instance_template/main.tf
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright 2018 Google LLC
* Copyright 2019 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -99,6 +99,13 @@ resource "google_compute_instance_template" "tpl" {
network = var.network
subnetwork = var.subnetwork
subnetwork_project = var.subnetwork_project
dynamic "access_config" {
for_each = var.access_config
content {
nat_ip = access_config.value.nat_ip
network_tier = access_config.value.network_tier
}
}
}

lifecycle {
Expand Down
14 changes: 13 additions & 1 deletion modules/instance_template/variables.tf
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright 2018 Google LLC
* Copyright 2019 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -164,3 +164,15 @@ variable "shielded_instance_config" {
enable_integrity_monitoring = true
}
}

###########################
# Public IP
###########################
variable "access_config" {
description = "Access configurations, i.e. IPs via which the VM instance can be accessed via the Internet."
type = list(object({
nat_ip = string
network_tier = string
}))
default = []
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ See the [simple](../../examples/preemptible_and_regular_instance_templates/simpl

| Name | Description | Type | Default | Required |
|------|-------------|:----:|:-----:|:-----:|
| access\_config | Access configurations, i.e. IPs via which the VM instance can be accessed via the Internet. | object | `<list>` | no |
| additional\_disks | List of maps of additional disks. See https://www.terraform.io/docs/providers/google/r/compute_instance_template.html#disk_name | object | `<list>` | no |
| auto\_delete | Whether or not the boot disk should be auto-deleted | string | `"true"` | no |
| can\_ip\_forward | Enable IP forwarding, for NAT instances for example | string | `"false"` | no |
Expand Down
4 changes: 3 additions & 1 deletion modules/preemptible_and_regular_instance_templates/main.tf
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright 2018 Google LLC
* Copyright 2019 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -39,6 +39,7 @@ module "preemptible" {
network = var.network
subnetwork = var.subnetwork
subnetwork_project = var.subnetwork_project
access_config = var.access_config
preemptible = true
}

Expand All @@ -63,5 +64,6 @@ module "regular" {
network = var.network
subnetwork = var.subnetwork
subnetwork_project = var.subnetwork_project
access_config = var.access_config
preemptible = false
}
14 changes: 13 additions & 1 deletion modules/preemptible_and_regular_instance_templates/variables.tf
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright 2018 Google LLC
* Copyright 2019 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -135,3 +135,15 @@ variable "service_account" {
})
description = "Service account to attach to the instance. See https://www.terraform.io/docs/providers/google/r/compute_instance_template.html#service_account."
}

###########################
# Public IP
###########################
variable "access_config" {
description = "Access configurations, i.e. IPs via which the VM instance can be accessed via the Internet."
type = list(object({
nat_ip = string
network_tier = string
}))
default = []
}

0 comments on commit dd199bc

Please sign in to comment.