Skip to content

JamesWoolfenden/terraform-gcp-bastion

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

terraform-gcp-bastion

Build Status Latest Release GitHub tag (latest SemVer) Terraform Version Infrastructure Tests pre-commit checkov Infrastructure Tests

The beginnings of a bastion module for GCP, now with compute firewall options. The Bastion is designed to work primarily with a private Kubernetes Cluster and is enabled for OS Logins. You'll need to add the service role an OS role to your users they will be able to SSH into it. Basic Kubernetes tools are also installed into the bastion by default.

2 examples are included, one with and one without a static IP. To find the image family and project:

gcloud compute images list
gcloud kms locations list
gcloud kms keyrings create --location=europe-west1 pike

Usage

Add module.bastion.tf to your code:-

module "bastion" {
  source             = "JamesWoolfenden/bastion/gcp"
  version            = "0.1.13"
  image              = var.image
  name               = var.name
  network_interface  = var.network_interface
  project            = var.project
  service_email      = var.service_email
  source_cidrs       = var.source_cidrs
  zone               = var.zone
}

Requirements

No requirements.

Providers

Name Version
google n/a

Modules

No modules.

Resources

Name Type
google_compute_firewall.ssh-bastion resource
google_compute_instance.bastion resource
google_compute_image.image data source
google_service_account.default data source

Inputs

Name Description Type Default Required
account_id n/a any n/a yes
firewall Flag to control the creation or not of a firewall rule. Maybe not needed if you use a pre-prepared or shared set-up number 0 no
image Describes the base image used map(any) n/a yes
init_script n/a string n/a yes
keyring n/a string "pike" no
kms_key_name n/a string "bastion" no
location n/a string "europe-west1" no
machine_type The machine type for the Bastion string "n1-standard-1" no
name The name of the Bastion Instance string "bastion" no
nat_ip Values set if using a Static IP any null no
network_interface n/a map(any) n/a yes
service_email Service account username string n/a yes
service_scope n/a list(any)
[
"https://www.googleapis.com/auth/cloud-platform"
]
no
source_cidrs The ranges to allow to connect to the bastion list(any) n/a yes
tags Hard-coded tags that associates the correct firewall to the instance list(any)
[
"bastion-ssh"
]
no
zone The GCP zone string n/a yes

Outputs

Name Description
bastion The Attributes of the Bastion
firewall The Attributes of the firewall
image The Attributes of the Image

Role and Permissions

The Terraform resource required is:

resource "google_project_iam_custom_role" "terraform_pike" {
  project     = "pike"
  role_id     = "terraform_pike"
  title       = "terraform_pike"
  description = "A user with least privileges"
  permissions = [
    "compute.disks.create",
    "compute.firewalls.create",
    "compute.firewalls.delete",
    "compute.firewalls.get",
    "compute.firewalls.update",
    "compute.instances.create",
    "compute.instances.delete",
    "compute.instances.get",
    "compute.instances.setMetadata",
    "compute.instances.setTags",
    "compute.networks.updatePolicy",
    "compute.subnetworks.use",
    "compute.subnetworks.useExternalIp",
    "compute.zones.get",
    "iam.serviceAccounts.get"
  ]
}

Information

Related Projects

Check out these related projects.

Help

Got a question?

File a GitHub issue.

Contributing

Bug Reports & Feature Requests

Please use the issue tracker to report any bugs or file feature requests.

Copyrights

Copyright © 2019-2023 James Woolfenden

License

License

See LICENSE for full details.

Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

https://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Contributors

James Woolfenden
James Woolfenden