# Create BigQuery dataset and table using terraform

Create BigQuery dataset and table using terraform

This is series BigQuery 101. Here in this blogs I am going to build base of our project by creating BigQuery dataset and tables using **terraform**.

You can also find this code in GitHub

[**GitHub - sudovazid/gcp\_terraform: Here is mostly terraform project avaiable to develop on Google…**  
\*You can't perform that action at this time. You signed in with another tab or window. You signed out in another tab or…\*github.com](https://github.com/sudovazid/gcp_terraform)

Now before starting terraform code let’s understand dataset and table in BigQuery

> As per google cloud **a dataset** is contained within a specific [project](https://cloud.google.com/docs/overview#projects). Datasets are top-level containers that are used to organize and control access to your [tables](https://cloud.google.com/bigquery/docs/tables) and [views](https://cloud.google.com/bigquery/docs/views)

And in this blog we are going to use dataset to migrate store tables data and querying

In datasets folder we will have three terraform files ***main.tf, variable.tf,*** and ***output.tf***

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1679902667896/fc506e00-fabf-41cc-97b1-6eb78f2222e2.png align="left")

BigQuery dataset table folder

We will create ***main.tf***, ***variable.tf***, ***output.tf*** file on terraform folder In this main file we will have dataset resources to deploy BigQuery dataset, variable file will have variable which are going to be use in building dataset and output file to get dataset id after creating dataset which will be used to create tables

### dataset.tf

Deploy dataset to BigQuery

### variable.tf

### output.tf

Now we will start with table folder

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1679902669438/157d98a3-9f37-4423-a587-648a16d5576b.png align="left")

BigQuery table folder

Here we have **main.tf** and **variable.tf**

> A BigQuery table contains individual records organized in rows. Each record is composed of columns (also called *fields*).

### table.tf

### variable.tf

Let’s combine all the resource with building modules.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1679902670951/1a8c5ff3-ed61-4b8a-9c0a-b5c72ae34882.png align="left")

BigQuery terraform module structure

Here we have **main.tf** to create terraform modules, **variable.tf** here we declare all the variables and **terraform.tfvars** here we pass the value in variables here we can also pass the provider variables :- ***project\_id, region, zone***

### main.tf

### variable.tf

### terraform.tfvars

### **Conclusion**

Here In this blog we have successfully deployed BigQuery dataset and table using terraform

### **References**

[**Introduction to tables | BigQuery | Google Cloud**  
\*A BigQuery table contains individual records organized in rows. Each record is composed of columns (also called…\*cloud.google.com](https://cloud.google.com/bigquery/docs/tables-intro)

[**Introduction to datasets | BigQuery | Google Cloud**  
\*This page provides an overview of datasets in BigQuery. A dataset is contained within a specific project. Datasets are…\*cloud.google.com](https://cloud.google.com/bigquery/docs/datasets-intro)
