Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add condition and accessPolicyVersion to BQ dataset access #8921

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changelog/12475.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
```release-note:enhancement
bigquery: added `condition` field to `google_bigquery_dataset_access` resource
```
```release-note:enhancement
bigquery: added `condition` field to `google_bigquery_dataset` resource
```
138 changes: 136 additions & 2 deletions google-beta/services/bigquery/resource_bigquery_dataset.go
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,40 @@ destroying the resource will fail if tables are present.`,
func bigqueryDatasetAccessSchema() *schema.Resource {
return &schema.Resource{
Schema: map[string]*schema.Schema{
"condition": {
Type: schema.TypeList,
Optional: true,
Description: `Condition for the binding. If CEL expression in this field is true, this
access binding will be considered.`,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"expression": {
Type: schema.TypeString,
Required: true,
Description: `Textual representation of an expression in Common Expression Language syntax.`,
},
"description": {
Type: schema.TypeString,
Optional: true,
Description: `Description of the expression. This is a longer text which describes the expression,
e.g. when hovered over it in a UI.`,
},
"location": {
Type: schema.TypeString,
Optional: true,
Description: `String indicating the location of the expression for error reporting, e.g. a file
name and a position in the file.`,
},
"title": {
Type: schema.TypeString,
Optional: true,
Description: `Title for the expression, i.e. a short string describing its purpose.
This can be used e.g. in UIs which allow to enter the expression.`,
},
},
},
},
"dataset": {
Type: schema.TypeList,
Optional: true,
Expand Down Expand Up @@ -593,7 +627,7 @@ func resourceBigQueryDatasetCreate(d *schema.ResourceData, meta interface{}) err
obj["labels"] = labelsProp
}

url, err := tpgresource.ReplaceVars(d, config, "{{BigQueryBasePath}}projects/{{project}}/datasets")
url, err := tpgresource.ReplaceVars(d, config, "{{BigQueryBasePath}}projects/{{project}}/datasets?accessPolicyVersion=3")
if err != nil {
return err
}
Expand Down Expand Up @@ -665,6 +699,7 @@ func resourceBigQueryDatasetRead(d *schema.ResourceData, meta interface{}) error
}

headers := make(http.Header)
url = url + "?accessPolicyVersion=3"
res, err := transport_tpg.SendRequest(transport_tpg.SendRequestOptions{
Config: config,
Method: "GET",
Expand Down Expand Up @@ -882,7 +917,7 @@ func resourceBigQueryDatasetUpdate(d *schema.ResourceData, meta interface{}) err
obj["labels"] = labelsProp
}

url, err := tpgresource.ReplaceVars(d, config, "{{BigQueryBasePath}}projects/{{project}}/datasets/{{dataset_id}}")
url, err := tpgresource.ReplaceVars(d, config, "{{BigQueryBasePath}}projects/{{project}}/datasets/{{dataset_id}}?accessPolicyVersion=3")
if err != nil {
return err
}
Expand Down Expand Up @@ -1014,6 +1049,7 @@ func flattenBigQueryDatasetAccess(v interface{}, d *schema.ResourceData, config
"view": flattenBigQueryDatasetAccessView(original["view"], d, config),
"dataset": flattenBigQueryDatasetAccessDataset(original["dataset"], d, config),
"routine": flattenBigQueryDatasetAccessRoutine(original["routine"], d, config),
"condition": flattenBigQueryDatasetAccessCondition(original["condition"], d, config),
})
}
return transformed
Expand Down Expand Up @@ -1142,6 +1178,41 @@ func flattenBigQueryDatasetAccessRoutineRoutineId(v interface{}, d *schema.Resou
return v
}

func flattenBigQueryDatasetAccessCondition(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
if v == nil {
return nil
}
original := v.(map[string]interface{})
if len(original) == 0 {
return nil
}
transformed := make(map[string]interface{})
transformed["expression"] =
flattenBigQueryDatasetAccessConditionExpression(original["expression"], d, config)
transformed["title"] =
flattenBigQueryDatasetAccessConditionTitle(original["title"], d, config)
transformed["description"] =
flattenBigQueryDatasetAccessConditionDescription(original["description"], d, config)
transformed["location"] =
flattenBigQueryDatasetAccessConditionLocation(original["location"], d, config)
return []interface{}{transformed}
}
func flattenBigQueryDatasetAccessConditionExpression(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
return v
}

func flattenBigQueryDatasetAccessConditionTitle(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
return v
}

func flattenBigQueryDatasetAccessConditionDescription(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
return v
}

func flattenBigQueryDatasetAccessConditionLocation(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
return v
}

func flattenBigQueryDatasetCreationTime(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
// Handles the string fixed64 format
if strVal, ok := v.(string); ok {
Expand Down Expand Up @@ -1440,6 +1511,13 @@ func expandBigQueryDatasetAccess(v interface{}, d tpgresource.TerraformResourceD
transformed["routine"] = transformedRoutine
}

transformedCondition, err := expandBigQueryDatasetAccessCondition(original["condition"], d, config)
if err != nil {
return nil, err
} else if val := reflect.ValueOf(transformedCondition); val.IsValid() && !tpgresource.IsEmptyValue(val) {
transformed["condition"] = transformedCondition
}

req = append(req, transformed)
}
return req, nil
Expand Down Expand Up @@ -1623,6 +1701,62 @@ func expandBigQueryDatasetAccessRoutineRoutineId(v interface{}, d tpgresource.Te
return v, nil
}

func expandBigQueryDatasetAccessCondition(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
l := v.([]interface{})
if len(l) == 0 || l[0] == nil {
return nil, nil
}
raw := l[0]
original := raw.(map[string]interface{})
transformed := make(map[string]interface{})

transformedExpression, err := expandBigQueryDatasetAccessConditionExpression(original["expression"], d, config)
if err != nil {
return nil, err
} else if val := reflect.ValueOf(transformedExpression); val.IsValid() && !tpgresource.IsEmptyValue(val) {
transformed["expression"] = transformedExpression
}

transformedTitle, err := expandBigQueryDatasetAccessConditionTitle(original["title"], d, config)
if err != nil {
return nil, err
} else if val := reflect.ValueOf(transformedTitle); val.IsValid() && !tpgresource.IsEmptyValue(val) {
transformed["title"] = transformedTitle
}

transformedDescription, err := expandBigQueryDatasetAccessConditionDescription(original["description"], d, config)
if err != nil {
return nil, err
} else if val := reflect.ValueOf(transformedDescription); val.IsValid() && !tpgresource.IsEmptyValue(val) {
transformed["description"] = transformedDescription
}

transformedLocation, err := expandBigQueryDatasetAccessConditionLocation(original["location"], d, config)
if err != nil {
return nil, err
} else if val := reflect.ValueOf(transformedLocation); val.IsValid() && !tpgresource.IsEmptyValue(val) {
transformed["location"] = transformedLocation
}

return transformed, nil
}

func expandBigQueryDatasetAccessConditionExpression(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
return v, nil
}

func expandBigQueryDatasetAccessConditionTitle(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
return v, nil
}

func expandBigQueryDatasetAccessConditionDescription(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
return v, nil
}

func expandBigQueryDatasetAccessConditionLocation(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
return v, nil
}

func expandBigQueryDatasetDatasetReference(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
transformed := make(map[string]interface{})
transformedDatasetId, err := expandBigQueryDatasetDatasetReferenceDatasetId(d.Get("dataset_id"), d, config)
Expand Down
Loading
Loading