-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
164 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
data "google_project" "project" { | ||
project_id = var.project_id | ||
} | ||
|
||
data " google_compute_network" "gke_vpc" { | ||
name = var.vpc_name | ||
project = data.google_project.project.id | ||
} | ||
|
||
data " google_compute_subnetwork" "master_subnet" { | ||
name = var.subnet_name | ||
project = data.google_project.project.id | ||
} | ||
|
||
|
||
resource "google_compute_instance" "bastion_host" { | ||
name = "bastion-host" | ||
machine_type = "n1-standard-1" | ||
zone = var.gcp_region | ||
|
||
boot_disk { | ||
initialize_params { | ||
image = "debian-cloud/debian-10" | ||
} | ||
} | ||
|
||
network_interface { | ||
network = data.google_compute_network.gke_vpc.name #google_compute_network.vpc_network.name | ||
subnetwork = data.google_compute_subnetwork.master_subnet.name # google_compute_subnetwork.vpc_subnet.name | ||
access_config {} # Allows external SSH access to the bastion host. | ||
} | ||
|
||
metadata = { | ||
user-data = file("${path.module}/cloud-config.yaml") | ||
ssh-keys = "lpt:${var.ssh_pub}" | ||
} | ||
|
||
tags = ["bastion"] | ||
} | ||
|
||
resource "google_compute_firewall" "allow_bastion_ssh_from_public" { | ||
name = "allow-bastion-ssh" | ||
network = data.google_compute_network.gke_vpc.name | ||
|
||
allow { | ||
protocol = "tcp" | ||
ports = ["22"] | ||
} | ||
|
||
source_ranges = ["0.0.0.0/0"] | ||
target_tags = ["bastion"] | ||
} | ||
|
||
resource "google_compute_firewall" "allow_bastion_to_gke" { | ||
name = "allow-bastion-to-gke" | ||
network = data.google_compute_network.gke_vpc.name | ||
|
||
allow { | ||
protocol = "tcp" | ||
ports = ["443"] # Port for GKE control plane | ||
} | ||
|
||
source_tags = ["bastion"] | ||
destination_ranges = [data.google_compute_subnetwork.master_subnet.ip_cidr_range] # GKE master CIDR | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
groups: | ||
- lpt | ||
|
||
users: | ||
- default | ||
- name: terraform | ||
gecos: lpt | ||
shell: /bin/bash | ||
primary_group: lpt | ||
sudo: ALL=(ALL) NOPASSWD:ALL | ||
groups: users | ||
lock_passwd: false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
terraform { | ||
required_providers { | ||
google = { | ||
source = "hashicorp/google" | ||
version = "~> 6" | ||
} | ||
} | ||
|
||
backend "gcs" { | ||
bucket = "lpt-schulung-bucket-tfstate" | ||
prefix = "gke_and_state_bucket" | ||
} | ||
} | ||
|
||
provider "google" { | ||
project = var.project_id | ||
region = var.gcp_region | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
|
||
variable "project_id" { | ||
description = "Project ID to apply and identify infrastructure code" | ||
type = string | ||
} | ||
|
||
variable "gcp_region" { | ||
description = "Region the infrastructure should be deployed in" | ||
type = string | ||
default = "europe-west1" | ||
} | ||
|
||
variable "vpc_name" { | ||
description = "VPC Name" | ||
type = string | ||
default = "simple-autopilot-private-network" | ||
} | ||
|
||
variable "subnet_name" { | ||
description = "Subnet Name" | ||
type = string | ||
default = "simple-autopilot-private-master-subnet" | ||
} | ||
|
||
|
||
variable "ssh_pub" { | ||
description = "VPC ID" | ||
type = string | ||
default = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQDD7/3NuwKwsZpNZUAq5tWDluX6KaLRq50W8CzWC83zzjS0wjswKUJRUZQy/RQRjQaOmtbnIh30buXGveUSV+pMkkTYLnZii7G3GmXnthDHRk3AhS+SirkhRwMCVeexRrQa+ezq0NVxxpAMGCChtWYO4EQ5ehjI858wnEai+fYm+imOsREt6QOPVbFMvOz1SytpHKG2d0De4+rC/hMToWZ5HED5Ib2o7CtgcdHyPESAYQmSMjt2ZMtOON3RqVdkQNRn+iETWEIDvvSfauDl2tGxUmomLTI8g4JnjGxWGfLTQ0zjXDeNuY4EameWXnZ9mxRJEo2iC5c1DyDPecO3JI4QCWw5sB6nAcaZjTnKi3n0t1Mz3rCUhrjCHCY+7QBVslri+XpB/RqXs359Qifv6CNGFz3JWI9KBr4CDapxF0DN71G9WsiH0HAXUasDmMjP4gVxnkhnED5xgndXWurVuhqIf0E/Q46rRCG1YpyN1exkEwaxC/V0i6zprFGrHymJ5Bs= [email protected]" | ||
} |