Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/bash

while getopts n:z:p: flag
do
case "${flag}" in
n) InstanceName=${OPTARG};;
z) Zone=${OPTARG};;
p) ProjectId=${OPTARG};;
esac
done

# Connect
gcloud compute ssh $InstanceName \
--zone=$Zone \
--project=$ProjectId \
--tunnel-through-iap
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
SHELL := /bin/bash

all: init apply ssh

clean: state destroy

version:
time terraform version

init:
time terraform init

validate:
time terraform validate

update:
time terraform get -update

plan:
time terraform plan

apply:
time terraform apply -auto-approve

destroy:
time terraform destroy -auto-approve

output:
time terraform output

ssh:
time terraform output SshKey | tail -n +3 | head -n-3 | sed "s/^[ \t]*//" > .sshkey.pem

state:
time terraform state list

connect: connect-app

connect-app:
chmod +x ./CloudShell/connect.sh
./CloudShell/connect.sh -n $$(terraform output -json App | jq -r .name) -z $$(terraform output -json App | jq -r .zone) -p $$(terraform output -json App | jq -r .project)

connect-agent1:
chmod +x ./CloudShell/connect.sh
./CloudShell/connect.sh -n $$(terraform output -json Agent1 | jq -r .name) -z $$(terraform output -json Agent1 | jq -r .zone) -p $$(terraform output -json Agent1 | jq -r .project)
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ This deployment creates a topology with three virtual private clouds, one having
```
terraform.required.auto.tfvars
```
You **MUST** uncomment all lines in this file and replace values to match your particular environment.
You **MUST** uncomment all lines in this file and replace values to match your particular environment.
Otherwise, Terraform will prompt the user to supply input arguents via cli.

