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

Handle bigquery_reservation_capacity_commitment creation when capacity_commitment_id is unspecified #9293

Merged
merged 5 commits into from
Oct 20, 2023
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
12 changes: 9 additions & 3 deletions mmv1/products/bigqueryreservation/CapacityCommitment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
name: 'CapacityCommitment'
base_url: projects/{{project}}/locations/{{location}}/capacityCommitments
create_url: projects/{{project}}/locations/{{location}}/capacityCommitments?capacityCommitmentId={{capacity_commitment_id}}
self_link: 'projects/{{project}}/locations/{{location}}/capacityCommitments/{{capacity_commitment_id}}'
self_link: '{{name}}'
zli82016 marked this conversation as resolved.
Show resolved Hide resolved
update_verb: :PATCH
update_mask: true
description: |
Expand All @@ -26,19 +26,25 @@ references: !ruby/object:Api::Resource::ReferenceLinks
guides:
'Introduction to Reservations': 'https://cloud.google.com/bigquery/docs/reservations-intro'
api: 'https://cloud.google.com/bigquery/docs/reference/reservations/rest/v1/projects.locations.capacityCommitments'
id_format: 'projects/{{project}}/locations/{{location}}/capacityCommitments/{{capacity_commitment_id}}'
id_format: '{{name}}'
import_format:
[
'projects/{{project}}/locations/{{location}}/capacityCommitments/{{capacity_commitment_id}}',
]
custom_code: !ruby/object:Provider::Terraform::CustomCode
constants: templates/terraform/constants/bigquery_reservation_capacity_commitment.go.erb
custom_import: templates/terraform/custom_import/bigquery_reservation_capacity_commitment_set_id.go.erb
examples:
- !ruby/object:Provider::Terraform::Examples
name: 'bigquery_reservation_capacity_commitment_basic'
pull_external: true
skip_docs: true
primary_resource_id: 'commitment'
- !ruby/object:Provider::Terraform::Examples
name: 'bigquery_reservation_capacity_commitment_no_id'
pull_external: true
skip_docs: true
primary_resource_id: 'commitment'
- !ruby/object:Provider::Terraform::Examples
name: 'bigquery_reservation_capacity_commitment_docs'
skip_test: true
Expand Down Expand Up @@ -102,7 +108,7 @@ properties:
- !ruby/object:Api::Type::String
name: 'renewalPlan'
description: |
The plan this capacity commitment is converted to after commitmentEndTime passes. Once the plan is changed, committed period is extended according to commitment plan. Only applicable some commitment plans.
The plan this capacity commitment is converted to after commitmentEndTime passes. Once the plan is changed, committed period is extended according to commitment plan. Only applicable for some commitment plans.
- !ruby/object:Api::Type::String
name: 'edition'
immutable: true
Expand Down
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
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"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
resource "google_bigquery_capacity_commitment" "<%= ctx[:primary_resource_id] %>" {
zli82016 marked this conversation as resolved.
Show resolved Hide resolved
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"
}