This terraform module and code repository is intended to be used to deploy various types of GCP Projects.
The three types of projects deployed using this module are: VPC Host Projects, Service Projects, and GCP Projects (with self-contained, or no, VPCs).
Following the sequential build system that these modules are intended for, a VPC Host project needs to be created so that a Shared VPC (SVPC) can be created. Once the SVPC is created, then a Service Project can be created and attached to the SVPC accordingly. GCP Projects, without reliance on, or an intention of creating a SPVC, can be created at any time.
The following permissions are required to be given to the service account, or user, being used to deploy this module for the following types of deployment.
The following permissions are required at the folder, or the organization level, depending on the parent of the project:
resourcemanager.organizations.get
resourcemanager.projects.create
orgpolicy.constraints.list
orgpolicy.policies.list
orgpolicy.policy.get
resourcemanager.folders.get
resourcemanager.folders.list
resourcemanager.projects.get
resourcemanager.projects.list
Alternatively, these permissions are contained within the predefined roles: Folder Viewer(roles/resourcemanager.folderViewer) and Project Creator(roles/resourcemanager.projectCreator).
In addition to the permissions above, the service account, or user, will need the following permissions on the network, or the project hosting the network, in order to attach the project to the SVPC. These permissions are contained in the predefined role Network User(roles/compute.networkUser).
The permissions for Network User are extensive and can be found here
The service account, or user, deploying the code will need to have the permissions-equivalent of Project Creator(roles/resourcemanager.projectCreator) and the Network Admin(roles/compute.networkAdmin) predefined roles in order to maintain and manage the host-VPC. In addition to the Project Creator role.
The Network Admin specific permissions are extensive and can be found here.
This repository, like the other modules in the GCP Toolkit set of modules, is intended to be deployed via variable values declared in a .tfvars file in an environment folder. The below example represents a block of code for deploying a non-SVPC attached VPC with Compute, OsLogin, and Container APIs included to be activated when the project is deployed.
projects = {
iap-project-template-v1 = {
uses_vpc_host_project = false
is_vpc_host_project = false
default_srv_accnt_action = "DEPRIVILEGE" # Creates the Default API SVC Account but removes IAM Roles
create_project_srv_accnt = true
org_id = ""
folder_id = ""
skip_delete = false
auto_create_network = false
activate_additional_apis = [
"compute.googleapis.com"
]
labels = {
managed_by = "terraform"
env = "back-to-demo"
}
per_project_iam_roles = {
"roles/compute.instanceAdmin.v1" = {
members = ["user:ktibbs9413@gmail.com"]
},
"roles/compute.admin" = {
members = ["serviceAccount:terraform-service-account@project_id.iam.gserviceaccount.com"]
},
"roles/iap.admin" = {
members = ["serviceAccount:terraform-service-account@project_id.iam.gserviceaccount.com"]
},
"roles/storage.admin" = {
members = ["serviceAccount:terraform-service-account@project_id.iam.gserviceaccount.com"]
}
}
},
}
service_account = {
"service_accounts" = {
project_id = "iap-project-template-v1"
service_account = {
"gce-svc-acc" = {
display_name = "GCE Service Account"
members = ["user:user@gmail.com"]
role = "roles/iam.serviceAccountUser"
}
}
}
}
custom_vpc = {
"iap-demo" = {
project_id = "iap-project-template-v1"
auto_create_subnetworks = false
subnets = {
"iap-west" = {
ip_cidr_range = "10.1.0.0/16"
subnet_region = "us-west4"
},
"iap-centrl" = {
ip_cidr_range = "10.2.0.0/16"
subnet_region = "us-central1"
},
}
}
}
firewall_rules = {
"iap-demo-firewall" = {
project_id = "iap-project-template-v1"
firewall_rule = {
"fw-999-allow-iap-tcp-forwarding" = {
vpc_name = "iap-demo"
allow = [{
ports = ["22"]
protocol = "tcp"
}]
description = "Allows Google's IP to forward SSH traffic over HTTPS"
direction = "INGRESS"
priority = 999
ranges = ["35.235.240.0/20"]
},
}
}
}
gce_instance = {
"iap-demo" = {
project_id = "iap-project-template-v1"
hostname = "iap-demo"
region = "us-west4"
zone = "us-west4-a"
machine_type = "e2-micro"
gce_image = "debian-cloud/debian-10"
gce_service_account_email = "gce-svc-acc@iap-project-template-v1.iam.gserviceaccount.com"
tags = ["demo"]
labels = {
env = "demo"
}
network_interface = {
"network" = {
subnet_name = "iap-west"
}
}
}
}
iap-iam = {
"iap-tunnel-instance" = {
instance = "iap-demo"
zone = "us-west4-a"
project_id = "iap-project-template-v1"
role = "roles/iap.tunnelResourceAccessor"
members = ["user:user@gmail.com"]
}
}
| Name | Version |
|---|---|
| google-beta | >=4.41.0 |
No providers.
| Name | Source | Version |
|---|---|---|
| gcp-projects | ./modules/gcp-project | n/a |
| service-projects | ./modules/gcp-project | n/a |
| vpc-host-projects | ./modules/gcp-project | n/a |
No resources.
| Name | Description | Type | Default | Required |
|---|---|---|---|---|
| environment | n/a | any |
n/a | yes |
| iam_roles | n/a | map(object({ |
{} |
no |
| project_id | terraform project. | any |
n/a | yes |
| projects | List of project objects. | map(object({ |
{} |
no |
| service_projects | List of service project objects. these must be created after vpc host projects | map(any) |
{} |
no |
| vpc_host_projects | List of vpc host project objects. these must be created first | map(any) |
{} |
no |
| Name | Description |
|---|---|
| gcp-projects_outputs | n/a |
| service-projects_outputs | n/a |
| vpc-host-projects_outputs | n/a |