Skip to content

Commit

Permalink
Merge pull request #57 from omazin/umig-external-ip
Browse files Browse the repository at this point in the history
[umig] Add external ips support.
  • Loading branch information
aaron-lane authored Jan 8, 2020
2 parents 48a9b07 + 3e2798b commit cfc281e
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 4 deletions.
9 changes: 8 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this
project adheres to [Semantic Versioning](http://semver.org/).

## [Unreleased]

### Added

- `access_config` variable on the `umig` submodule. [#57]


## [1.3.0] - 2019-12-09

### Added
Expand All @@ -16,7 +22,7 @@ project adheres to [Semantic Versioning](http://semver.org/).

### Added

- Support for public IPs. Added `access_config` variable. [#43]
- `access_config` variable on the `instance_template` and `preemptible_and_regular_instance_templates` submodules. [#43]

### Fixed

Expand Down Expand Up @@ -77,3 +83,4 @@ project adheres to [Semantic Versioning](http://semver.org/).
[#42]: https://github.com/terraform-google-modules/terraform-google-vm/pull/42
[#43]: https://github.com/terraform-google-modules/terraform-google-vm/pull/43
[#44]: https://github.com/terraform-google-modules/terraform-google-vm/pull/44
[#57]: https://github.com/terraform-google-modules/terraform-google-vm/pull/57
14 changes: 13 additions & 1 deletion examples/umig/full/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 @@ -21,6 +21,17 @@ provider "google" {
version = "~> 2.7.0"
}

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

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

module "instance_template" {
source = "../../../modules/instance_template"
name_prefix = "${var.hostname}-instance-template"
Expand Down Expand Up @@ -61,4 +72,5 @@ module "umig" {
num_instances = var.target_size
instance_template = module.instance_template.self_link
named_ports = var.named_ports
access_config = [local.access_config]
}
1 change: 1 addition & 0 deletions modules/umig/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ See the [simple](examples/umig/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 |
| hostname | Hostname of instances | string | `""` | no |
| instance\_template | Instance template self_link used to create compute instances | string | n/a | yes |
| named\_ports | Named name and named port | object | `<list>` | no |
Expand Down
10 changes: 9 additions & 1 deletion modules/umig/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 @@ -51,6 +51,14 @@ resource "google_compute_instance_from_template" "compute_instance" {
subnetwork = var.subnetwork
subnetwork_project = var.subnetwork_project
network_ip = length(var.static_ips) == 0 ? "" : element(local.static_ips, count.index)

dynamic "access_config" {
for_each = var.access_config
content {
nat_ip = access_config.value.nat_ip
network_tier = access_config.value.network_tier
}
}
}

source_instance_template = var.instance_template
Expand Down
10 changes: 9 additions & 1 deletion modules/umig/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 @@ -64,3 +64,11 @@ variable "instance_template" {
description = "Instance template self_link used to create compute instances"
}

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 cfc281e

Please sign in to comment.