Skip to content

Commit

Permalink
terraform: add name, tags, etc as variables for examples (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
clstokes authored Jan 10, 2024
1 parent 81ee586 commit 4160bd2
Show file tree
Hide file tree
Showing 14 changed files with 151 additions and 29 deletions.
4 changes: 2 additions & 2 deletions terraform/aws/aws-ec2-autoscaling-dual-subnet/main.tf
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
locals {
name = "example-${basename(path.cwd)}"
name = var.name != "" ? var.name : "example-${basename(path.cwd)}"

tags = {
tags = var.tags != "" ? var.tags : {
Name = local.name
}
}
Expand Down
14 changes: 14 additions & 0 deletions terraform/aws/aws-ec2-autoscaling-dual-subnet/variables.tf
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
#
# Variables for all resources
#
variable "name" {
description = "Name for all resources"
type = string
default = ""
}
variable "tags" {
description = "Map of tags to add to all resources"
type = map(string)
default = {}
}

#
# Variables for Tailscale
#
Expand Down
4 changes: 2 additions & 2 deletions terraform/aws/aws-ec2-autoscaling-session-recorder/main.tf
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
locals {
name = "example-${basename(path.cwd)}"
name = var.name != "" ? var.name : "example-${basename(path.cwd)}"

tags = {
tags = var.tags != "" ? var.tags : {
Name = local.name
}
}
Expand Down
14 changes: 14 additions & 0 deletions terraform/aws/aws-ec2-autoscaling-session-recorder/variables.tf
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
#
# Variables for all resources
#
variable "name" {
description = "Name for all resources"
type = string
default = ""
}
variable "tags" {
description = "Map of tags to add to all resources"
type = map(string)
default = {}
}

#
# Variables for Tailscale
#
Expand Down
4 changes: 2 additions & 2 deletions terraform/aws/aws-ec2-autoscaling/main.tf
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
locals {
name = "example-${basename(path.cwd)}"
name = var.name != "" ? var.name : "example-${basename(path.cwd)}"

tags = {
tags = var.tags != "" ? var.tags : {
Name = local.name
}
}
Expand Down
14 changes: 14 additions & 0 deletions terraform/aws/aws-ec2-autoscaling/variables.tf
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
#
# Variables for all resources
#
variable "name" {
description = "Name for all resources"
type = string
default = ""
}
variable "tags" {
description = "Map of tags to add to all resources"
type = map(string)
default = {}
}

#
# Variables for Tailscale
#
Expand Down
4 changes: 2 additions & 2 deletions terraform/aws/aws-ec2-instance-dual-stack-ipv4-ipv6/main.tf
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
locals {
name = "example-${basename(path.cwd)}"
name = var.name != "" ? var.name : "example-${basename(path.cwd)}"

tags = {
tags = var.tags != "" ? var.tags : {
Name = local.name
}
}
Expand Down
14 changes: 14 additions & 0 deletions terraform/aws/aws-ec2-instance-dual-stack-ipv4-ipv6/variables.tf
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
#
# Variables for all resources
#
variable "name" {
description = "Name for all resources"
type = string
default = ""
}
variable "tags" {
description = "Map of tags to add to all resources"
type = map(string)
default = {}
}

#
# Variables for Tailscale
#
Expand Down
4 changes: 2 additions & 2 deletions terraform/aws/aws-ec2-instance/main.tf
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
locals {
name = "example-${basename(path.cwd)}"
name = var.name != "" ? var.name : "example-${basename(path.cwd)}"

tags = {
tags = var.tags != "" ? var.tags : {
Name = local.name
}
}
Expand Down
14 changes: 14 additions & 0 deletions terraform/aws/aws-ec2-instance/variables.tf
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
#
# Variables for all resources
#
variable "name" {
description = "Name for all resources"
type = string
default = ""
}
variable "tags" {
description = "Map of tags to add to all resources"
type = map(string)
default = {}
}

#
# Variables for Tailscale
#
Expand Down
13 changes: 4 additions & 9 deletions terraform/azure/azure-linux-vm/main.tf
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
locals {
name = "example-${basename(path.cwd)}"
name = var.name != "" ? var.name : "example-${basename(path.cwd)}"

tags = {
tags = var.tags != "" ? var.tags : {
Name = local.name
}
}
Expand Down Expand Up @@ -39,12 +39,7 @@ resource "tailscale_tailnet_key" "main" {
preauthorized = true
reusable = true
recreate_if_invalid = "always"
tags = [
"tag:example-infra",
"tag:example-exitnode",
"tag:example-subnetrouter",
"tag:example-appconnector",
]
tags = var.tailscale_device_tags
}

module "tailscale_azure_linux_virtual_machine" {
Expand All @@ -57,7 +52,7 @@ module "tailscale_azure_linux_virtual_machine" {
primary_subnet_id = module.network.public_subnet_id

machine_name = local.name
machine_size = "Standard_DS1_v2"
machine_size = var.machine_size
admin_public_key_path = var.admin_public_key_path
resource_tags = local.tags

Expand Down
28 changes: 28 additions & 0 deletions terraform/azure/azure-linux-vm/variables.tf
Original file line number Diff line number Diff line change
@@ -1,6 +1,30 @@
#
# Variables for all resources
#
variable "name" {
description = "Name for all resources"
type = string
default = ""
}
variable "tags" {
description = "Map of tags to add to all resources"
type = map(string)
default = {}
}

#
# Variables for Tailscale
#
variable "tailscale_device_tags" {
description = "Tailscale device tags to assign"
type = set(string)
default = [
"tag:example-infra",
"tag:example-exitnode",
"tag:example-subnetrouter",
"tag:example-appconnector",
]
}
variable "tailscale_set_preferences" {
description = "Preferences to set via `tailscale set ...` - e.g. `--auto-update`. (Do not include `tailscale set`.)"
type = set(string)
Expand All @@ -17,3 +41,7 @@ variable "location" {
variable "admin_public_key_path" {
type = string
}
variable "machine_size" {
type = string
default = "Standard_DS1_v2"
}
16 changes: 6 additions & 10 deletions terraform/google/google-compute-instance/main.tf
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
locals {
name = "example-${basename(path.cwd)}"
name = var.name != "" ? var.name : "example-${basename(path.cwd)}"

metadata = {
tags = var.tags != "" ? var.tags : ["example"]

metadata = var.metadata != "" ? var.metadata : {
Name = local.name
}
tags = ["example"]
}

module "vpc" {
Expand Down Expand Up @@ -34,20 +35,15 @@ resource "tailscale_tailnet_key" "main" {
preauthorized = true
reusable = true
recreate_if_invalid = "always"
tags = [
"tag:example-infra",
"tag:example-exitnode",
"tag:example-subnetrouter",
"tag:example-appconnector",
]
tags = var.tailscale_device_tags
}

module "tailscale_instance" {
source = "../internal-modules/google-compute-instance"

zone = var.zone
machine_name = local.name
machine_type = "e2-medium"
machine_type = var.machine_type
subnet = module.vpc.subnets_ids[0]

instance_metadata = local.metadata
Expand Down
33 changes: 33 additions & 0 deletions terraform/google/google-compute-instance/variables.tf
Original file line number Diff line number Diff line change
@@ -1,6 +1,35 @@
#
# Variables for all resources
#
variable "name" {
description = "Name for all resources"
type = string
default = ""
}
variable "tags" {
description = "Set of tags to add to all resources"
type = set(string)
default = []
}
variable "metadata" {
description = "Map of metadata to add to all resources"
type = map(string)
default = {}
}

#
# Variables for Tailscale
#
variable "tailscale_device_tags" {
description = "Tailscale device tags to assign"
type = set(string)
default = [
"tag:example-infra",
"tag:example-exitnode",
"tag:example-subnetrouter",
"tag:example-appconnector",
]
}
variable "tailscale_set_preferences" {
description = "Preferences to set via `tailscale set ...` - e.g. `--auto-update`. (Do not include `tailscale set`.)"
type = set(string)
Expand All @@ -22,3 +51,7 @@ variable "zone" {
description = "The Google Cloud zone to deploy to"
type = string
}
variable "machine_type" {
type = string
default = "e2-medium"
}

0 comments on commit 4160bd2

Please sign in to comment.