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
40 changes: 40 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Run unit tests
name: terraform-build
#description: To perform terraform build
#author: Karthick Dharman.

# Triggers the workflow on all push or pull request events
on: [push, pull_request]

# The jobs that we will beed to run terraform
jobs:
# This workflow contains a single job called "build"
build:
# The type of runner that the job will run on
runs-on: ubuntu-latest

# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- name: Checkout Codebase
uses: actions/checkout@v2

- name: setup terraform
uses: hashicorp/setup-terraform@v1
with:
terraform_version: '1.1.2'

- name: terraform init
run: terraform init --input=false

- name: terraform format
run: terraform fmt -check

- name: terraform validate
run: terraform validate

- name: terraform scan
uses: accurics/terrascan-action@main
with:
iac_type: 'terraform'

22 changes: 15 additions & 7 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
# Local .terraform directories
**/.terraform/*

# .tfstate files
# Compiled files
*.tfstate
*.tfstate.*
*.tfstate.backup
*.tfstate.lock.info
*.plan
*.terraform.lock.hcl

# Directories
.terraform/
.vs/
.idea/

# SSH Keys
*.pem

**/.idea
**/*.iml
# Ignore Mac .DS_Store files
.DS_Store
41 changes: 38 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,40 @@
# terraform-google-project [![Latest Release](https://img.shields.io/github/release/bootlabstech/terraform-google-project.svg)](https://github.com/bootlabstech/terraform-google-project/releases/latest)
# terraform-google-project

[![Bootlabstech][logo]](https://www.bootlabs.in)
### Build
Please use the below commands to run terraform.

[logo]: https://www.bootlabs.in/wp-content/uploads/2020/09/logo.png
```
terraform init --input=false
terraform plan
terraform apply
```

### Clean Up
To destroy the resources that you have created please use the below command.

```
terraform destroy
```

### Provider Dependencies
Providers are Terraform plugins that will be automatically installed during `terraform init` if available on the Terraform registry.
```
Terraform version >= 1.1.2
google(hashicorp/google) >= 4.1.0
```


### Module Dependencies
Dependencies are external modules that this module references. A module is considered external if it isn't within the same repository.

This module has no external module dependencies.

### Prerequisites
#### IAM Permissions
Please ensure the below IAM permissions are in place to create this google project on the specified organization.

```
roles/resourcemanager.projectCreator
```
#### API Enablement
NA
18 changes: 9 additions & 9 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,28 @@ resource "google_project" "my_project" {
}

resource "random_string" "random" {
length = 6
special = false
lower = false
upper = false
length = 6
special = false
lower = false
upper = false
}

resource "google_project_service" "project" {
for_each = toset(var.service_apis)
project = google_project.my_project.id
service = each.key
project = google_project.my_project.id
service = each.key

disable_dependent_services = false
disable_on_destroy = true
disable_on_destroy = true
}

resource "google_compute_shared_vpc_host_project" "host" {
count = var.is_host_project ? 1 : 0
count = var.is_host_project ? 1 : 0
project = google_project.my_project.project_id
}

resource "google_compute_shared_vpc_service_project" "service" {
count = var.is_service_project ? 1 : 0
count = var.is_service_project ? 1 : 0
host_project = var.host_project_id
service_project = google_project.my_project.project_id
}
8 changes: 4 additions & 4 deletions provider.tf
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
terraform {
required_version = ">=0.13"
required_version = "1.1.2"

required_providers {
google = {
source = "hashicorp/google"
source = "hashicorp/google"
version = "4.1.0"
}
}
}
}
53 changes: 47 additions & 6 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,41 @@ variable "project_id_prefix" {

variable "billing_account" {
type = string
description = "The alphanumeric ID of the billing account this project belongs to. The user or service account performing this operation with Terraform must have at minimum Billing Account User privileges (roles/billing.user) on the billing account."
description = <<-EOT
{
"type": "api",
"purpose": "autocomplete",
"data": "/api/v1/autocomplete/billingid",
"description": "The alphanumeric ID of the billing account this project belongs to."
}
EOT
}

variable "org_id" {
type = string
description = "The numeric ID of the organization this project belongs to. Changing this forces a new project to be created. Only one of org_id or folder_id may be specified. If the org_id is specified then the project is created at the top level. Changing this forces the project to be migrated to the newly specified organization."
description = <<-EOT
{
"type": "api",
"purpose": "autocomplete",
"data": "/api/v1/autocomplete/organizationID",
"description": "The numeric ID of the organization this project belongs to. Changing this forces a new project to be created."
}
EOT
}

// optional variables
variable "auto_create_network" {
type = bool
description = "Create the 'default' network automatically. Default false. If set to false, the default network will be deleted. Note that, for quota purposes, you will still need to have 1 network slot available to create the project successfully, even if you set auto_create_network to false, since the network will exist momentarily."
description = <<-EOT
{
"type": "json",
"purpose": "autocomplete",
"data": [ "true",
"false"
],
"description": "Create the 'default' network automatically."
}
EOT
default = false
}

Expand All @@ -34,18 +57,36 @@ variable "service_apis" {

variable "is_host_project" {
type = bool
description = "Set to true if this project should be a host project; both this and is_service_project cannot be true"
description = <<-EOT
{
"type": "json",
"purpose": "autocomplete",
"data": [ "true",
"false"
],
"description": "Set to true if this project should be a host project; both this and is_service_project cannot be true"
}
EOT
default = false
}

variable "is_service_project" {
type = bool
description = "Set to true if this project should be a service project; both this and is_host_project cannot be true"
description = <<-EOT
{
"type": "json",
"purpose": "autocomplete",
"data": [ "true",
"false"
],
"description": "Set to true if this project should be a service project; both this and is_host_project cannot be true"
}
EOT
default = false
}

variable "host_project_id" {
type = string
description = "the host project id; only needed when is_service_project is set to true"
default = ""
}
}