Create project in Google Cloud using Terraform
Create project in Google Cloud
Here is the beginning of everything, before having your vm, sql and etc you have to have the project. Follow the softness.
provider "google" {
credentials = file("<path_to_service_account_key_json>")
project = "<your_organization_id>"
region = "us-central1"
}
resource "google_project" "example" {
name = "example-project"
project_id = "example-project-id"
org_id = "<your_organization_id>"
billing_account = "<your_billing_account_id>"
}
resource "google_project_service" "compute" {
project = google_project.example.project_id
service = "compute.googleapis.com"
}
resource "google_project_service" "iam" {
project = google_project.example.project_id
service = "iam.googleapis.com"
}
resource "google_project_service" "storage" {
project = google_project.example.project_id
service = "storage.googleapis.com"
}
output "project_id" {
value = google_project.example.project_id
}
Be sure to replace <path_to_service_account_key_json>, <your_organization_id>, and <your_billing_account_id> with the appropriate values for your environment. The above example creates a new project on Google Cloud, defines a name and ID for the project, and associates it with a specific billing account. Additionally, the example enables Compute Engine (compute.googleapis.com), IAM (iam.googleapis.com), and Google Cloud Storage (storage.googleapis.com) services for the project.
After running Terraform, you can use the project_id output to identify the ID of the newly created project.
Hope you like it!!!