diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..57af94f --- /dev/null +++ b/.github/workflows/build.yml @@ -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' + \ No newline at end of file diff --git a/.gitignore b/.gitignore index abe5147..66c17e4 100644 --- a/.gitignore +++ b/.gitignore @@ -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 diff --git a/README.md b/README.md index eebdec9..37e2e28 100644 --- a/README.md +++ b/README.md @@ -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 \ No newline at end of file +``` +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 diff --git a/main.tf b/main.tf index ac3569a..e4c0094 100644 --- a/main.tf +++ b/main.tf @@ -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 } \ No newline at end of file diff --git a/provider.tf b/provider.tf index 2fbd8b3..7596a1b 100644 --- a/provider.tf +++ b/provider.tf @@ -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" } } -} \ No newline at end of file +} diff --git a/variables.tf b/variables.tf index 918deea..14e85cf 100644 --- a/variables.tf +++ b/variables.tf @@ -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 } @@ -34,13 +57,31 @@ 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 } @@ -48,4 +89,4 @@ variable "host_project_id" { type = string description = "the host project id; only needed when is_service_project is set to true" default = "" -} \ No newline at end of file +}