## Optional Variables
Expand All @@ -30,4 +30,4 @@ terraform validate
terraform plan
terraform state list
terraform output
```
```
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@ data "google_compute_machine_types" "App" {

data "http" "ip" {
url = "https://ifconfig.me/ip"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ locals {
File3Content = tls_private_key.SshKey.public_key_openssh
File3Name = "id_rsa.pub"
Preamble = replace("${local.UserLoginTag}-${local.UserProjectTag}-${local.AppTag}", "_", "-")
Private1VpcNetworkMtu = var.Private1VpcNetworkMtu
Private1VpcNetworkPeerName = "${local.Preamble}-test1-vpc-peer"
Private2VpcNetworkMtu = var.Private2VpcNetworkMtu
Private2VpcNetworkPeerName = "${local.Preamble}-test2-vpc-peer"
PublicFirewallRuleSourceIpRanges = var.PublicFirewallRuleSourceIpRanges == null ? [ "${data.http.ip.response_body}/32" ] : var.PublicFirewallRuleSourceIpRanges
SshKeyAlgorithm = "RSA"
Expand All @@ -20,4 +22,4 @@ locals {
UserEmailTag = var.UserEmailTag == null ? "terraform@example.com" : var.UserEmailTag
UserLoginTag = var.UserLoginTag == null ? "terraform" : var.UserLoginTag
UserProjectTag = var.UserProjectTag == null ? lower(random_id.RandomId.id) : var.UserProjectTag
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module "App" {
source = "git::https://github.com/armdupre/terraform-google-module-bps-app.git?ref=11.20.3"
source = "git::https://github.com/Keysight/terraform-google-module-bps-app.git?ref=26.0.0"
Eth0SubnetName = module.Vpc.PublicSubnet.name
Eth0VpcNetworkName = module.Vpc.PublicVpcNetwork.name
MachineType = local.AppMachineType
Expand All @@ -16,7 +16,7 @@ module "App" {
}

module "Agent1" {
source = "git::https://github.com/armdupre/terraform-google-module-bps-agent.git?ref=11.20.3"
source = "git::https://github.com/Keysight/terraform-google-module-bps-agent.git?ref=26.0.0"
Eth0SubnetName = module.Vpc.PublicSubnet.name
Eth0VpcNetworkName = module.Vpc.PublicVpcNetwork.name
Eth1SubnetName = module.Vpc.Private1Subnet.name
Expand All @@ -39,4 +39,4 @@ module "Agent1" {

resource "random_id" "RandomId" {
byte_length = 4
}
}
Original file line number Diff line number Diff line change
@@ -1,77 +1,88 @@
output "Agent1" {
value = {
"architecture" : module.Agent1.Instance.architecture
"can_ip_forward" : module.Agent1.Instance.can_ip_forward
"cpu_platform" : module.Agent1.Instance.cpu_platform
"current_status" : module.Agent1.Instance.current_status
"image_name" : module.Agent1.Image.name
"image_project" : module.Agent1.Image.project
"instance_id" : module.Agent1.Instance.instance_id
"machine_description" : data.google_compute_machine_types.Agent.machine_types.0.description
"machine_guest_cpus" : data.google_compute_machine_types.Agent.machine_types.0.guest_cpus
"machine_is_shared_cpus" : data.google_compute_machine_types.Agent.machine_types.0.is_shared_cpus
"machine_memory_mb" : data.google_compute_machine_types.Agent.machine_types.0.memory_mb
"machine_type" : module.App.Instance.machine_type
"machine_type" : module.Agent1.Instance.machine_type
"name" : module.Agent1.Instance.name
"network_ip" : module.Agent1.Instance.network_ip
"project" : module.Agent1.Instance.project
"public_address" : module.Agent1.Eth0PublicIpAddress.address
"public_address_type" : module.Agent1.Eth0PublicIpAddress.address_type
"serial-port-enable" : module.Agent1.Instance.serial-port-enable
"zone" : module.Agent1.Instance.zone
architecture = module.Agent1.Instance.architecture
can_ip_forward = module.Agent1.Instance.can_ip_forward
cpu_platform = module.Agent1.Instance.cpu_platform
current_status = module.Agent1.Instance.current_status
eth0 = {
public_ip_address = {
address = module.Agent1.Eth0PublicIpAddress.address
address_type = module.Agent1.Eth0PublicIpAddress.address_type
}
}
image = {
name = module.Agent1.Image.name
project = module.Agent1.Image.project
}
instance_id = module.Agent1.Instance.instance_id
machine = {
description = data.google_compute_machine_types.Agent.machine_types.0.description
guest_cpus = data.google_compute_machine_types.Agent.machine_types.0.guest_cpus
is_shared_cpus = data.google_compute_machine_types.Agent.machine_types.0.is_shared_cpus
machine_type = module.Agent1.Instance.machine_type
memory_mb = data.google_compute_machine_types.Agent.machine_types.0.memory_mb
}
name = module.Agent1.Instance.name
network_ip = module.Agent1.Instance.network_ip
project = module.Agent1.Instance.project
serial-port-enable = module.Agent1.Instance.serial-port-enable
zone = module.Agent1.Instance.zone
}
}

output "App" {
value = {
"architecture" : module.App.Instance.architecture
"can_ip_forward" : module.App.Instance.can_ip_forward
"cpu_platform" : module.App.Instance.cpu_platform
"current_status" : module.App.Instance.current_status
"image_name" : module.App.Image.name
"image_project" : module.App.Image.project
"instance_id" : module.App.Instance.instance_id
"machine_description" : data.google_compute_machine_types.App.machine_types.0.description
"machine_guest_cpus" : data.google_compute_machine_types.App.machine_types.0.guest_cpus
"machine_is_shared_cpus" : data.google_compute_machine_types.App.machine_types.0.is_shared_cpus
"machine_memory_mb" : data.google_compute_machine_types.App.machine_types.0.memory_mb
"machine_type" : module.App.Instance.machine_type
"name" : module.App.Instance.name
"network_ip" : module.App.Instance.network_ip
"project" : module.App.Instance.project
"public_address" : module.App.Eth0PublicIpAddress.address
"public_address_type" : module.App.Eth0PublicIpAddress.address_type
"public_ip" : split("//", module.App.Eth0PublicIpAddress.address)[1]
"serial-port-enable" : module.App.Instance.serial-port-enable
"zone" : module.App.Instance.zone
architecture = module.App.Instance.architecture
can_ip_forward = module.App.Instance.can_ip_forward
cpu_platform = module.App.Instance.cpu_platform
current_status = module.App.Instance.current_status
image = {
name = module.App.Image.name
project = module.App.Image.project
}
instance_id = module.App.Instance.instance_id
machine = {
description = data.google_compute_machine_types.App.machine_types.0.description
guest_cpus = data.google_compute_machine_types.App.machine_types.0.guest_cpus
is_shared_cpus = data.google_compute_machine_types.App.machine_types.0.is_shared_cpus
memory_mb = data.google_compute_machine_types.App.machine_types.0.memory_mb
machine_type = module.App.Instance.machine_type
}
name = module.App.Instance.name
network_ip = module.App.Instance.network_ip
project = module.App.Instance.project
public_address = module.App.Eth0PublicIpAddress.address
public_address_type = module.App.Eth0PublicIpAddress.address_type
public_ip = split("//", module.App.Eth0PublicIpAddress.address)[1]
serial-port-enable = module.App.Instance.serial-port-enable
zone = module.App.Instance.zone
}
}

output "Private1VpcNetwork" {
value = {
"mtu" : module.Vpc.Private1VpcNetwork.mtu
"name" : module.Vpc.Private1VpcNetwork.name
mtu = module.Vpc.Private1VpcNetwork.mtu
name = module.Vpc.Private1VpcNetwork.name
}
}

output "Private2VpcNetwork" {
value = {
"mtu" : module.Vpc.Private2VpcNetwork.mtu
"name" : module.Vpc.Private2VpcNetwork.name
mtu = module.Vpc.Private2VpcNetwork.mtu
name = module.Vpc.Private2VpcNetwork.name
}
}

output "PublicVpcNetwork" {
value = {
"mtu" : module.Vpc.PublicVpcNetwork.mtu
"name" : module.Vpc.PublicVpcNetwork.name
mtu = module.Vpc.PublicVpcNetwork.mtu
name = module.Vpc.PublicVpcNetwork.name
}
}

output "SshKey" {
sensitive = true
value = {
"private_key_pem" : tls_private_key.SshKey.private_key_pem
private_key_pem = tls_private_key.SshKey.private_key_pem
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,32 @@ AppMachineType must be one of the following types:
}
}

variable "Private1VpcNetworkMtu" {
default = 1460
description = "Maxium Transmission Unit associated with the first private vpc network"
type = number
validation {
condition = contains([1460, 1500, 8896], var.Private1VpcNetworkMtu)
error_message = <<EOF
Private1VpcNetworkMtu must be one of the following values:
1460, 1500, 8896
EOF
}
}

variable "Private2VpcNetworkMtu" {
default = 1460
description = "Maxium Transmission Unit associated with the second private vpc network"
type = number
validation {
condition = contains([1460, 1500, 8896], var.Private2VpcNetworkMtu)
error_message = <<EOF
Private2VpcNetworkMtu must be one of the following values:
1460, 1500, 8896
EOF
}
}

variable "ProjectId" {
description = "Globally unique identifier for working project"
type = string
Expand Down Expand Up @@ -71,4 +97,4 @@ variable "ZoneName" {
default = "us-central1-a"
description = "Deployment area within a region"
type = string
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ terraform {
required_providers {
google = {
source = "hashicorp/google"
version = ">= 6.12.0"
version = ">= 7.18.0"
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
module "Vpc" {
source = "git::https://github.com/armdupre/terraform-google-module-3-vpcs-1-public-subnet-2-private-subnets.git?ref=11.20.2"
source = "git::https://github.com/Keysight/terraform-google-module-3-vpcs-1-public-subnet-2-private-subnets.git?ref=26.0.0"
Private1VpcNetworkMtu = local.Private1VpcNetworkMtu
Private2VpcNetworkMtu = local.Private2VpcNetworkMtu
PublicFirewallRuleSourceIpRanges = local.PublicFirewallRuleSourceIpRanges
RegionName = data.google_client_config.current.region
Tag = local.AppTag
Expand All @@ -17,4 +19,4 @@ resource "google_compute_network_peering" "Private2VpcNetworkPeer" {
name = local.Private2VpcNetworkPeerName
network = module.Vpc.Private2VpcNetwork.id
peer_network = module.Vpc.Private1VpcNetwork.id
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/bash

while getopts n:z:p: flag
do
case "${flag}" in
n) InstanceName=${OPTARG};;
z) Zone=${OPTARG};;
p) ProjectId=${OPTARG};;
esac
done

# Connect
gcloud compute ssh $InstanceName \
--zone=$Zone \
--project=$ProjectId \
--tunnel-through-iap
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
SHELL := /bin/bash

all: init apply ssh

clean: state destroy

version:
time terraform version

init:
time terraform init

validate:
time terraform validate

update:
time terraform get -update

plan:
time terraform plan

apply:
time terraform apply -auto-approve

destroy:
time terraform destroy -auto-approve

output:
time terraform output

ssh:
time terraform output SshKey | tail -n +3 | head -n-3 | sed "s/^[ \t]*//" > .sshkey.pem

state:
time terraform state list

connect: connect-app

connect-app:
chmod +x ./CloudShell/connect.sh
./CloudShell/connect.sh -n $$(terraform output -json App | jq -r .name) -z $$(terraform output -json App | jq -r .zone) -p $$(terraform output -json App | jq -r .project)

connect-agent1:
chmod +x ./CloudShell/connect.sh
./CloudShell/connect.sh -n $$(terraform output -json Agent1 | jq -r .name) -z $$(terraform output -json Agent1 | jq -r .zone) -p $$(terraform output -json Agent1 | jq -r .project)
Loading