This contains instruction on how to create a Google cloud storage, Google storage buckets and Google compute engine using Terraform
- What is Terraform?
- open-source tool by HashiCorp, used for provisioning infrastructure resources
- supports DevOps best practices for change management
- Managing configuration files in source control to maintain an ideal provisioning state for testing and production environments
- What is IaC?
- Infrastructure-as-Code
- build, change, and manage your infrastructure in a safe, consistent, and repeatable way by defining resource configurations that you can version, reuse, and share.
- Some advantages
- Infrastructure lifecycle management
- Version control commits
- Very useful for stack-based deployments, and with cloud providers such as AWS, GCP, Azure, K8S…
- State-based approach to track resource changes throughout deployments
visit Terraform Download page to download either for windows, linux or Mac OS. Also follow the instructions to setting Terraform.
To verify your installation, run terraform -help
- A google cloud platform account. If you don't have one, you can create a free account thats comes with a $300 credit here
- A GCP project. create one here. Keep note of your Project ID. it should look like this
PROJECT_NAME-453233
- Enable Compute Engine for your project in the GCP Console
- Create a Service Account key. This will used throughout the entire project.
- Select the project you created in the previous step
- Navigate to the IAM section
- Click on Create Service account
- choose a name of your choice, then create and continue
- Select Role. Since we will be using this service account for the project, then we will select all the roles that will be needed.
- BigQuery Admin
- Compute Admin
- Storage Admin
- Storage Object Admin
- Skip granting additional users access, and click "Done".
After you create your service account, download your service account key.
- Select your service account from the list.
- Select the "Keys" tab.
- In the drop down menu, select "Create new key".
- Leave the "Key Type" as JSON.
- Click "Create" to create the key and save the key file to your system.
-
create a directory
mkdir gcp-terraform
-
enter into the directory
cd gcp-terraform
-
create a new file
touch main.tf
and copy the content of main.tf into it -
copy the filepath of your service key account and paste it in the
filepath.json
in themain.tf
files -
create another file in the same directory
touch variables.tf
and copy the content of variables.tf into it -
Configure the variables in
variables.tf
- set your project_id, region, BQ_DATASET, cloud_storage, compute_instance
NOTE: the machine type used in the project is a c3 machine type, which is currently in preview. you can use an alternative machine type like
e2-standard-8
by editing the configuration inmain.tf
.
- set your project_id, region, BQ_DATASET, cloud_storage, compute_instance
NOTE: the machine type used in the project is a c3 machine type, which is currently in preview. you can use an alternative machine type like
-
open terminal and run
terraform init
to initialize files. This might take a few mins. -
run
terraform plan
to see the infrastructure to be created. -
run
terraform apply
to create the infrasture. a prompt will be ask, typeyes
to preceed.
You have successfully created a compute engine, a cloud storage bucket and a bigquery warehouse. run terraform show
to see the configurations.
continue setup here