-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Handle bigquery_reservation_capacity_commitment creation when capacit…
…y_commitment_id is unspecified (#9293) * handle bigquery_reservation_capacity_commitment creation when capacity_commitment_id is unspecified * revert change to import_format * fix indentation * add custom import * add custom import file
- Loading branch information
Showing
4 changed files
with
51 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
.../templates/terraform/custom_import/bigquery_reservation_capacity_commitment_set_id.go.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
config := meta.(*transport_tpg.Config) | ||
if err := tpgresource.ParseImportId([]string{ | ||
"^projects/(?P<project>[^/]+)/locations/(?P<location>[^/]+)/capacityCommitments/(?P<capacity_commitment_id>[^/]+)$", | ||
"^(?P<project>[^/]+)/(?P<location>[^/]+)/(?P<capacity_commitment_id>[^/]+)$", | ||
"^(?P<location>[^/]+)/(?P<capacity_commitment_id>[^/]+)$", | ||
}, d, config); err != nil { | ||
return nil, err | ||
} | ||
|
||
// Set name based on the components | ||
if err := d.Set("name", "projects/{{project}}/locations/{{location}}/capacityCommitments/{{capacity_commitment_id}}"); err != nil { | ||
return nil, fmt.Errorf("Error setting name: %s", err) | ||
} | ||
|
||
// Replace import id for the resource id | ||
id, err := tpgresource.ReplaceVars(d, config, d.Get("name").(string)) | ||
if err != nil { | ||
return nil, fmt.Errorf("Error constructing id: %s", err) | ||
} | ||
d.SetId(id) | ||
|
||
return []*schema.ResourceData{d}, nil |
14 changes: 7 additions & 7 deletions
14
mmv1/templates/terraform/examples/bigquery_reservation_capacity_commitment_basic.tf.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,15 @@ | ||
resource "google_bigquery_capacity_commitment" "<%= ctx[:primary_resource_id] %>" { | ||
capacity_commitment_id = "capacity-tf-test%{random_suffix}" | ||
capacity_commitment_id = "capacity-tf-test%{random_suffix}" | ||
|
||
location = "us-west2" | ||
slot_count = 100 | ||
plan = "FLEX_FLAT_RATE" | ||
edition = "ENTERPRISE" | ||
location = "us-west2" | ||
slot_count = 100 | ||
plan = "FLEX_FLAT_RATE" | ||
edition = "ENTERPRISE" | ||
} | ||
|
||
resource "time_sleep" "wait_61_seconds" { | ||
depends_on = [google_bigquery_capacity_commitment.<%= ctx[:primary_resource_id] %>] | ||
|
||
# Only needed for CI tests to be able to tear down the commitment once it's expired | ||
create_duration = "61s" | ||
create_duration = "61s" | ||
} |
13 changes: 13 additions & 0 deletions
13
mmv1/templates/terraform/examples/bigquery_reservation_capacity_commitment_no_id.tf.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
resource "google_bigquery_capacity_commitment" "<%= ctx[:primary_resource_id] %>" { | ||
location = "us-west2" | ||
slot_count = 100 | ||
plan = "FLEX_FLAT_RATE" | ||
edition = "ENTERPRISE" | ||
} | ||
|
||
resource "time_sleep" "wait_61_seconds" { | ||
depends_on = [google_bigquery_capacity_commitment.<%= ctx[:primary_resource_id] %>] | ||
|
||
# Only needed for CI tests to be able to tear down the commitment once it's expired | ||
create_duration = "61s" | ||
} |