Closed ds8080 closed 1 month ago
I can repro this issue. The logic is to create a view without the schema first and then update the view with the schema. But the api does not allow changing the mode from NULLABLE to REQUIRED.
POST /bigquery/v2/projects/myproject/datasets/issue14220/tables?alt=json&prettyPrint=false HTTP/1.1
Host: bigquery.googleapis.com
{
"labels": {
"env": "default"
},
"tableReference": {
"datasetId": "issue14220",
"projectId": "myproject",
"tableId": "public_view"
},
"timePartitioning": {
"type": "DAY"
},
"view": {
"query": "SELECT * FROM `myproject.issue14220.private_table`\n",
"useLegacySql": false
}
}
---[ RESPONSE ]--------------------------------------
HTTP/2.0 200 OK
{
"kind": "bigquery#table",
"etag": "lgwdPJC+OrywdLDBqT8/2g==",
"id": "myproject:issue14220.public_view",
"selfLink": "https://bigquery.googleapis.com/bigquery/v2/projects/myproject/datasets/issue14220/tables/public_view",
"tableReference": {
"projectId": "myproject",
"datasetId": "issue14220",
"tableId": "public_view"
},
"labels": {
"env": "default"
},
"schema": {
"fields": [
{
"name": "requiredField",
"type": "STRING",
"mode": "NULLABLE"
},
{
"name": "optionalField",
"type": "STRING",
"mode": "NULLABLE"
}
]
},
"timePartitioning": {
"type": "DAY"
},
"numBytes": "0",
"numLongTermBytes": "0",
"numRows": "0",
"creationTime": "1680732441241",
"lastModifiedTime": "1680732441578",
"type": "VIEW",
"view": {
"query": "SELECT * FROM `myproject.issue14220.private_table`\n",
"useLegacySql": false
},
"location": "US",
"numTotalLogicalBytes": "0",
"numActiveLogicalBytes": "0",
"numLongTermLogicalBytes": "0"
}
-----------------------------------------------------
PUT /bigquery/v2/projects/myproject/datasets/issue14220/tables/public_view?alt=json&prettyPrint=false HTTP/1.1
Host: bigquery.googleapis.com
{
"labels": {
"env": "default"
},
"schema": {
"fields": [
{
"description": "requiredField",
"mode": "REQUIRED",
"name": "requiredField",
"type": "STRING"
},
{
"description": "optionalField",
"mode": "NULLABLE",
"name": "optionalField",
"type": "STRING"
}
]
},
"tableReference": {
"datasetId": "issue14220",
"projectId": "myproject",
"tableId": "public_view"
},
"timePartitioning": {
"type": "DAY"
},
"view": {
"query": "SELECT * FROM `myproject.issue14220.private_table`\n",
"useLegacySql": false
}
}
---[ RESPONSE ]--------------------------------------
HTTP/2.0 400 Bad Request
{
"error": {
"code": 400,
"message": "Provided Schema does not match Table myproject:issue14220.public_view. Field requiredField has changed mode from NULLABLE to REQUIRED",
"errors": [
{
"message": "Provided Schema does not match Table myproject:issue14220.public_view. Field requiredField has changed mode from NULLABLE to REQUIRED",
"domain": "global",
"reason": "invalid"
}
],
"status": "INVALID_ARGUMENT"
}
}
b/280326829
closed with https://github.com/GoogleCloudPlatform/magic-modules/pull/7973
This will release with v5.0.0. Check https://github.com/hashicorp/terraform-provider-google/issues/15582 for more details on the major release.
reopened due to revert: https://github.com/GoogleCloudPlatform/magic-modules/pull/9204
I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.
Community Note
modular-magician
user, it is either in the process of being autogenerated, or is planned to be autogenerated soon. If an issue is assigned to a user, that user is claiming responsibility for the issue. If an issue is assigned tohashibot
, a community member has claimed the issue already.Terraform Version
We are using terraform-enterprise to deploy the terraform to our GCP projects Terraform Provider Version : 4.59.0 Terraform version : 1.2.3
Affected Resource(s)
Terraform Configuration Files
Debug Output
Link to gist with terraform apply output as seen in Terraform-Enterprise https://gist.github.com/ds8080/1666d2446e09ab338803bdb9bdb7f7e1
Panic Output
Expected Behavior
VIew should have been created with schema matching the GBQ table
Actual Behavior
View gets created with mode:NULLABLE columns even though we specify it as mode:REQUIRED in the terraform. So the terraform apply fails
Steps to Reproduce
terraform apply
Important Factoids
References
0000