Authorize views in bigquery using terraform script - Facing error

Hi Everyone!

I’m trying to authorize my bigquery views against their base tables using a terraform script. But I’m unable to do as it is throwing me error as mentioned below. Can someone able to help me, please?

Error -

Error: Unsupported argument

on main.tf line 120, in module “data_authorized_views”

120:   authorized_datasets = [

An argument named “authorized_datasets” is not expected here.


Error: Unsupported argument

On main.tf line 120, in module “data_authorized_views”

120:   authorized_views = [

An argument named “authorized_views” is not expected here.   

Below is the code snippet.

module “data_authorized_views” {
	source = “terraform-google-modules/bigquery/google//modules/authorization”
	version = “~>0.12”

	dataset_id = module.bq_data_set.bigquery_dataset.dataset_id
	project_id = module.bq_data_set.bigquery_dataset.project

	authorized_datasets = [
		{
			project_id = module.bq_data_set.bigquery_dataset.project
			dataset_id = “data_tables”
		}
	]

	authorized_views = [
		{
			project_id = module.bq_data_set.bigquery_dataset.project
			dataset_id = “data_views”
		}
	]

I have taken the following link as reference to create terraform script.

https://registry.terraform.io/modules/terraform-google-modules/bigquery/google/latest/submodules/authorization

Thank you!

You have specified an exceedingly old version of the module. The current version is 5.4.2.

Thanks for the response @maxb - I’ve updated it to the latest version ~5.4.2, still it is throwing the same error.

~5.4.2 is not a valid Terraform version expression. I suppose you mean ~> 5.4.2.

That module version supports the parameter names in your earlier post.

I even copied your config snippet into a local file, fixed the incorrect smart quotes and missing closing brace, replaced the references to other data with empty values, and confirmed that terraform validate passes.

That’s all I can say based on the information you’ve provided.

Thank you @maxb

I’m trying with the below code -


module "edw_authorized_views" {
   source  = "terraform-google-modules/bigquery/google//modules/authorization"
   version = "~> 5.4.2"

   dataset_id = module.edw_bq_data_set_view_test.bigquery_dataset.dataset_id
   project_id = module.edw_bq_data_set_view_test.bigquery_dataset.project

   authorized_views = [
   {
      project_id = data.google_project.edw-prcd-bq.project_id
      dataset_id = "edw_publish_view_test"
      table_id = ""

    }
  ]

  authorized_datasets = [
  {
     project_id = data.google_project.edw-stage-bq.project_id
     dataset_id = "edw_view_test"
   }
  ]
}

When executing the above terraform (terraform plan), getting the following error

bash-5.1$ terraform plan
╷
│ Error: Invalid value for module argument
│
│   on main.tf line 1153, in module "edw_authorized_views":
│ 1153:    authorized_views = [
│ 1154:    {
│ 1155:       project_id = data.google_project.edw-prcd-bq.project_id
│ 1156:       dataset_id = "edw_publish_view_test"
│ 1157:       table_id = []
│ 1158:     }
│ 1159:   ]
│
│ The given value is not suitable for child module variable "authorized_views" defined at .terraform/modules/edw_authorized_views/modules/authorization/variables.tf:39,1-28: element 0: attribute "table_id": string
│ required.
╵
╷
│ Error: Unsupported block type
│
│   on .terraform/modules/edw_authorized_views/modules/authorization/main.tf line 68, in resource "google_bigquery_dataset_access" "authorized_dataset":
│   68:   dataset {
│
│ Blocks of type "dataset" are not expected here.

This is what it is there in 68th line of - .terraform/modules/edw_authorized_views/modules/authorization/main.tf

resource "google_bigquery_dataset_access" "authorized_dataset" {
  for_each   = local.datasets
  dataset_id = var.dataset_id
  project    = var.project_id
  dataset {
    dataset {
      project_id = each.value.project_id
      dataset_id = each.value.dataset_id
    }
    target_types = ["VIEWS"]
  }
}

Can you please help me to identify where I’m doing wrong? Thanks!