diff --git a/.changelog/4273.txt b/.changelog/4273.txt new file mode 100644 index 00000000000..6001dd428c7 --- /dev/null +++ b/.changelog/4273.txt @@ -0,0 +1,6 @@ +```release-note:breaking-change +billing: import support for `google_billing_budget` never functioned correctly, and has been removed. +``` +```release-note:enhancement +billing: promoted `google_billing_budget` to GA +``` diff --git a/google/config.go b/google/config.go index 8a6c1cfe733..e2ce973cf53 100644 --- a/google/config.go +++ b/google/config.go @@ -90,6 +90,7 @@ type Config struct { BigQueryBasePath string BigqueryDataTransferBasePath string BigtableBasePath string + BillingBasePath string BinaryAuthorizationBasePath string CloudAssetBasePath string CloudBuildBasePath string @@ -166,6 +167,7 @@ var AppEngineDefaultBasePath = "https://appengine.googleapis.com/v1/" var BigQueryDefaultBasePath = "https://bigquery.googleapis.com/bigquery/v2/" var BigqueryDataTransferDefaultBasePath = "https://bigquerydatatransfer.googleapis.com/v1/" var BigtableDefaultBasePath = "https://bigtableadmin.googleapis.com/v2/" +var BillingDefaultBasePath = "https://billingbudgets.googleapis.com/v1/" var BinaryAuthorizationDefaultBasePath = "https://binaryauthorization.googleapis.com/v1/" var CloudAssetDefaultBasePath = "https://cloudasset.googleapis.com/v1/" var CloudBuildDefaultBasePath = "https://cloudbuild.googleapis.com/v1/" @@ -952,6 +954,7 @@ func ConfigureBasePaths(c *Config) { c.BigQueryBasePath = BigQueryDefaultBasePath c.BigqueryDataTransferBasePath = BigqueryDataTransferDefaultBasePath c.BigtableBasePath = BigtableDefaultBasePath + c.BillingBasePath = BillingDefaultBasePath c.BinaryAuthorizationBasePath = BinaryAuthorizationDefaultBasePath c.CloudAssetBasePath = CloudAssetDefaultBasePath c.CloudBuildBasePath = CloudBuildDefaultBasePath diff --git a/google/provider.go b/google/provider.go index d2d38e531cd..b647c7c32db 100644 --- a/google/provider.go +++ b/google/provider.go @@ -191,6 +191,14 @@ func Provider() *schema.Provider { "GOOGLE_BIGTABLE_CUSTOM_ENDPOINT", }, BigtableDefaultBasePath), }, + "billing_custom_endpoint": { + Type: schema.TypeString, + Optional: true, + ValidateFunc: validateCustomEndpoint, + DefaultFunc: schema.MultiEnvDefaultFunc([]string{ + "GOOGLE_BILLING_CUSTOM_ENDPOINT", + }, BillingDefaultBasePath), + }, "binary_authorization_custom_endpoint": { Type: schema.TypeString, Optional: true, @@ -687,9 +695,9 @@ func Provider() *schema.Provider { return provider } -// Generated resources: 176 +// Generated resources: 177 // Generated IAM resources: 75 -// Total generated resources: 251 +// Total generated resources: 252 func ResourceMap() map[string]*schema.Resource { resourceMap, _ := ResourceMapWithErrors() return resourceMap @@ -725,6 +733,7 @@ func ResourceMapWithErrors() (map[string]*schema.Resource, error) { "google_bigquery_routine": resourceBigQueryRoutine(), "google_bigquery_data_transfer_config": resourceBigqueryDataTransferConfig(), "google_bigtable_app_profile": resourceBigtableAppProfile(), + "google_billing_budget": resourceBillingBudget(), "google_binary_authorization_attestor": resourceBinaryAuthorizationAttestor(), "google_binary_authorization_attestor_iam_binding": ResourceIamBinding(BinaryAuthorizationAttestorIamSchema, BinaryAuthorizationAttestorIamUpdaterProducer, BinaryAuthorizationAttestorIdParseFunc), "google_binary_authorization_attestor_iam_member": ResourceIamMember(BinaryAuthorizationAttestorIamSchema, BinaryAuthorizationAttestorIamUpdaterProducer, BinaryAuthorizationAttestorIdParseFunc), @@ -1142,6 +1151,7 @@ func providerConfigure(ctx context.Context, d *schema.ResourceData, p *schema.Pr config.BigQueryBasePath = d.Get("big_query_custom_endpoint").(string) config.BigqueryDataTransferBasePath = d.Get("bigquery_data_transfer_custom_endpoint").(string) config.BigtableBasePath = d.Get("bigtable_custom_endpoint").(string) + config.BillingBasePath = d.Get("billing_custom_endpoint").(string) config.BinaryAuthorizationBasePath = d.Get("binary_authorization_custom_endpoint").(string) config.CloudAssetBasePath = d.Get("cloud_asset_custom_endpoint").(string) config.CloudBuildBasePath = d.Get("cloud_build_custom_endpoint").(string) diff --git a/google/resource_active_directory_domain_generated_test.go b/google/resource_active_directory_domain_generated_test.go index b37dd281d18..c6dabb68f15 100644 --- a/google/resource_active_directory_domain_generated_test.go +++ b/google/resource_active_directory_domain_generated_test.go @@ -78,7 +78,13 @@ func testAccCheckActiveDirectoryDomainDestroyProducer(t *testing.T) func(s *terr return err } - _, err = sendRequest(config, "GET", "", url, config.userAgent, nil) + billingProject := "" + + if config.BillingProject != "" { + billingProject = config.BillingProject + } + + _, err = sendRequest(config, "GET", billingProject, url, config.userAgent, nil) if err == nil { return fmt.Errorf("ActiveDirectoryDomain still exists at %s", url) } diff --git a/google/resource_app_engine_domain_mapping_generated_test.go b/google/resource_app_engine_domain_mapping_generated_test.go index e984f3c7f05..42f907a6656 100644 --- a/google/resource_app_engine_domain_mapping_generated_test.go +++ b/google/resource_app_engine_domain_mapping_generated_test.go @@ -80,7 +80,13 @@ func testAccCheckAppEngineDomainMappingDestroyProducer(t *testing.T) func(s *ter return err } - _, err = sendRequest(config, "GET", "", url, config.userAgent, nil) + billingProject := "" + + if config.BillingProject != "" { + billingProject = config.BillingProject + } + + _, err = sendRequest(config, "GET", billingProject, url, config.userAgent, nil) if err == nil { return fmt.Errorf("AppEngineDomainMapping still exists at %s", url) } diff --git a/google/resource_app_engine_firewall_rule_generated_test.go b/google/resource_app_engine_firewall_rule_generated_test.go index b3ab9173311..c8d25b4626b 100644 --- a/google/resource_app_engine_firewall_rule_generated_test.go +++ b/google/resource_app_engine_firewall_rule_generated_test.go @@ -90,7 +90,13 @@ func testAccCheckAppEngineFirewallRuleDestroyProducer(t *testing.T) func(s *terr return err } - _, err = sendRequest(config, "GET", "", url, config.userAgent, nil) + billingProject := "" + + if config.BillingProject != "" { + billingProject = config.BillingProject + } + + _, err = sendRequest(config, "GET", billingProject, url, config.userAgent, nil) if err == nil { return fmt.Errorf("AppEngineFirewallRule still exists at %s", url) } diff --git a/google/resource_big_query_dataset_generated_test.go b/google/resource_big_query_dataset_generated_test.go index f42b2bee11d..21b53507ff1 100644 --- a/google/resource_big_query_dataset_generated_test.go +++ b/google/resource_big_query_dataset_generated_test.go @@ -97,7 +97,13 @@ func testAccCheckBigQueryDatasetDestroyProducer(t *testing.T) func(s *terraform. return err } - _, err = sendRequest(config, "GET", "", url, config.userAgent, nil) + billingProject := "" + + if config.BillingProject != "" { + billingProject = config.BillingProject + } + + _, err = sendRequest(config, "GET", billingProject, url, config.userAgent, nil) if err == nil { return fmt.Errorf("BigQueryDataset still exists at %s", url) } diff --git a/google/resource_big_query_routine_generated_test.go b/google/resource_big_query_routine_generated_test.go index d221c6f1559..7559795dfe7 100644 --- a/google/resource_big_query_routine_generated_test.go +++ b/google/resource_big_query_routine_generated_test.go @@ -136,7 +136,13 @@ func testAccCheckBigQueryRoutineDestroyProducer(t *testing.T) func(s *terraform. return err } - _, err = sendRequest(config, "GET", "", url, config.userAgent, nil) + billingProject := "" + + if config.BillingProject != "" { + billingProject = config.BillingProject + } + + _, err = sendRequest(config, "GET", billingProject, url, config.userAgent, nil) if err == nil { return fmt.Errorf("BigQueryRoutine still exists at %s", url) } diff --git a/google/resource_bigtable_app_profile_generated_test.go b/google/resource_bigtable_app_profile_generated_test.go index 3a559a59d3c..5120487e703 100644 --- a/google/resource_bigtable_app_profile_generated_test.go +++ b/google/resource_bigtable_app_profile_generated_test.go @@ -150,7 +150,13 @@ func testAccCheckBigtableAppProfileDestroyProducer(t *testing.T) func(s *terrafo return err } - _, err = sendRequest(config, "GET", "", url, config.userAgent, nil) + billingProject := "" + + if config.BillingProject != "" { + billingProject = config.BillingProject + } + + _, err = sendRequest(config, "GET", billingProject, url, config.userAgent, nil) if err == nil { return fmt.Errorf("BigtableAppProfile still exists at %s", url) } diff --git a/google/resource_billing_budget.go b/google/resource_billing_budget.go new file mode 100644 index 00000000000..8f33ddca991 --- /dev/null +++ b/google/resource_billing_budget.go @@ -0,0 +1,954 @@ +// ---------------------------------------------------------------------------- +// +// *** AUTO GENERATED CODE *** AUTO GENERATED CODE *** +// +// ---------------------------------------------------------------------------- +// +// This file is automatically generated by Magic Modules and manual +// changes will be clobbered when the file is regenerated. +// +// Please read more about how to change this file in +// .github/CONTRIBUTING.md. +// +// ---------------------------------------------------------------------------- + +package google + +import ( + "fmt" + "log" + "reflect" + "strconv" + "time" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" +) + +func resourceBillingBudget() *schema.Resource { + return &schema.Resource{ + Create: resourceBillingBudgetCreate, + Read: resourceBillingBudgetRead, + Update: resourceBillingBudgetUpdate, + Delete: resourceBillingBudgetDelete, + + Timeouts: &schema.ResourceTimeout{ + Create: schema.DefaultTimeout(4 * time.Minute), + Update: schema.DefaultTimeout(4 * time.Minute), + Delete: schema.DefaultTimeout(4 * time.Minute), + }, + + Schema: map[string]*schema.Schema{ + "amount": { + Type: schema.TypeList, + Required: true, + Description: `The budgeted amount for each usage period.`, + MaxItems: 1, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "last_period_amount": { + Type: schema.TypeBool, + Optional: true, + Description: `Configures a budget amount that is automatically set to 100% of +last period's spend. +Boolean. Set value to true to use. Do not set to false, instead +use the 'specified_amount' block.`, + ExactlyOneOf: []string{"amount.0.specified_amount", "amount.0.last_period_amount"}, + }, + "specified_amount": { + Type: schema.TypeList, + Optional: true, + Description: `A specified amount to use as the budget. currencyCode is +optional. If specified, it must match the currency of the +billing account. The currencyCode is provided on output.`, + MaxItems: 1, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "currency_code": { + Type: schema.TypeString, + Optional: true, + Description: `The 3-letter currency code defined in ISO 4217.`, + }, + "nanos": { + Type: schema.TypeInt, + Optional: true, + Description: `Number of nano (10^-9) units of the amount. +The value must be between -999,999,999 and +999,999,999 +inclusive. If units is positive, nanos must be positive or +zero. If units is zero, nanos can be positive, zero, or +negative. If units is negative, nanos must be negative or +zero. For example $-1.75 is represented as units=-1 and +nanos=-750,000,000.`, + }, + "units": { + Type: schema.TypeString, + Optional: true, + Description: `The whole units of the amount. For example if currencyCode +is "USD", then 1 unit is one US dollar.`, + }, + }, + }, + ExactlyOneOf: []string{"amount.0.specified_amount", "amount.0.last_period_amount"}, + }, + }, + }, + }, + "billing_account": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + Description: `ID of the billing account to set a budget on.`, + }, + "threshold_rules": { + Type: schema.TypeList, + Required: true, + Description: `Rules that trigger alerts (notifications of thresholds being +crossed) when spend exceeds the specified percentages of the +budget.`, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "threshold_percent": { + Type: schema.TypeFloat, + Required: true, + Description: `Send an alert when this threshold is exceeded. This is a +1.0-based percentage, so 0.5 = 50%. Must be >= 0.`, + }, + "spend_basis": { + Type: schema.TypeString, + Optional: true, + ValidateFunc: validation.StringInSlice([]string{"CURRENT_SPEND", "FORECASTED_SPEND", ""}, false), + Description: `The type of basis used to determine if spend has passed +the threshold. Default value: "CURRENT_SPEND" Possible values: ["CURRENT_SPEND", "FORECASTED_SPEND"]`, + Default: "CURRENT_SPEND", + }, + }, + }, + }, + "all_updates_rule": { + Type: schema.TypeList, + Optional: true, + Description: `Defines notifications that are sent on every update to the +billing account's spend, regardless of the thresholds defined +using threshold rules.`, + MaxItems: 1, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "disable_default_iam_recipients": { + Type: schema.TypeBool, + Optional: true, + Description: `Boolean. When set to true, disables default notifications sent +when a threshold is exceeded. Default recipients are +those with Billing Account Administrators and Billing +Account Users IAM roles for the target account.`, + Default: false, + }, + "monitoring_notification_channels": { + Type: schema.TypeList, + Optional: true, + Description: `The full resource name of a monitoring notification +channel in the form +projects/{project_id}/notificationChannels/{channel_id}. +A maximum of 5 channels are allowed.`, + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + AtLeastOneOf: []string{"all_updates_rule.0.pubsub_topic", "all_updates_rule.0.monitoring_notification_channels"}, + }, + "pubsub_topic": { + Type: schema.TypeString, + Optional: true, + Description: `The name of the Cloud Pub/Sub topic where budget related +messages will be published, in the form +projects/{project_id}/topics/{topic_id}. Updates are sent +at regular intervals to the topic.`, + AtLeastOneOf: []string{"all_updates_rule.0.pubsub_topic", "all_updates_rule.0.monitoring_notification_channels"}, + }, + "schema_version": { + Type: schema.TypeString, + Optional: true, + Description: `The schema version of the notification. Only "1.0" is +accepted. It represents the JSON schema as defined in +https://cloud.google.com/billing/docs/how-to/budgets#notification_format.`, + Default: "1.0", + }, + }, + }, + }, + "budget_filter": { + Type: schema.TypeList, + Computed: true, + Optional: true, + Description: `Filters that define which resources are used to compute the actual +spend against the budget.`, + MaxItems: 1, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "credit_types": { + Type: schema.TypeList, + Computed: true, + Optional: true, + Description: `A set of subaccounts of the form billingAccounts/{account_id}, +specifying that usage from only this set of subaccounts should +be included in the budget. If a subaccount is set to the name of +the parent account, usage from the parent account will be included. +If the field is omitted, the report will include usage from the parent +account and all subaccounts, if they exist.`, + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + AtLeastOneOf: []string{"budget_filter.0.projects", "budget_filter.0.credit_types_treatment", "budget_filter.0.services", "budget_filter.0.subaccounts", "budget_filter.0.labels"}, + }, + "credit_types_treatment": { + Type: schema.TypeString, + Optional: true, + ValidateFunc: validation.StringInSlice([]string{"INCLUDE_ALL_CREDITS", "EXCLUDE_ALL_CREDITS", "INCLUDE_SPECIFIED_CREDITS", ""}, false), + Description: `Specifies how credits should be treated when determining spend +for threshold calculations. Default value: "INCLUDE_ALL_CREDITS" Possible values: ["INCLUDE_ALL_CREDITS", "EXCLUDE_ALL_CREDITS", "INCLUDE_SPECIFIED_CREDITS"]`, + Default: "INCLUDE_ALL_CREDITS", + AtLeastOneOf: []string{"budget_filter.0.projects", "budget_filter.0.credit_types_treatment", "budget_filter.0.services", "budget_filter.0.subaccounts", "budget_filter.0.labels"}, + }, + "labels": { + Type: schema.TypeMap, + Computed: true, + Optional: true, + Description: `A single label and value pair specifying that usage from only +this set of labeled resources should be included in the budget.`, + Elem: &schema.Schema{Type: schema.TypeString}, + AtLeastOneOf: []string{"budget_filter.0.projects", "budget_filter.0.credit_types_treatment", "budget_filter.0.services", "budget_filter.0.subaccounts", "budget_filter.0.labels"}, + }, + "projects": { + Type: schema.TypeList, + Optional: true, + Description: `A set of projects of the form projects/{project_id}, +specifying that usage from only this set of projects should be +included in the budget. If omitted, the report will include +all usage for the billing account, regardless of which project +the usage occurred on. Only zero or one project can be +specified currently.`, + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + AtLeastOneOf: []string{"budget_filter.0.projects", "budget_filter.0.credit_types_treatment", "budget_filter.0.services", "budget_filter.0.subaccounts", "budget_filter.0.labels"}, + }, + "services": { + Type: schema.TypeList, + Computed: true, + Optional: true, + Description: `A set of services of the form services/{service_id}, +specifying that usage from only this set of services should be +included in the budget. If omitted, the report will include +usage for all the services. The service names are available +through the Catalog API: +https://cloud.google.com/billing/v1/how-tos/catalog-api.`, + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + AtLeastOneOf: []string{"budget_filter.0.projects", "budget_filter.0.credit_types_treatment", "budget_filter.0.services", "budget_filter.0.subaccounts", "budget_filter.0.labels"}, + }, + "subaccounts": { + Type: schema.TypeList, + Computed: true, + Optional: true, + Description: `A set of subaccounts of the form billingAccounts/{account_id}, +specifying that usage from only this set of subaccounts should +be included in the budget. If a subaccount is set to the name of +the parent account, usage from the parent account will be included. +If the field is omitted, the report will include usage from the parent +account and all subaccounts, if they exist.`, + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + AtLeastOneOf: []string{"budget_filter.0.projects", "budget_filter.0.credit_types_treatment", "budget_filter.0.services", "budget_filter.0.subaccounts", "budget_filter.0.labels"}, + }, + }, + }, + }, + "display_name": { + Type: schema.TypeString, + Optional: true, + Description: `User data for display name in UI. Must be <= 60 chars.`, + }, + "name": { + Type: schema.TypeString, + Computed: true, + Description: `Resource name of the budget. The resource name +implies the scope of a budget. Values are of the form +billingAccounts/{billingAccountId}/budgets/{budgetId}.`, + }, + }, + } +} + +func resourceBillingBudgetCreate(d *schema.ResourceData, meta interface{}) error { + config := meta.(*Config) + userAgent, err := generateUserAgentString(d, config.userAgent) + if err != nil { + return err + } + + obj := make(map[string]interface{}) + displayNameProp, err := expandBillingBudgetDisplayName(d.Get("display_name"), d, config) + if err != nil { + return err + } else if v, ok := d.GetOkExists("display_name"); !isEmptyValue(reflect.ValueOf(displayNameProp)) && (ok || !reflect.DeepEqual(v, displayNameProp)) { + obj["displayName"] = displayNameProp + } + budgetFilterProp, err := expandBillingBudgetBudgetFilter(d.Get("budget_filter"), d, config) + if err != nil { + return err + } else if v, ok := d.GetOkExists("budget_filter"); !isEmptyValue(reflect.ValueOf(budgetFilterProp)) && (ok || !reflect.DeepEqual(v, budgetFilterProp)) { + obj["budgetFilter"] = budgetFilterProp + } + amountProp, err := expandBillingBudgetAmount(d.Get("amount"), d, config) + if err != nil { + return err + } else if v, ok := d.GetOkExists("amount"); !isEmptyValue(reflect.ValueOf(amountProp)) && (ok || !reflect.DeepEqual(v, amountProp)) { + obj["amount"] = amountProp + } + thresholdRulesProp, err := expandBillingBudgetThresholdRules(d.Get("threshold_rules"), d, config) + if err != nil { + return err + } else if v, ok := d.GetOkExists("threshold_rules"); !isEmptyValue(reflect.ValueOf(thresholdRulesProp)) && (ok || !reflect.DeepEqual(v, thresholdRulesProp)) { + obj["thresholdRules"] = thresholdRulesProp + } + notificationsRuleProp, err := expandBillingBudgetAllUpdatesRule(d.Get("all_updates_rule"), d, config) + if err != nil { + return err + } else if v, ok := d.GetOkExists("all_updates_rule"); !isEmptyValue(reflect.ValueOf(notificationsRuleProp)) && (ok || !reflect.DeepEqual(v, notificationsRuleProp)) { + obj["notificationsRule"] = notificationsRuleProp + } + + url, err := replaceVars(d, config, "{{BillingBasePath}}billingAccounts/{{billing_account}}/budgets") + if err != nil { + return err + } + + log.Printf("[DEBUG] Creating new Budget: %#v", obj) + billingProject := "" + + // err == nil indicates that the billing_project value was found + if bp, err := getBillingProject(d, config); err == nil { + billingProject = bp + } + + res, err := sendRequestWithTimeout(config, "POST", billingProject, url, userAgent, obj, d.Timeout(schema.TimeoutCreate)) + if err != nil { + return fmt.Errorf("Error creating Budget: %s", err) + } + if err := d.Set("name", flattenBillingBudgetName(res["name"], d, config)); err != nil { + return fmt.Errorf(`Error setting computed identity field "name": %s`, err) + } + + // Store the ID now + id, err := replaceVars(d, config, "{{name}}") + if err != nil { + return fmt.Errorf("Error constructing id: %s", err) + } + d.SetId(id) + + log.Printf("[DEBUG] Finished creating Budget %q: %#v", d.Id(), res) + + // `name` is autogenerated from the api so needs to be set post-create + name, ok := res["name"] + if !ok { + respBody, ok := res["response"] + if !ok { + return fmt.Errorf("Create response didn't contain critical fields. Create may not have succeeded.") + } + + name, ok = respBody.(map[string]interface{})["name"] + if !ok { + return fmt.Errorf("Create response didn't contain critical fields. Create may not have succeeded.") + } + } + if err := d.Set("name", name.(string)); err != nil { + return fmt.Errorf("Error setting name: %s", err) + } + d.SetId(name.(string)) + + return resourceBillingBudgetRead(d, meta) +} + +func resourceBillingBudgetRead(d *schema.ResourceData, meta interface{}) error { + config := meta.(*Config) + userAgent, err := generateUserAgentString(d, config.userAgent) + if err != nil { + return err + } + + url, err := replaceVars(d, config, "{{BillingBasePath}}{{name}}") + if err != nil { + return err + } + + billingProject := "" + + // err == nil indicates that the billing_project value was found + if bp, err := getBillingProject(d, config); err == nil { + billingProject = bp + } + + res, err := sendRequest(config, "GET", billingProject, url, userAgent, nil) + if err != nil { + return handleNotFoundError(err, d, fmt.Sprintf("BillingBudget %q", d.Id())) + } + + if err := d.Set("name", flattenBillingBudgetName(res["name"], d, config)); err != nil { + return fmt.Errorf("Error reading Budget: %s", err) + } + if err := d.Set("display_name", flattenBillingBudgetDisplayName(res["displayName"], d, config)); err != nil { + return fmt.Errorf("Error reading Budget: %s", err) + } + if err := d.Set("budget_filter", flattenBillingBudgetBudgetFilter(res["budgetFilter"], d, config)); err != nil { + return fmt.Errorf("Error reading Budget: %s", err) + } + if err := d.Set("amount", flattenBillingBudgetAmount(res["amount"], d, config)); err != nil { + return fmt.Errorf("Error reading Budget: %s", err) + } + if err := d.Set("threshold_rules", flattenBillingBudgetThresholdRules(res["thresholdRules"], d, config)); err != nil { + return fmt.Errorf("Error reading Budget: %s", err) + } + if err := d.Set("all_updates_rule", flattenBillingBudgetAllUpdatesRule(res["notificationsRule"], d, config)); err != nil { + return fmt.Errorf("Error reading Budget: %s", err) + } + + return nil +} + +func resourceBillingBudgetUpdate(d *schema.ResourceData, meta interface{}) error { + config := meta.(*Config) + userAgent, err := generateUserAgentString(d, config.userAgent) + if err != nil { + return err + } + + billingProject := "" + + obj := make(map[string]interface{}) + displayNameProp, err := expandBillingBudgetDisplayName(d.Get("display_name"), d, config) + if err != nil { + return err + } else if v, ok := d.GetOkExists("display_name"); !isEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, displayNameProp)) { + obj["displayName"] = displayNameProp + } + budgetFilterProp, err := expandBillingBudgetBudgetFilter(d.Get("budget_filter"), d, config) + if err != nil { + return err + } else if v, ok := d.GetOkExists("budget_filter"); !isEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, budgetFilterProp)) { + obj["budgetFilter"] = budgetFilterProp + } + amountProp, err := expandBillingBudgetAmount(d.Get("amount"), d, config) + if err != nil { + return err + } else if v, ok := d.GetOkExists("amount"); !isEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, amountProp)) { + obj["amount"] = amountProp + } + thresholdRulesProp, err := expandBillingBudgetThresholdRules(d.Get("threshold_rules"), d, config) + if err != nil { + return err + } else if v, ok := d.GetOkExists("threshold_rules"); !isEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, thresholdRulesProp)) { + obj["thresholdRules"] = thresholdRulesProp + } + notificationsRuleProp, err := expandBillingBudgetAllUpdatesRule(d.Get("all_updates_rule"), d, config) + if err != nil { + return err + } else if v, ok := d.GetOkExists("all_updates_rule"); !isEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, notificationsRuleProp)) { + obj["notificationsRule"] = notificationsRuleProp + } + + url, err := replaceVars(d, config, "{{BillingBasePath}}{{name}}") + if err != nil { + return err + } + + log.Printf("[DEBUG] Updating Budget %q: %#v", d.Id(), obj) + + // err == nil indicates that the billing_project value was found + if bp, err := getBillingProject(d, config); err == nil { + billingProject = bp + } + + res, err := sendRequestWithTimeout(config, "PATCH", billingProject, url, userAgent, obj, d.Timeout(schema.TimeoutUpdate)) + + if err != nil { + return fmt.Errorf("Error updating Budget %q: %s", d.Id(), err) + } else { + log.Printf("[DEBUG] Finished updating Budget %q: %#v", d.Id(), res) + } + + return resourceBillingBudgetRead(d, meta) +} + +func resourceBillingBudgetDelete(d *schema.ResourceData, meta interface{}) error { + config := meta.(*Config) + userAgent, err := generateUserAgentString(d, config.userAgent) + if err != nil { + return err + } + + billingProject := "" + + url, err := replaceVars(d, config, "{{BillingBasePath}}{{name}}") + if err != nil { + return err + } + + var obj map[string]interface{} + log.Printf("[DEBUG] Deleting Budget %q", d.Id()) + + // err == nil indicates that the billing_project value was found + if bp, err := getBillingProject(d, config); err == nil { + billingProject = bp + } + + res, err := sendRequestWithTimeout(config, "DELETE", billingProject, url, userAgent, obj, d.Timeout(schema.TimeoutDelete)) + if err != nil { + return handleNotFoundError(err, d, "Budget") + } + + log.Printf("[DEBUG] Finished deleting Budget %q: %#v", d.Id(), res) + return nil +} + +func flattenBillingBudgetName(v interface{}, d *schema.ResourceData, config *Config) interface{} { + return v +} + +func flattenBillingBudgetDisplayName(v interface{}, d *schema.ResourceData, config *Config) interface{} { + return v +} + +func flattenBillingBudgetBudgetFilter(v interface{}, d *schema.ResourceData, config *Config) interface{} { + if v == nil { + return nil + } + original := v.(map[string]interface{}) + if len(original) == 0 { + return nil + } + transformed := make(map[string]interface{}) + transformed["projects"] = + flattenBillingBudgetBudgetFilterProjects(original["projects"], d, config) + transformed["credit_types_treatment"] = + flattenBillingBudgetBudgetFilterCreditTypesTreatment(original["creditTypesTreatment"], d, config) + transformed["services"] = + flattenBillingBudgetBudgetFilterServices(original["services"], d, config) + transformed["credit_types"] = + flattenBillingBudgetBudgetFilterCreditTypes(original["creditTypes"], d, config) + transformed["subaccounts"] = + flattenBillingBudgetBudgetFilterSubaccounts(original["subaccounts"], d, config) + transformed["labels"] = + flattenBillingBudgetBudgetFilterLabels(original["labels"], d, config) + return []interface{}{transformed} +} +func flattenBillingBudgetBudgetFilterProjects(v interface{}, d *schema.ResourceData, config *Config) interface{} { + return v +} + +func flattenBillingBudgetBudgetFilterCreditTypesTreatment(v interface{}, d *schema.ResourceData, config *Config) interface{} { + return v +} + +func flattenBillingBudgetBudgetFilterServices(v interface{}, d *schema.ResourceData, config *Config) interface{} { + return v +} + +func flattenBillingBudgetBudgetFilterCreditTypes(v interface{}, d *schema.ResourceData, config *Config) interface{} { + return v +} + +func flattenBillingBudgetBudgetFilterSubaccounts(v interface{}, d *schema.ResourceData, config *Config) interface{} { + return v +} + +func flattenBillingBudgetBudgetFilterLabels(v interface{}, d *schema.ResourceData, config *Config) interface{} { + return v +} + +func flattenBillingBudgetAmount(v interface{}, d *schema.ResourceData, config *Config) interface{} { + if v == nil { + return nil + } + original := v.(map[string]interface{}) + if len(original) == 0 { + return nil + } + transformed := make(map[string]interface{}) + transformed["specified_amount"] = + flattenBillingBudgetAmountSpecifiedAmount(original["specifiedAmount"], d, config) + transformed["last_period_amount"] = + flattenBillingBudgetAmountLastPeriodAmount(original["lastPeriodAmount"], d, config) + return []interface{}{transformed} +} +func flattenBillingBudgetAmountSpecifiedAmount(v interface{}, d *schema.ResourceData, config *Config) interface{} { + if v == nil { + return nil + } + original := v.(map[string]interface{}) + if len(original) == 0 { + return nil + } + transformed := make(map[string]interface{}) + transformed["currency_code"] = + flattenBillingBudgetAmountSpecifiedAmountCurrencyCode(original["currencyCode"], d, config) + transformed["units"] = + flattenBillingBudgetAmountSpecifiedAmountUnits(original["units"], d, config) + transformed["nanos"] = + flattenBillingBudgetAmountSpecifiedAmountNanos(original["nanos"], d, config) + return []interface{}{transformed} +} +func flattenBillingBudgetAmountSpecifiedAmountCurrencyCode(v interface{}, d *schema.ResourceData, config *Config) interface{} { + return v +} + +func flattenBillingBudgetAmountSpecifiedAmountUnits(v interface{}, d *schema.ResourceData, config *Config) interface{} { + return v +} + +func flattenBillingBudgetAmountSpecifiedAmountNanos(v interface{}, d *schema.ResourceData, config *Config) interface{} { + // Handles the string fixed64 format + if strVal, ok := v.(string); ok { + if intVal, err := strconv.ParseInt(strVal, 10, 64); err == nil { + return intVal + } + } + + // number values are represented as float64 + if floatVal, ok := v.(float64); ok { + intVal := int(floatVal) + return intVal + } + + return v // let terraform core handle it otherwise +} + +func flattenBillingBudgetAmountLastPeriodAmount(v interface{}, d *schema.ResourceData, config *Config) interface{} { + return v != nil +} + +func flattenBillingBudgetThresholdRules(v interface{}, d *schema.ResourceData, config *Config) interface{} { + if v == nil { + return v + } + l := v.([]interface{}) + transformed := make([]interface{}, 0, len(l)) + for _, raw := range l { + original := raw.(map[string]interface{}) + if len(original) < 1 { + // Do not include empty json objects coming back from the api + continue + } + transformed = append(transformed, map[string]interface{}{ + "threshold_percent": flattenBillingBudgetThresholdRulesThresholdPercent(original["thresholdPercent"], d, config), + "spend_basis": flattenBillingBudgetThresholdRulesSpendBasis(original["spendBasis"], d, config), + }) + } + return transformed +} +func flattenBillingBudgetThresholdRulesThresholdPercent(v interface{}, d *schema.ResourceData, config *Config) interface{} { + return v +} + +func flattenBillingBudgetThresholdRulesSpendBasis(v interface{}, d *schema.ResourceData, config *Config) interface{} { + return v +} + +func flattenBillingBudgetAllUpdatesRule(v interface{}, d *schema.ResourceData, config *Config) interface{} { + if v == nil { + return nil + } + original := v.(map[string]interface{}) + if len(original) == 0 { + return nil + } + transformed := make(map[string]interface{}) + transformed["pubsub_topic"] = + flattenBillingBudgetAllUpdatesRulePubsubTopic(original["pubsubTopic"], d, config) + transformed["schema_version"] = + flattenBillingBudgetAllUpdatesRuleSchemaVersion(original["schemaVersion"], d, config) + transformed["monitoring_notification_channels"] = + flattenBillingBudgetAllUpdatesRuleMonitoringNotificationChannels(original["monitoringNotificationChannels"], d, config) + transformed["disable_default_iam_recipients"] = + flattenBillingBudgetAllUpdatesRuleDisableDefaultIamRecipients(original["disableDefaultIamRecipients"], d, config) + return []interface{}{transformed} +} +func flattenBillingBudgetAllUpdatesRulePubsubTopic(v interface{}, d *schema.ResourceData, config *Config) interface{} { + return v +} + +func flattenBillingBudgetAllUpdatesRuleSchemaVersion(v interface{}, d *schema.ResourceData, config *Config) interface{} { + if v == nil || isEmptyValue(reflect.ValueOf(v)) { + return "1.0" + } + + return v +} + +func flattenBillingBudgetAllUpdatesRuleMonitoringNotificationChannels(v interface{}, d *schema.ResourceData, config *Config) interface{} { + return v +} + +func flattenBillingBudgetAllUpdatesRuleDisableDefaultIamRecipients(v interface{}, d *schema.ResourceData, config *Config) interface{} { + return v +} + +func expandBillingBudgetDisplayName(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { + return v, nil +} + +func expandBillingBudgetBudgetFilter(v interface{}, d TerraformResourceData, config *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{}) + + transformedProjects, err := expandBillingBudgetBudgetFilterProjects(original["projects"], d, config) + if err != nil { + return nil, err + } else if val := reflect.ValueOf(transformedProjects); val.IsValid() && !isEmptyValue(val) { + transformed["projects"] = transformedProjects + } + + transformedCreditTypesTreatment, err := expandBillingBudgetBudgetFilterCreditTypesTreatment(original["credit_types_treatment"], d, config) + if err != nil { + return nil, err + } else if val := reflect.ValueOf(transformedCreditTypesTreatment); val.IsValid() && !isEmptyValue(val) { + transformed["creditTypesTreatment"] = transformedCreditTypesTreatment + } + + transformedServices, err := expandBillingBudgetBudgetFilterServices(original["services"], d, config) + if err != nil { + return nil, err + } else if val := reflect.ValueOf(transformedServices); val.IsValid() && !isEmptyValue(val) { + transformed["services"] = transformedServices + } + + transformedCreditTypes, err := expandBillingBudgetBudgetFilterCreditTypes(original["credit_types"], d, config) + if err != nil { + return nil, err + } else if val := reflect.ValueOf(transformedCreditTypes); val.IsValid() && !isEmptyValue(val) { + transformed["creditTypes"] = transformedCreditTypes + } + + transformedSubaccounts, err := expandBillingBudgetBudgetFilterSubaccounts(original["subaccounts"], d, config) + if err != nil { + return nil, err + } else if val := reflect.ValueOf(transformedSubaccounts); val.IsValid() && !isEmptyValue(val) { + transformed["subaccounts"] = transformedSubaccounts + } + + transformedLabels, err := expandBillingBudgetBudgetFilterLabels(original["labels"], d, config) + if err != nil { + return nil, err + } else if val := reflect.ValueOf(transformedLabels); val.IsValid() && !isEmptyValue(val) { + transformed["labels"] = transformedLabels + } + + return transformed, nil +} + +func expandBillingBudgetBudgetFilterProjects(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { + return v, nil +} + +func expandBillingBudgetBudgetFilterCreditTypesTreatment(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { + return v, nil +} + +func expandBillingBudgetBudgetFilterServices(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { + return v, nil +} + +func expandBillingBudgetBudgetFilterCreditTypes(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { + return v, nil +} + +func expandBillingBudgetBudgetFilterSubaccounts(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { + return v, nil +} + +func expandBillingBudgetBudgetFilterLabels(v interface{}, d TerraformResourceData, config *Config) (map[string]string, error) { + if v == nil { + return map[string]string{}, nil + } + m := make(map[string]string) + for k, val := range v.(map[string]interface{}) { + m[k] = val.(string) + } + return m, nil +} + +func expandBillingBudgetAmount(v interface{}, d TerraformResourceData, config *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{}) + + transformedSpecifiedAmount, err := expandBillingBudgetAmountSpecifiedAmount(original["specified_amount"], d, config) + if err != nil { + return nil, err + } else if val := reflect.ValueOf(transformedSpecifiedAmount); val.IsValid() && !isEmptyValue(val) { + transformed["specifiedAmount"] = transformedSpecifiedAmount + } + + transformedLastPeriodAmount, err := expandBillingBudgetAmountLastPeriodAmount(original["last_period_amount"], d, config) + if err != nil { + return nil, err + } else if val := reflect.ValueOf(transformedLastPeriodAmount); val.IsValid() && !isEmptyValue(val) { + transformed["lastPeriodAmount"] = transformedLastPeriodAmount + } + + return transformed, nil +} + +func expandBillingBudgetAmountSpecifiedAmount(v interface{}, d TerraformResourceData, config *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{}) + + transformedCurrencyCode, err := expandBillingBudgetAmountSpecifiedAmountCurrencyCode(original["currency_code"], d, config) + if err != nil { + return nil, err + } else if val := reflect.ValueOf(transformedCurrencyCode); val.IsValid() && !isEmptyValue(val) { + transformed["currencyCode"] = transformedCurrencyCode + } + + transformedUnits, err := expandBillingBudgetAmountSpecifiedAmountUnits(original["units"], d, config) + if err != nil { + return nil, err + } else if val := reflect.ValueOf(transformedUnits); val.IsValid() && !isEmptyValue(val) { + transformed["units"] = transformedUnits + } + + transformedNanos, err := expandBillingBudgetAmountSpecifiedAmountNanos(original["nanos"], d, config) + if err != nil { + return nil, err + } else if val := reflect.ValueOf(transformedNanos); val.IsValid() && !isEmptyValue(val) { + transformed["nanos"] = transformedNanos + } + + return transformed, nil +} + +func expandBillingBudgetAmountSpecifiedAmountCurrencyCode(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { + return v, nil +} + +func expandBillingBudgetAmountSpecifiedAmountUnits(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { + return v, nil +} + +func expandBillingBudgetAmountSpecifiedAmountNanos(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { + return v, nil +} + +func expandBillingBudgetAmountLastPeriodAmount(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { + if v == nil || !v.(bool) { + return nil, nil + } + + return struct{}{}, nil +} + +func expandBillingBudgetThresholdRules(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { + l := v.([]interface{}) + req := make([]interface{}, 0, len(l)) + for _, raw := range l { + if raw == nil { + continue + } + original := raw.(map[string]interface{}) + transformed := make(map[string]interface{}) + + transformedThresholdPercent, err := expandBillingBudgetThresholdRulesThresholdPercent(original["threshold_percent"], d, config) + if err != nil { + return nil, err + } else { + transformed["thresholdPercent"] = transformedThresholdPercent + } + + transformedSpendBasis, err := expandBillingBudgetThresholdRulesSpendBasis(original["spend_basis"], d, config) + if err != nil { + return nil, err + } else if val := reflect.ValueOf(transformedSpendBasis); val.IsValid() && !isEmptyValue(val) { + transformed["spendBasis"] = transformedSpendBasis + } + + req = append(req, transformed) + } + return req, nil +} + +func expandBillingBudgetThresholdRulesThresholdPercent(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { + return v, nil +} + +func expandBillingBudgetThresholdRulesSpendBasis(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { + return v, nil +} + +func expandBillingBudgetAllUpdatesRule(v interface{}, d TerraformResourceData, config *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{}) + + transformedPubsubTopic, err := expandBillingBudgetAllUpdatesRulePubsubTopic(original["pubsub_topic"], d, config) + if err != nil { + return nil, err + } else if val := reflect.ValueOf(transformedPubsubTopic); val.IsValid() && !isEmptyValue(val) { + transformed["pubsubTopic"] = transformedPubsubTopic + } + + transformedSchemaVersion, err := expandBillingBudgetAllUpdatesRuleSchemaVersion(original["schema_version"], d, config) + if err != nil { + return nil, err + } else if val := reflect.ValueOf(transformedSchemaVersion); val.IsValid() && !isEmptyValue(val) { + transformed["schemaVersion"] = transformedSchemaVersion + } + + transformedMonitoringNotificationChannels, err := expandBillingBudgetAllUpdatesRuleMonitoringNotificationChannels(original["monitoring_notification_channels"], d, config) + if err != nil { + return nil, err + } else if val := reflect.ValueOf(transformedMonitoringNotificationChannels); val.IsValid() && !isEmptyValue(val) { + transformed["monitoringNotificationChannels"] = transformedMonitoringNotificationChannels + } + + transformedDisableDefaultIamRecipients, err := expandBillingBudgetAllUpdatesRuleDisableDefaultIamRecipients(original["disable_default_iam_recipients"], d, config) + if err != nil { + return nil, err + } else if val := reflect.ValueOf(transformedDisableDefaultIamRecipients); val.IsValid() && !isEmptyValue(val) { + transformed["disableDefaultIamRecipients"] = transformedDisableDefaultIamRecipients + } + + return transformed, nil +} + +func expandBillingBudgetAllUpdatesRulePubsubTopic(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { + return v, nil +} + +func expandBillingBudgetAllUpdatesRuleSchemaVersion(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { + return v, nil +} + +func expandBillingBudgetAllUpdatesRuleMonitoringNotificationChannels(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { + return v, nil +} + +func expandBillingBudgetAllUpdatesRuleDisableDefaultIamRecipients(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { + return v, nil +} diff --git a/google/resource_billing_budget_generated_test.go b/google/resource_billing_budget_generated_test.go new file mode 100644 index 00000000000..90685ef6d4f --- /dev/null +++ b/google/resource_billing_budget_generated_test.go @@ -0,0 +1,290 @@ +// ---------------------------------------------------------------------------- +// +// *** AUTO GENERATED CODE *** AUTO GENERATED CODE *** +// +// ---------------------------------------------------------------------------- +// +// This file is automatically generated by Magic Modules and manual +// changes will be clobbered when the file is regenerated. +// +// Please read more about how to change this file in +// .github/CONTRIBUTING.md. +// +// ---------------------------------------------------------------------------- + +package google + +import ( + "fmt" + "strings" + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" +) + +func TestAccBillingBudget_billingBudgetBasicExample(t *testing.T) { + t.Parallel() + + context := map[string]interface{}{ + "billing_acct": getTestBillingAccountFromEnv(t), + "random_suffix": randString(t, 10), + } + + vcrTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + ExternalProviders: map[string]resource.ExternalProvider{ + "random": {}, + }, + CheckDestroy: testAccCheckBillingBudgetDestroyProducer(t), + Steps: []resource.TestStep{ + { + Config: testAccBillingBudget_billingBudgetBasicExample(context), + }, + }, + }) +} + +func testAccBillingBudget_billingBudgetBasicExample(context map[string]interface{}) string { + return Nprintf(` +data "google_billing_account" "account" { + billing_account = "%{billing_acct}" +} + +resource "google_billing_budget" "budget" { + billing_account = data.google_billing_account.account.id + display_name = "Example Billing Budget%{random_suffix}" + amount { + specified_amount { + currency_code = "USD" + units = "100000" + } + } + threshold_rules { + threshold_percent = 0.5 + } +} +`, context) +} + +func TestAccBillingBudget_billingBudgetLastperiodExample(t *testing.T) { + t.Parallel() + + context := map[string]interface{}{ + "billing_acct": getTestBillingAccountFromEnv(t), + "random_suffix": randString(t, 10), + } + + vcrTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + ExternalProviders: map[string]resource.ExternalProvider{ + "random": {}, + }, + CheckDestroy: testAccCheckBillingBudgetDestroyProducer(t), + Steps: []resource.TestStep{ + { + Config: testAccBillingBudget_billingBudgetLastperiodExample(context), + }, + }, + }) +} + +func testAccBillingBudget_billingBudgetLastperiodExample(context map[string]interface{}) string { + return Nprintf(` +data "google_billing_account" "account" { + billing_account = "%{billing_acct}" +} + +data "google_project" "project" { +} + +resource "google_billing_budget" "budget" { + billing_account = data.google_billing_account.account.id + display_name = "Example Billing Budget%{random_suffix}" + + budget_filter { + projects = ["projects/${data.google_project.project.number}"] + } + + amount { + last_period_amount = true + } + + threshold_rules { + threshold_percent = 10.0 + # Typically threshold_percent would be set closer to 1.0 (100%). + # It has been purposely set high (10.0 / 1000%) in this example + # so it does not trigger alerts during automated testing. + } +} +`, context) +} + +func TestAccBillingBudget_billingBudgetFilterExample(t *testing.T) { + t.Parallel() + + context := map[string]interface{}{ + "billing_acct": getTestBillingAccountFromEnv(t), + "random_suffix": randString(t, 10), + } + + vcrTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + ExternalProviders: map[string]resource.ExternalProvider{ + "random": {}, + }, + CheckDestroy: testAccCheckBillingBudgetDestroyProducer(t), + Steps: []resource.TestStep{ + { + Config: testAccBillingBudget_billingBudgetFilterExample(context), + }, + }, + }) +} + +func testAccBillingBudget_billingBudgetFilterExample(context map[string]interface{}) string { + return Nprintf(` +data "google_billing_account" "account" { + billing_account = "%{billing_acct}" +} + +data "google_project" "project" { +} + +resource "google_billing_budget" "budget" { + billing_account = data.google_billing_account.account.id + display_name = "Example Billing Budget%{random_suffix}" + + budget_filter { + projects = ["projects/${data.google_project.project.number}"] + credit_types_treatment = "EXCLUDE_ALL_CREDITS" + services = ["services/24E6-581D-38E5"] # Bigquery + } + + amount { + specified_amount { + currency_code = "USD" + units = "100000" + } + } + + threshold_rules { + threshold_percent = 0.5 + } + threshold_rules { + threshold_percent = 0.9 + spend_basis = "FORECASTED_SPEND" + } +} +`, context) +} + +func TestAccBillingBudget_billingBudgetNotifyExample(t *testing.T) { + t.Parallel() + + context := map[string]interface{}{ + "billing_acct": getTestBillingAccountFromEnv(t), + "random_suffix": randString(t, 10), + } + + vcrTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + ExternalProviders: map[string]resource.ExternalProvider{ + "random": {}, + }, + CheckDestroy: testAccCheckBillingBudgetDestroyProducer(t), + Steps: []resource.TestStep{ + { + Config: testAccBillingBudget_billingBudgetNotifyExample(context), + }, + }, + }) +} + +func testAccBillingBudget_billingBudgetNotifyExample(context map[string]interface{}) string { + return Nprintf(` +data "google_billing_account" "account" { + billing_account = "%{billing_acct}" +} + +data "google_project" "project" { +} + +resource "google_billing_budget" "budget" { + billing_account = data.google_billing_account.account.id + display_name = "Example Billing Budget%{random_suffix}" + + budget_filter { + projects = ["projects/${data.google_project.project.number}"] + } + + amount { + specified_amount { + currency_code = "USD" + units = "100000" + } + } + + threshold_rules { + threshold_percent = 1.0 + } + threshold_rules { + threshold_percent = 1.0 + spend_basis = "FORECASTED_SPEND" + } + + all_updates_rule { + monitoring_notification_channels = [ + google_monitoring_notification_channel.notification_channel.id, + ] + disable_default_iam_recipients = true + } +} + +resource "google_monitoring_notification_channel" "notification_channel" { + display_name = "Example Notification Channel%{random_suffix}" + type = "email" + + labels = { + email_address = "address@example.com" + } +} +`, context) +} + +func testAccCheckBillingBudgetDestroyProducer(t *testing.T) func(s *terraform.State) error { + return func(s *terraform.State) error { + for name, rs := range s.RootModule().Resources { + if rs.Type != "google_billing_budget" { + continue + } + if strings.HasPrefix(name, "data.") { + continue + } + + config := googleProviderConfig(t) + + url, err := replaceVarsForTest(config, rs, "{{BillingBasePath}}{{name}}") + if err != nil { + return err + } + + billingProject := "" + + if config.BillingProject != "" { + billingProject = config.BillingProject + } + + _, err = sendRequest(config, "GET", billingProject, url, config.userAgent, nil) + if err == nil { + return fmt.Errorf("BillingBudget still exists at %s", url) + } + } + + return nil + } +} diff --git a/google/resource_billing_budget_sweeper_test.go b/google/resource_billing_budget_sweeper_test.go new file mode 100644 index 00000000000..5bdb73d663e --- /dev/null +++ b/google/resource_billing_budget_sweeper_test.go @@ -0,0 +1,124 @@ +// ---------------------------------------------------------------------------- +// +// *** AUTO GENERATED CODE *** AUTO GENERATED CODE *** +// +// ---------------------------------------------------------------------------- +// +// This file is automatically generated by Magic Modules and manual +// changes will be clobbered when the file is regenerated. +// +// Please read more about how to change this file in +// .github/CONTRIBUTING.md. +// +// ---------------------------------------------------------------------------- + +package google + +import ( + "context" + "log" + "strings" + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" +) + +func init() { + resource.AddTestSweepers("BillingBudget", &resource.Sweeper{ + Name: "BillingBudget", + F: testSweepBillingBudget, + }) +} + +// At the time of writing, the CI only passes us-central1 as the region +func testSweepBillingBudget(region string) error { + resourceName := "BillingBudget" + log.Printf("[INFO][SWEEPER_LOG] Starting sweeper for %s", resourceName) + + config, err := sharedConfigForRegion(region) + if err != nil { + log.Printf("[INFO][SWEEPER_LOG] error getting shared config for region: %s", err) + return err + } + + err = config.LoadAndValidate(context.Background()) + if err != nil { + log.Printf("[INFO][SWEEPER_LOG] error loading: %s", err) + return err + } + + t := &testing.T{} + billingId := getTestBillingAccountFromEnv(t) + + // Setup variables to replace in list template + d := &ResourceDataMock{ + FieldsInSchema: map[string]interface{}{ + "project": config.Project, + "region": region, + "location": region, + "zone": "-", + "billing_account": billingId, + }, + } + + listTemplate := strings.Split("https://billingbudgets.googleapis.com/v1/billingAccounts/{{billing_account}}/budgets", "?")[0] + listUrl, err := replaceVars(d, config, listTemplate) + if err != nil { + log.Printf("[INFO][SWEEPER_LOG] error preparing sweeper list url: %s", err) + return nil + } + + res, err := sendRequest(config, "GET", config.Project, listUrl, config.userAgent, nil) + if err != nil { + log.Printf("[INFO][SWEEPER_LOG] Error in response from request %s: %s", listUrl, err) + return nil + } + + resourceList, ok := res["budgets"] + if !ok { + log.Printf("[INFO][SWEEPER_LOG] Nothing found in response.") + return nil + } + + rl := resourceList.([]interface{}) + + log.Printf("[INFO][SWEEPER_LOG] Found %d items in %s list response.", len(rl), resourceName) + // Keep count of items that aren't sweepable for logging. + nonPrefixCount := 0 + for _, ri := range rl { + obj := ri.(map[string]interface{}) + if obj["name"] == nil { + log.Printf("[INFO][SWEEPER_LOG] %s resource name was nil", resourceName) + return nil + } + + name := GetResourceNameFromSelfLink(obj["name"].(string)) + // Skip resources that shouldn't be sweeped + if !isSweepableTestResource(name) { + nonPrefixCount++ + continue + } + + deleteTemplate := "https://billingbudgets.googleapis.com/v1/{{name}}" + deleteUrl, err := replaceVars(d, config, deleteTemplate) + if err != nil { + log.Printf("[INFO][SWEEPER_LOG] error preparing delete url: %s", err) + return nil + } + deleteUrl = deleteUrl + name + + // Don't wait on operations as we may have a lot to delete + _, err = sendRequest(config, "DELETE", config.Project, deleteUrl, config.userAgent, nil) + if err != nil { + log.Printf("[INFO][SWEEPER_LOG] Error deleting for url %s : %s", deleteUrl, err) + } else { + log.Printf("[INFO][SWEEPER_LOG] Sent delete request for %s resource: %s", resourceName, name) + } + } + + if nonPrefixCount > 0 { + log.Printf("[INFO][SWEEPER_LOG] %d items were non-sweepable and skipped.", nonPrefixCount) + } + + return nil +} diff --git a/google/resource_binary_authorization_attestor_generated_test.go b/google/resource_binary_authorization_attestor_generated_test.go index 2d7654ca329..d7ac839283a 100644 --- a/google/resource_binary_authorization_attestor_generated_test.go +++ b/google/resource_binary_authorization_attestor_generated_test.go @@ -107,7 +107,13 @@ func testAccCheckBinaryAuthorizationAttestorDestroyProducer(t *testing.T) func(s return err } - _, err = sendRequest(config, "GET", "", url, config.userAgent, nil) + billingProject := "" + + if config.BillingProject != "" { + billingProject = config.BillingProject + } + + _, err = sendRequest(config, "GET", billingProject, url, config.userAgent, nil) if err == nil { return fmt.Errorf("BinaryAuthorizationAttestor still exists at %s", url) } diff --git a/google/resource_cloud_asset_folder_feed_generated_test.go b/google/resource_cloud_asset_folder_feed_generated_test.go index 64d49db09b7..87ecdfa0168 100644 --- a/google/resource_cloud_asset_folder_feed_generated_test.go +++ b/google/resource_cloud_asset_folder_feed_generated_test.go @@ -135,7 +135,13 @@ func testAccCheckCloudAssetFolderFeedDestroyProducer(t *testing.T) func(s *terra return err } - _, err = sendRequest(config, "GET", "", url, config.userAgent, nil) + billingProject := "" + + if config.BillingProject != "" { + billingProject = config.BillingProject + } + + _, err = sendRequest(config, "GET", billingProject, url, config.userAgent, nil) if err == nil { return fmt.Errorf("CloudAssetFolderFeed still exists at %s", url) } diff --git a/google/resource_cloud_asset_organization_feed_generated_test.go b/google/resource_cloud_asset_organization_feed_generated_test.go index 7d82a2e517b..edd887c323d 100644 --- a/google/resource_cloud_asset_organization_feed_generated_test.go +++ b/google/resource_cloud_asset_organization_feed_generated_test.go @@ -129,7 +129,13 @@ func testAccCheckCloudAssetOrganizationFeedDestroyProducer(t *testing.T) func(s return err } - _, err = sendRequest(config, "GET", "", url, config.userAgent, nil) + billingProject := "" + + if config.BillingProject != "" { + billingProject = config.BillingProject + } + + _, err = sendRequest(config, "GET", billingProject, url, config.userAgent, nil) if err == nil { return fmt.Errorf("CloudAssetOrganizationFeed still exists at %s", url) } diff --git a/google/resource_cloud_asset_project_feed_generated_test.go b/google/resource_cloud_asset_project_feed_generated_test.go index 9c42f4d1ab9..a129855e226 100644 --- a/google/resource_cloud_asset_project_feed_generated_test.go +++ b/google/resource_cloud_asset_project_feed_generated_test.go @@ -126,7 +126,13 @@ func testAccCheckCloudAssetProjectFeedDestroyProducer(t *testing.T) func(s *terr return err } - _, err = sendRequest(config, "GET", "", url, config.userAgent, nil) + billingProject := "" + + if config.BillingProject != "" { + billingProject = config.BillingProject + } + + _, err = sendRequest(config, "GET", billingProject, url, config.userAgent, nil) if err == nil { return fmt.Errorf("CloudAssetProjectFeed still exists at %s", url) } diff --git a/google/resource_cloud_build_trigger_generated_test.go b/google/resource_cloud_build_trigger_generated_test.go index 241091cd285..9d231598f5c 100644 --- a/google/resource_cloud_build_trigger_generated_test.go +++ b/google/resource_cloud_build_trigger_generated_test.go @@ -175,7 +175,13 @@ func testAccCheckCloudBuildTriggerDestroyProducer(t *testing.T) func(s *terrafor return err } - _, err = sendRequest(config, "GET", "", url, config.userAgent, nil) + billingProject := "" + + if config.BillingProject != "" { + billingProject = config.BillingProject + } + + _, err = sendRequest(config, "GET", billingProject, url, config.userAgent, nil) if err == nil { return fmt.Errorf("CloudBuildTrigger still exists at %s", url) } diff --git a/google/resource_cloud_identity_group_generated_test.go b/google/resource_cloud_identity_group_generated_test.go index d51add50f47..8bdf3eef935 100644 --- a/google/resource_cloud_identity_group_generated_test.go +++ b/google/resource_cloud_identity_group_generated_test.go @@ -87,7 +87,13 @@ func testAccCheckCloudIdentityGroupDestroyProducer(t *testing.T) func(s *terrafo return err } - _, err = sendRequest(config, "GET", "", url, config.userAgent, nil) + billingProject := "" + + if config.BillingProject != "" { + billingProject = config.BillingProject + } + + _, err = sendRequest(config, "GET", billingProject, url, config.userAgent, nil) if err == nil { return fmt.Errorf("CloudIdentityGroup still exists at %s", url) } diff --git a/google/resource_cloud_identity_group_membership_generated_test.go b/google/resource_cloud_identity_group_membership_generated_test.go index 6ad12088443..1f1ccac0f24 100644 --- a/google/resource_cloud_identity_group_membership_generated_test.go +++ b/google/resource_cloud_identity_group_membership_generated_test.go @@ -179,7 +179,13 @@ func testAccCheckCloudIdentityGroupMembershipDestroyProducer(t *testing.T) func( return err } - _, err = sendRequest(config, "GET", "", url, config.userAgent, nil) + billingProject := "" + + if config.BillingProject != "" { + billingProject = config.BillingProject + } + + _, err = sendRequest(config, "GET", billingProject, url, config.userAgent, nil) if err == nil { return fmt.Errorf("CloudIdentityGroupMembership still exists at %s", url) } diff --git a/google/resource_cloud_iot_device_generated_test.go b/google/resource_cloud_iot_device_generated_test.go index 129d94b1e90..bd049f580b6 100644 --- a/google/resource_cloud_iot_device_generated_test.go +++ b/google/resource_cloud_iot_device_generated_test.go @@ -145,7 +145,13 @@ func testAccCheckCloudIotDeviceDestroyProducer(t *testing.T) func(s *terraform.S return err } - _, err = sendRequest(config, "GET", "", url, config.userAgent, nil) + billingProject := "" + + if config.BillingProject != "" { + billingProject = config.BillingProject + } + + _, err = sendRequest(config, "GET", billingProject, url, config.userAgent, nil) if err == nil { return fmt.Errorf("CloudIotDevice still exists at %s", url) } diff --git a/google/resource_cloud_iot_device_registry_generated_test.go b/google/resource_cloud_iot_device_registry_generated_test.go index e3ac3d3de25..bd98d7c6a75 100644 --- a/google/resource_cloud_iot_device_registry_generated_test.go +++ b/google/resource_cloud_iot_device_registry_generated_test.go @@ -207,7 +207,13 @@ func testAccCheckCloudIotDeviceRegistryDestroyProducer(t *testing.T) func(s *ter return err } - _, err = sendRequest(config, "GET", "", url, config.userAgent, nil) + billingProject := "" + + if config.BillingProject != "" { + billingProject = config.BillingProject + } + + _, err = sendRequest(config, "GET", billingProject, url, config.userAgent, nil) if err == nil { return fmt.Errorf("CloudIotDeviceRegistry still exists at %s", url) } diff --git a/google/resource_cloud_run_domain_mapping_generated_test.go b/google/resource_cloud_run_domain_mapping_generated_test.go index f769e378207..87a94f60ad0 100644 --- a/google/resource_cloud_run_domain_mapping_generated_test.go +++ b/google/resource_cloud_run_domain_mapping_generated_test.go @@ -107,7 +107,13 @@ func testAccCheckCloudRunDomainMappingDestroyProducer(t *testing.T) func(s *terr return err } - _, err = sendRequest(config, "GET", "", url, config.userAgent, nil) + billingProject := "" + + if config.BillingProject != "" { + billingProject = config.BillingProject + } + + _, err = sendRequest(config, "GET", billingProject, url, config.userAgent, nil) if err == nil { return fmt.Errorf("CloudRunDomainMapping still exists at %s", url) } diff --git a/google/resource_cloud_run_service_generated_test.go b/google/resource_cloud_run_service_generated_test.go index c114590c47a..8e93f2fe3a7 100644 --- a/google/resource_cloud_run_service_generated_test.go +++ b/google/resource_cloud_run_service_generated_test.go @@ -286,7 +286,13 @@ func testAccCheckCloudRunServiceDestroyProducer(t *testing.T) func(s *terraform. return err } - _, err = sendRequest(config, "GET", "", url, config.userAgent, nil) + billingProject := "" + + if config.BillingProject != "" { + billingProject = config.BillingProject + } + + _, err = sendRequest(config, "GET", billingProject, url, config.userAgent, nil) if err == nil { return fmt.Errorf("CloudRunService still exists at %s", url) } diff --git a/google/resource_cloud_scheduler_job_generated_test.go b/google/resource_cloud_scheduler_job_generated_test.go index c79ac6fd173..3d97b0ae356 100644 --- a/google/resource_cloud_scheduler_job_generated_test.go +++ b/google/resource_cloud_scheduler_job_generated_test.go @@ -303,7 +303,13 @@ func testAccCheckCloudSchedulerJobDestroyProducer(t *testing.T) func(s *terrafor return err } - _, err = sendRequest(config, "GET", "", url, config.userAgent, nil) + billingProject := "" + + if config.BillingProject != "" { + billingProject = config.BillingProject + } + + _, err = sendRequest(config, "GET", billingProject, url, config.userAgent, nil) if err == nil { return fmt.Errorf("CloudSchedulerJob still exists at %s", url) } diff --git a/google/resource_cloud_tasks_queue_generated_test.go b/google/resource_cloud_tasks_queue_generated_test.go index 251d80c172b..7c78ac7df15 100644 --- a/google/resource_cloud_tasks_queue_generated_test.go +++ b/google/resource_cloud_tasks_queue_generated_test.go @@ -137,7 +137,13 @@ func testAccCheckCloudTasksQueueDestroyProducer(t *testing.T) func(s *terraform. return err } - _, err = sendRequest(config, "GET", "", url, config.userAgent, nil) + billingProject := "" + + if config.BillingProject != "" { + billingProject = config.BillingProject + } + + _, err = sendRequest(config, "GET", billingProject, url, config.userAgent, nil) if err == nil { return fmt.Errorf("CloudTasksQueue still exists at %s", url) } diff --git a/google/resource_compute_address_generated_test.go b/google/resource_compute_address_generated_test.go index 90e30bd350f..26e2b800ce4 100644 --- a/google/resource_compute_address_generated_test.go +++ b/google/resource_compute_address_generated_test.go @@ -263,7 +263,13 @@ func testAccCheckComputeAddressDestroyProducer(t *testing.T) func(s *terraform.S return err } - _, err = sendRequest(config, "GET", "", url, config.userAgent, nil) + billingProject := "" + + if config.BillingProject != "" { + billingProject = config.BillingProject + } + + _, err = sendRequest(config, "GET", billingProject, url, config.userAgent, nil) if err == nil { return fmt.Errorf("ComputeAddress still exists at %s", url) } diff --git a/google/resource_compute_autoscaler_generated_test.go b/google/resource_compute_autoscaler_generated_test.go index 99cef41f815..1124059b339 100644 --- a/google/resource_compute_autoscaler_generated_test.go +++ b/google/resource_compute_autoscaler_generated_test.go @@ -134,7 +134,13 @@ func testAccCheckComputeAutoscalerDestroyProducer(t *testing.T) func(s *terrafor return err } - _, err = sendRequest(config, "GET", "", url, config.userAgent, nil) + billingProject := "" + + if config.BillingProject != "" { + billingProject = config.BillingProject + } + + _, err = sendRequest(config, "GET", billingProject, url, config.userAgent, nil) if err == nil { return fmt.Errorf("ComputeAutoscaler still exists at %s", url) } diff --git a/google/resource_compute_backend_bucket_generated_test.go b/google/resource_compute_backend_bucket_generated_test.go index 0a1753adf0b..04b9d9f93a8 100644 --- a/google/resource_compute_backend_bucket_generated_test.go +++ b/google/resource_compute_backend_bucket_generated_test.go @@ -83,7 +83,13 @@ func testAccCheckComputeBackendBucketDestroyProducer(t *testing.T) func(s *terra return err } - _, err = sendRequest(config, "GET", "", url, config.userAgent, nil) + billingProject := "" + + if config.BillingProject != "" { + billingProject = config.BillingProject + } + + _, err = sendRequest(config, "GET", billingProject, url, config.userAgent, nil) if err == nil { return fmt.Errorf("ComputeBackendBucket still exists at %s", url) } diff --git a/google/resource_compute_backend_service_generated_test.go b/google/resource_compute_backend_service_generated_test.go index f581f2473a5..579531caf22 100644 --- a/google/resource_compute_backend_service_generated_test.go +++ b/google/resource_compute_backend_service_generated_test.go @@ -135,7 +135,13 @@ func testAccCheckComputeBackendServiceDestroyProducer(t *testing.T) func(s *terr return err } - _, err = sendRequest(config, "GET", "", url, config.userAgent, nil) + billingProject := "" + + if config.BillingProject != "" { + billingProject = config.BillingProject + } + + _, err = sendRequest(config, "GET", billingProject, url, config.userAgent, nil) if err == nil { return fmt.Errorf("ComputeBackendService still exists at %s", url) } diff --git a/google/resource_compute_disk_generated_test.go b/google/resource_compute_disk_generated_test.go index 72f53456986..8447fd5514e 100644 --- a/google/resource_compute_disk_generated_test.go +++ b/google/resource_compute_disk_generated_test.go @@ -83,7 +83,13 @@ func testAccCheckComputeDiskDestroyProducer(t *testing.T) func(s *terraform.Stat return err } - _, err = sendRequest(config, "GET", "", url, config.userAgent, nil) + billingProject := "" + + if config.BillingProject != "" { + billingProject = config.BillingProject + } + + _, err = sendRequest(config, "GET", billingProject, url, config.userAgent, nil) if err == nil { return fmt.Errorf("ComputeDisk still exists at %s", url) } diff --git a/google/resource_compute_disk_resource_policy_attachment_generated_test.go b/google/resource_compute_disk_resource_policy_attachment_generated_test.go index 66f347efaa9..7472b011579 100644 --- a/google/resource_compute_disk_resource_policy_attachment_generated_test.go +++ b/google/resource_compute_disk_resource_policy_attachment_generated_test.go @@ -104,7 +104,13 @@ func testAccCheckComputeDiskResourcePolicyAttachmentDestroyProducer(t *testing.T return err } - _, err = sendRequest(config, "GET", "", url, config.userAgent, nil) + billingProject := "" + + if config.BillingProject != "" { + billingProject = config.BillingProject + } + + _, err = sendRequest(config, "GET", billingProject, url, config.userAgent, nil) if err == nil { return fmt.Errorf("ComputeDiskResourcePolicyAttachment still exists at %s", url) } diff --git a/google/resource_compute_external_vpn_gateway_generated_test.go b/google/resource_compute_external_vpn_gateway_generated_test.go index 3f0c461bc40..cf50c1670ac 100644 --- a/google/resource_compute_external_vpn_gateway_generated_test.go +++ b/google/resource_compute_external_vpn_gateway_generated_test.go @@ -174,7 +174,13 @@ func testAccCheckComputeExternalVpnGatewayDestroyProducer(t *testing.T) func(s * return err } - _, err = sendRequest(config, "GET", "", url, config.userAgent, nil) + billingProject := "" + + if config.BillingProject != "" { + billingProject = config.BillingProject + } + + _, err = sendRequest(config, "GET", billingProject, url, config.userAgent, nil) if err == nil { return fmt.Errorf("ComputeExternalVpnGateway still exists at %s", url) } diff --git a/google/resource_compute_firewall_generated_test.go b/google/resource_compute_firewall_generated_test.go index 0c3bb894539..56feb9526da 100644 --- a/google/resource_compute_firewall_generated_test.go +++ b/google/resource_compute_firewall_generated_test.go @@ -92,7 +92,13 @@ func testAccCheckComputeFirewallDestroyProducer(t *testing.T) func(s *terraform. return err } - _, err = sendRequest(config, "GET", "", url, config.userAgent, nil) + billingProject := "" + + if config.BillingProject != "" { + billingProject = config.BillingProject + } + + _, err = sendRequest(config, "GET", billingProject, url, config.userAgent, nil) if err == nil { return fmt.Errorf("ComputeFirewall still exists at %s", url) } diff --git a/google/resource_compute_forwarding_rule_generated_test.go b/google/resource_compute_forwarding_rule_generated_test.go index b7cb1d6184f..38e4c9f8be4 100644 --- a/google/resource_compute_forwarding_rule_generated_test.go +++ b/google/resource_compute_forwarding_rule_generated_test.go @@ -221,7 +221,13 @@ func testAccCheckComputeForwardingRuleDestroyProducer(t *testing.T) func(s *terr return err } - _, err = sendRequest(config, "GET", "", url, config.userAgent, nil) + billingProject := "" + + if config.BillingProject != "" { + billingProject = config.BillingProject + } + + _, err = sendRequest(config, "GET", billingProject, url, config.userAgent, nil) if err == nil { return fmt.Errorf("ComputeForwardingRule still exists at %s", url) } diff --git a/google/resource_compute_global_address_generated_test.go b/google/resource_compute_global_address_generated_test.go index fbcd6b74e32..cd041a7ddcd 100644 --- a/google/resource_compute_global_address_generated_test.go +++ b/google/resource_compute_global_address_generated_test.go @@ -76,7 +76,13 @@ func testAccCheckComputeGlobalAddressDestroyProducer(t *testing.T) func(s *terra return err } - _, err = sendRequest(config, "GET", "", url, config.userAgent, nil) + billingProject := "" + + if config.BillingProject != "" { + billingProject = config.BillingProject + } + + _, err = sendRequest(config, "GET", billingProject, url, config.userAgent, nil) if err == nil { return fmt.Errorf("ComputeGlobalAddress still exists at %s", url) } diff --git a/google/resource_compute_global_forwarding_rule_generated_test.go b/google/resource_compute_global_forwarding_rule_generated_test.go index a49db08f984..adb81683fbb 100644 --- a/google/resource_compute_global_forwarding_rule_generated_test.go +++ b/google/resource_compute_global_forwarding_rule_generated_test.go @@ -120,7 +120,13 @@ func testAccCheckComputeGlobalForwardingRuleDestroyProducer(t *testing.T) func(s return err } - _, err = sendRequest(config, "GET", "", url, config.userAgent, nil) + billingProject := "" + + if config.BillingProject != "" { + billingProject = config.BillingProject + } + + _, err = sendRequest(config, "GET", billingProject, url, config.userAgent, nil) if err == nil { return fmt.Errorf("ComputeGlobalForwardingRule still exists at %s", url) } diff --git a/google/resource_compute_global_network_endpoint_group_generated_test.go b/google/resource_compute_global_network_endpoint_group_generated_test.go index bbb67176a36..13f9a2a6446 100644 --- a/google/resource_compute_global_network_endpoint_group_generated_test.go +++ b/google/resource_compute_global_network_endpoint_group_generated_test.go @@ -114,7 +114,13 @@ func testAccCheckComputeGlobalNetworkEndpointGroupDestroyProducer(t *testing.T) return err } - _, err = sendRequest(config, "GET", "", url, config.userAgent, nil) + billingProject := "" + + if config.BillingProject != "" { + billingProject = config.BillingProject + } + + _, err = sendRequest(config, "GET", billingProject, url, config.userAgent, nil) if err == nil { return fmt.Errorf("ComputeGlobalNetworkEndpointGroup still exists at %s", url) } diff --git a/google/resource_compute_ha_vpn_gateway_generated_test.go b/google/resource_compute_ha_vpn_gateway_generated_test.go index deae41416e1..b8ef51d5e5c 100644 --- a/google/resource_compute_ha_vpn_gateway_generated_test.go +++ b/google/resource_compute_ha_vpn_gateway_generated_test.go @@ -296,7 +296,13 @@ func testAccCheckComputeHaVpnGatewayDestroyProducer(t *testing.T) func(s *terraf return err } - _, err = sendRequest(config, "GET", "", url, config.userAgent, nil) + billingProject := "" + + if config.BillingProject != "" { + billingProject = config.BillingProject + } + + _, err = sendRequest(config, "GET", billingProject, url, config.userAgent, nil) if err == nil { return fmt.Errorf("ComputeHaVpnGateway still exists at %s", url) } diff --git a/google/resource_compute_health_check_generated_test.go b/google/resource_compute_health_check_generated_test.go index 99c9dca9c9e..e7c35be9a99 100644 --- a/google/resource_compute_health_check_generated_test.go +++ b/google/resource_compute_health_check_generated_test.go @@ -584,7 +584,13 @@ func testAccCheckComputeHealthCheckDestroyProducer(t *testing.T) func(s *terrafo return err } - _, err = sendRequest(config, "GET", "", url, config.userAgent, nil) + billingProject := "" + + if config.BillingProject != "" { + billingProject = config.BillingProject + } + + _, err = sendRequest(config, "GET", billingProject, url, config.userAgent, nil) if err == nil { return fmt.Errorf("ComputeHealthCheck still exists at %s", url) } diff --git a/google/resource_compute_http_health_check_generated_test.go b/google/resource_compute_http_health_check_generated_test.go index 81932dfd96f..c0f91bb5fde 100644 --- a/google/resource_compute_http_health_check_generated_test.go +++ b/google/resource_compute_http_health_check_generated_test.go @@ -79,7 +79,13 @@ func testAccCheckComputeHttpHealthCheckDestroyProducer(t *testing.T) func(s *ter return err } - _, err = sendRequest(config, "GET", "", url, config.userAgent, nil) + billingProject := "" + + if config.BillingProject != "" { + billingProject = config.BillingProject + } + + _, err = sendRequest(config, "GET", billingProject, url, config.userAgent, nil) if err == nil { return fmt.Errorf("ComputeHttpHealthCheck still exists at %s", url) } diff --git a/google/resource_compute_https_health_check_generated_test.go b/google/resource_compute_https_health_check_generated_test.go index 80c3db6b55f..f1689f13db1 100644 --- a/google/resource_compute_https_health_check_generated_test.go +++ b/google/resource_compute_https_health_check_generated_test.go @@ -79,7 +79,13 @@ func testAccCheckComputeHttpsHealthCheckDestroyProducer(t *testing.T) func(s *te return err } - _, err = sendRequest(config, "GET", "", url, config.userAgent, nil) + billingProject := "" + + if config.BillingProject != "" { + billingProject = config.BillingProject + } + + _, err = sendRequest(config, "GET", billingProject, url, config.userAgent, nil) if err == nil { return fmt.Errorf("ComputeHttpsHealthCheck still exists at %s", url) } diff --git a/google/resource_compute_image_generated_test.go b/google/resource_compute_image_generated_test.go index a0de4ae291c..98915395dfe 100644 --- a/google/resource_compute_image_generated_test.go +++ b/google/resource_compute_image_generated_test.go @@ -128,7 +128,13 @@ func testAccCheckComputeImageDestroyProducer(t *testing.T) func(s *terraform.Sta return err } - _, err = sendRequest(config, "GET", "", url, config.userAgent, nil) + billingProject := "" + + if config.BillingProject != "" { + billingProject = config.BillingProject + } + + _, err = sendRequest(config, "GET", billingProject, url, config.userAgent, nil) if err == nil { return fmt.Errorf("ComputeImage still exists at %s", url) } diff --git a/google/resource_compute_instance_group_named_port_generated_test.go b/google/resource_compute_instance_group_named_port_generated_test.go index 4e02d9df03e..9fe83c299cd 100644 --- a/google/resource_compute_instance_group_named_port_generated_test.go +++ b/google/resource_compute_instance_group_named_port_generated_test.go @@ -115,7 +115,13 @@ func testAccCheckComputeInstanceGroupNamedPortDestroyProducer(t *testing.T) func return err } - _, err = sendRequest(config, "GET", "", url, config.userAgent, nil) + billingProject := "" + + if config.BillingProject != "" { + billingProject = config.BillingProject + } + + _, err = sendRequest(config, "GET", billingProject, url, config.userAgent, nil) if err == nil { return fmt.Errorf("ComputeInstanceGroupNamedPort still exists at %s", url) } diff --git a/google/resource_compute_managed_ssl_certificate_generated_test.go b/google/resource_compute_managed_ssl_certificate_generated_test.go index 02eea4279df..9add4c2f524 100644 --- a/google/resource_compute_managed_ssl_certificate_generated_test.go +++ b/google/resource_compute_managed_ssl_certificate_generated_test.go @@ -241,7 +241,13 @@ func testAccCheckComputeManagedSslCertificateDestroyProducer(t *testing.T) func( return err } - _, err = sendRequest(config, "GET", "", url, config.userAgent, nil) + billingProject := "" + + if config.BillingProject != "" { + billingProject = config.BillingProject + } + + _, err = sendRequest(config, "GET", billingProject, url, config.userAgent, nil) if err == nil { return fmt.Errorf("ComputeManagedSslCertificate still exists at %s", url) } diff --git a/google/resource_compute_network_endpoint_group_generated_test.go b/google/resource_compute_network_endpoint_group_generated_test.go index 4d07074bb46..76022d6bef4 100644 --- a/google/resource_compute_network_endpoint_group_generated_test.go +++ b/google/resource_compute_network_endpoint_group_generated_test.go @@ -92,7 +92,13 @@ func testAccCheckComputeNetworkEndpointGroupDestroyProducer(t *testing.T) func(s return err } - _, err = sendRequest(config, "GET", "", url, config.userAgent, nil) + billingProject := "" + + if config.BillingProject != "" { + billingProject = config.BillingProject + } + + _, err = sendRequest(config, "GET", billingProject, url, config.userAgent, nil) if err == nil { return fmt.Errorf("ComputeNetworkEndpointGroup still exists at %s", url) } diff --git a/google/resource_compute_network_generated_test.go b/google/resource_compute_network_generated_test.go index 4324d04e913..ae121274c72 100644 --- a/google/resource_compute_network_generated_test.go +++ b/google/resource_compute_network_generated_test.go @@ -111,7 +111,13 @@ func testAccCheckComputeNetworkDestroyProducer(t *testing.T) func(s *terraform.S return err } - _, err = sendRequest(config, "GET", "", url, config.userAgent, nil) + billingProject := "" + + if config.BillingProject != "" { + billingProject = config.BillingProject + } + + _, err = sendRequest(config, "GET", billingProject, url, config.userAgent, nil) if err == nil { return fmt.Errorf("ComputeNetwork still exists at %s", url) } diff --git a/google/resource_compute_node_group_generated_test.go b/google/resource_compute_node_group_generated_test.go index 57e1cf112ad..06fd5cd1e94 100644 --- a/google/resource_compute_node_group_generated_test.go +++ b/google/resource_compute_node_group_generated_test.go @@ -139,7 +139,13 @@ func testAccCheckComputeNodeGroupDestroyProducer(t *testing.T) func(s *terraform return err } - _, err = sendRequest(config, "GET", "", url, config.userAgent, nil) + billingProject := "" + + if config.BillingProject != "" { + billingProject = config.BillingProject + } + + _, err = sendRequest(config, "GET", billingProject, url, config.userAgent, nil) if err == nil { return fmt.Errorf("ComputeNodeGroup still exists at %s", url) } diff --git a/google/resource_compute_node_template_generated_test.go b/google/resource_compute_node_template_generated_test.go index 0ac9c4e363e..3c0abd38252 100644 --- a/google/resource_compute_node_template_generated_test.go +++ b/google/resource_compute_node_template_generated_test.go @@ -78,7 +78,13 @@ func testAccCheckComputeNodeTemplateDestroyProducer(t *testing.T) func(s *terraf return err } - _, err = sendRequest(config, "GET", "", url, config.userAgent, nil) + billingProject := "" + + if config.BillingProject != "" { + billingProject = config.BillingProject + } + + _, err = sendRequest(config, "GET", billingProject, url, config.userAgent, nil) if err == nil { return fmt.Errorf("ComputeNodeTemplate still exists at %s", url) } diff --git a/google/resource_compute_region_autoscaler_generated_test.go b/google/resource_compute_region_autoscaler_generated_test.go index 34f99b63940..37975a3c421 100644 --- a/google/resource_compute_region_autoscaler_generated_test.go +++ b/google/resource_compute_region_autoscaler_generated_test.go @@ -134,7 +134,13 @@ func testAccCheckComputeRegionAutoscalerDestroyProducer(t *testing.T) func(s *te return err } - _, err = sendRequest(config, "GET", "", url, config.userAgent, nil) + billingProject := "" + + if config.BillingProject != "" { + billingProject = config.BillingProject + } + + _, err = sendRequest(config, "GET", billingProject, url, config.userAgent, nil) if err == nil { return fmt.Errorf("ComputeRegionAutoscaler still exists at %s", url) } diff --git a/google/resource_compute_region_backend_service_generated_test.go b/google/resource_compute_region_backend_service_generated_test.go index 197c0d1a671..8924443faf3 100644 --- a/google/resource_compute_region_backend_service_generated_test.go +++ b/google/resource_compute_region_backend_service_generated_test.go @@ -367,7 +367,13 @@ func testAccCheckComputeRegionBackendServiceDestroyProducer(t *testing.T) func(s return err } - _, err = sendRequest(config, "GET", "", url, config.userAgent, nil) + billingProject := "" + + if config.BillingProject != "" { + billingProject = config.BillingProject + } + + _, err = sendRequest(config, "GET", billingProject, url, config.userAgent, nil) if err == nil { return fmt.Errorf("ComputeRegionBackendService still exists at %s", url) } diff --git a/google/resource_compute_region_disk_generated_test.go b/google/resource_compute_region_disk_generated_test.go index b2e0b6385b3..43b8c71ada5 100644 --- a/google/resource_compute_region_disk_generated_test.go +++ b/google/resource_compute_region_disk_generated_test.go @@ -96,7 +96,13 @@ func testAccCheckComputeRegionDiskDestroyProducer(t *testing.T) func(s *terrafor return err } - _, err = sendRequest(config, "GET", "", url, config.userAgent, nil) + billingProject := "" + + if config.BillingProject != "" { + billingProject = config.BillingProject + } + + _, err = sendRequest(config, "GET", billingProject, url, config.userAgent, nil) if err == nil { return fmt.Errorf("ComputeRegionDisk still exists at %s", url) } diff --git a/google/resource_compute_region_disk_resource_policy_attachment_generated_test.go b/google/resource_compute_region_disk_resource_policy_attachment_generated_test.go index a5ee3a63104..1d624766608 100644 --- a/google/resource_compute_region_disk_resource_policy_attachment_generated_test.go +++ b/google/resource_compute_region_disk_resource_policy_attachment_generated_test.go @@ -119,7 +119,13 @@ func testAccCheckComputeRegionDiskResourcePolicyAttachmentDestroyProducer(t *tes return err } - _, err = sendRequest(config, "GET", "", url, config.userAgent, nil) + billingProject := "" + + if config.BillingProject != "" { + billingProject = config.BillingProject + } + + _, err = sendRequest(config, "GET", billingProject, url, config.userAgent, nil) if err == nil { return fmt.Errorf("ComputeRegionDiskResourcePolicyAttachment still exists at %s", url) } diff --git a/google/resource_compute_region_health_check_generated_test.go b/google/resource_compute_region_health_check_generated_test.go index c6acde13811..66952d4fd98 100644 --- a/google/resource_compute_region_health_check_generated_test.go +++ b/google/resource_compute_region_health_check_generated_test.go @@ -596,7 +596,13 @@ func testAccCheckComputeRegionHealthCheckDestroyProducer(t *testing.T) func(s *t return err } - _, err = sendRequest(config, "GET", "", url, config.userAgent, nil) + billingProject := "" + + if config.BillingProject != "" { + billingProject = config.BillingProject + } + + _, err = sendRequest(config, "GET", billingProject, url, config.userAgent, nil) if err == nil { return fmt.Errorf("ComputeRegionHealthCheck still exists at %s", url) } diff --git a/google/resource_compute_region_network_endpoint_group_generated_test.go b/google/resource_compute_region_network_endpoint_group_generated_test.go index 00fc1612b17..e68ac730262 100644 --- a/google/resource_compute_region_network_endpoint_group_generated_test.go +++ b/google/resource_compute_region_network_endpoint_group_generated_test.go @@ -268,7 +268,13 @@ func testAccCheckComputeRegionNetworkEndpointGroupDestroyProducer(t *testing.T) return err } - _, err = sendRequest(config, "GET", "", url, config.userAgent, nil) + billingProject := "" + + if config.BillingProject != "" { + billingProject = config.BillingProject + } + + _, err = sendRequest(config, "GET", billingProject, url, config.userAgent, nil) if err == nil { return fmt.Errorf("ComputeRegionNetworkEndpointGroup still exists at %s", url) } diff --git a/google/resource_compute_region_ssl_certificate_generated_test.go b/google/resource_compute_region_ssl_certificate_generated_test.go index 052b714e471..adccf64d10b 100644 --- a/google/resource_compute_region_ssl_certificate_generated_test.go +++ b/google/resource_compute_region_ssl_certificate_generated_test.go @@ -245,7 +245,13 @@ func testAccCheckComputeRegionSslCertificateDestroyProducer(t *testing.T) func(s return err } - _, err = sendRequest(config, "GET", "", url, config.userAgent, nil) + billingProject := "" + + if config.BillingProject != "" { + billingProject = config.BillingProject + } + + _, err = sendRequest(config, "GET", billingProject, url, config.userAgent, nil) if err == nil { return fmt.Errorf("ComputeRegionSslCertificate still exists at %s", url) } diff --git a/google/resource_compute_region_target_http_proxy_generated_test.go b/google/resource_compute_region_target_http_proxy_generated_test.go index a923b3b8510..86cffb6c5c3 100644 --- a/google/resource_compute_region_target_http_proxy_generated_test.go +++ b/google/resource_compute_region_target_http_proxy_generated_test.go @@ -163,7 +163,13 @@ func testAccCheckComputeRegionTargetHttpProxyDestroyProducer(t *testing.T) func( return err } - _, err = sendRequest(config, "GET", "", url, config.userAgent, nil) + billingProject := "" + + if config.BillingProject != "" { + billingProject = config.BillingProject + } + + _, err = sendRequest(config, "GET", billingProject, url, config.userAgent, nil) if err == nil { return fmt.Errorf("ComputeRegionTargetHttpProxy still exists at %s", url) } diff --git a/google/resource_compute_region_target_https_proxy_generated_test.go b/google/resource_compute_region_target_https_proxy_generated_test.go index ba98d777395..3125b0b341e 100644 --- a/google/resource_compute_region_target_https_proxy_generated_test.go +++ b/google/resource_compute_region_target_https_proxy_generated_test.go @@ -126,7 +126,13 @@ func testAccCheckComputeRegionTargetHttpsProxyDestroyProducer(t *testing.T) func return err } - _, err = sendRequest(config, "GET", "", url, config.userAgent, nil) + billingProject := "" + + if config.BillingProject != "" { + billingProject = config.BillingProject + } + + _, err = sendRequest(config, "GET", billingProject, url, config.userAgent, nil) if err == nil { return fmt.Errorf("ComputeRegionTargetHttpsProxy still exists at %s", url) } diff --git a/google/resource_compute_region_url_map_generated_test.go b/google/resource_compute_region_url_map_generated_test.go index d2adfa0e30d..3a96a2af65d 100644 --- a/google/resource_compute_region_url_map_generated_test.go +++ b/google/resource_compute_region_url_map_generated_test.go @@ -580,7 +580,13 @@ func testAccCheckComputeRegionUrlMapDestroyProducer(t *testing.T) func(s *terraf return err } - _, err = sendRequest(config, "GET", "", url, config.userAgent, nil) + billingProject := "" + + if config.BillingProject != "" { + billingProject = config.BillingProject + } + + _, err = sendRequest(config, "GET", billingProject, url, config.userAgent, nil) if err == nil { return fmt.Errorf("ComputeRegionUrlMap still exists at %s", url) } diff --git a/google/resource_compute_reservation_generated_test.go b/google/resource_compute_reservation_generated_test.go index 9b70e579be4..f93168bd9aa 100644 --- a/google/resource_compute_reservation_generated_test.go +++ b/google/resource_compute_reservation_generated_test.go @@ -85,7 +85,13 @@ func testAccCheckComputeReservationDestroyProducer(t *testing.T) func(s *terrafo return err } - _, err = sendRequest(config, "GET", "", url, config.userAgent, nil) + billingProject := "" + + if config.BillingProject != "" { + billingProject = config.BillingProject + } + + _, err = sendRequest(config, "GET", billingProject, url, config.userAgent, nil) if err == nil { return fmt.Errorf("ComputeReservation still exists at %s", url) } diff --git a/google/resource_compute_resource_policy_generated_test.go b/google/resource_compute_resource_policy_generated_test.go index f69316a60d7..32268b3738b 100644 --- a/google/resource_compute_resource_policy_generated_test.go +++ b/google/resource_compute_resource_policy_generated_test.go @@ -182,7 +182,13 @@ func testAccCheckComputeResourcePolicyDestroyProducer(t *testing.T) func(s *terr return err } - _, err = sendRequest(config, "GET", "", url, config.userAgent, nil) + billingProject := "" + + if config.BillingProject != "" { + billingProject = config.BillingProject + } + + _, err = sendRequest(config, "GET", billingProject, url, config.userAgent, nil) if err == nil { return fmt.Errorf("ComputeResourcePolicy still exists at %s", url) } diff --git a/google/resource_compute_route_generated_test.go b/google/resource_compute_route_generated_test.go index 6a9a8e909bb..fced4892219 100644 --- a/google/resource_compute_route_generated_test.go +++ b/google/resource_compute_route_generated_test.go @@ -163,7 +163,13 @@ func testAccCheckComputeRouteDestroyProducer(t *testing.T) func(s *terraform.Sta return err } - _, err = sendRequest(config, "GET", "", url, config.userAgent, nil, isPeeringOperationInProgress) + billingProject := "" + + if config.BillingProject != "" { + billingProject = config.BillingProject + } + + _, err = sendRequest(config, "GET", billingProject, url, config.userAgent, nil, isPeeringOperationInProgress) if err == nil { return fmt.Errorf("ComputeRoute still exists at %s", url) } diff --git a/google/resource_compute_router_generated_test.go b/google/resource_compute_router_generated_test.go index 45c82792ce6..d607a5f79a8 100644 --- a/google/resource_compute_router_generated_test.go +++ b/google/resource_compute_router_generated_test.go @@ -93,7 +93,13 @@ func testAccCheckComputeRouterDestroyProducer(t *testing.T) func(s *terraform.St return err } - _, err = sendRequest(config, "GET", "", url, config.userAgent, nil) + billingProject := "" + + if config.BillingProject != "" { + billingProject = config.BillingProject + } + + _, err = sendRequest(config, "GET", billingProject, url, config.userAgent, nil) if err == nil { return fmt.Errorf("ComputeRouter still exists at %s", url) } diff --git a/google/resource_compute_snapshot_generated_test.go b/google/resource_compute_snapshot_generated_test.go index 42bc3520540..75403c715a7 100644 --- a/google/resource_compute_snapshot_generated_test.go +++ b/google/resource_compute_snapshot_generated_test.go @@ -95,7 +95,13 @@ func testAccCheckComputeSnapshotDestroyProducer(t *testing.T) func(s *terraform. return err } - _, err = sendRequest(config, "GET", "", url, config.userAgent, nil) + billingProject := "" + + if config.BillingProject != "" { + billingProject = config.BillingProject + } + + _, err = sendRequest(config, "GET", billingProject, url, config.userAgent, nil) if err == nil { return fmt.Errorf("ComputeSnapshot still exists at %s", url) } diff --git a/google/resource_compute_ssl_certificate_generated_test.go b/google/resource_compute_ssl_certificate_generated_test.go index ed12a8d3d20..607690f0e10 100644 --- a/google/resource_compute_ssl_certificate_generated_test.go +++ b/google/resource_compute_ssl_certificate_generated_test.go @@ -238,7 +238,13 @@ func testAccCheckComputeSslCertificateDestroyProducer(t *testing.T) func(s *terr return err } - _, err = sendRequest(config, "GET", "", url, config.userAgent, nil) + billingProject := "" + + if config.BillingProject != "" { + billingProject = config.BillingProject + } + + _, err = sendRequest(config, "GET", billingProject, url, config.userAgent, nil) if err == nil { return fmt.Errorf("ComputeSslCertificate still exists at %s", url) } diff --git a/google/resource_compute_ssl_policy_generated_test.go b/google/resource_compute_ssl_policy_generated_test.go index 5b0e38cceb6..0026fb30546 100644 --- a/google/resource_compute_ssl_policy_generated_test.go +++ b/google/resource_compute_ssl_policy_generated_test.go @@ -89,7 +89,13 @@ func testAccCheckComputeSslPolicyDestroyProducer(t *testing.T) func(s *terraform return err } - _, err = sendRequest(config, "GET", "", url, config.userAgent, nil) + billingProject := "" + + if config.BillingProject != "" { + billingProject = config.BillingProject + } + + _, err = sendRequest(config, "GET", billingProject, url, config.userAgent, nil) if err == nil { return fmt.Errorf("ComputeSslPolicy still exists at %s", url) } diff --git a/google/resource_compute_subnetwork_generated_test.go b/google/resource_compute_subnetwork_generated_test.go index f602c49b467..732d33f28cf 100644 --- a/google/resource_compute_subnetwork_generated_test.go +++ b/google/resource_compute_subnetwork_generated_test.go @@ -138,7 +138,13 @@ func testAccCheckComputeSubnetworkDestroyProducer(t *testing.T) func(s *terrafor return err } - _, err = sendRequest(config, "GET", "", url, config.userAgent, nil) + billingProject := "" + + if config.BillingProject != "" { + billingProject = config.BillingProject + } + + _, err = sendRequest(config, "GET", billingProject, url, config.userAgent, nil) if err == nil { return fmt.Errorf("ComputeSubnetwork still exists at %s", url) } diff --git a/google/resource_compute_target_grpc_proxy_generated_test.go b/google/resource_compute_target_grpc_proxy_generated_test.go index fa2a1589aac..cd4e96eb7dc 100644 --- a/google/resource_compute_target_grpc_proxy_generated_test.go +++ b/google/resource_compute_target_grpc_proxy_generated_test.go @@ -159,7 +159,13 @@ func testAccCheckComputeTargetGrpcProxyDestroyProducer(t *testing.T) func(s *ter return err } - _, err = sendRequest(config, "GET", "", url, config.userAgent, nil) + billingProject := "" + + if config.BillingProject != "" { + billingProject = config.BillingProject + } + + _, err = sendRequest(config, "GET", billingProject, url, config.userAgent, nil) if err == nil { return fmt.Errorf("ComputeTargetGrpcProxy still exists at %s", url) } diff --git a/google/resource_compute_target_http_proxy_generated_test.go b/google/resource_compute_target_http_proxy_generated_test.go index b768591fb9a..d0f3e80345d 100644 --- a/google/resource_compute_target_http_proxy_generated_test.go +++ b/google/resource_compute_target_http_proxy_generated_test.go @@ -158,7 +158,13 @@ func testAccCheckComputeTargetHttpProxyDestroyProducer(t *testing.T) func(s *ter return err } - _, err = sendRequest(config, "GET", "", url, config.userAgent, nil) + billingProject := "" + + if config.BillingProject != "" { + billingProject = config.BillingProject + } + + _, err = sendRequest(config, "GET", billingProject, url, config.userAgent, nil) if err == nil { return fmt.Errorf("ComputeTargetHttpProxy still exists at %s", url) } diff --git a/google/resource_compute_target_https_proxy_generated_test.go b/google/resource_compute_target_https_proxy_generated_test.go index 25b6142ea8f..1c679a9c360 100644 --- a/google/resource_compute_target_https_proxy_generated_test.go +++ b/google/resource_compute_target_https_proxy_generated_test.go @@ -122,7 +122,13 @@ func testAccCheckComputeTargetHttpsProxyDestroyProducer(t *testing.T) func(s *te return err } - _, err = sendRequest(config, "GET", "", url, config.userAgent, nil) + billingProject := "" + + if config.BillingProject != "" { + billingProject = config.BillingProject + } + + _, err = sendRequest(config, "GET", billingProject, url, config.userAgent, nil) if err == nil { return fmt.Errorf("ComputeTargetHttpsProxy still exists at %s", url) } diff --git a/google/resource_compute_target_instance_generated_test.go b/google/resource_compute_target_instance_generated_test.go index 2de128f8f77..3ceaac4312b 100644 --- a/google/resource_compute_target_instance_generated_test.go +++ b/google/resource_compute_target_instance_generated_test.go @@ -98,7 +98,13 @@ func testAccCheckComputeTargetInstanceDestroyProducer(t *testing.T) func(s *terr return err } - _, err = sendRequest(config, "GET", "", url, config.userAgent, nil) + billingProject := "" + + if config.BillingProject != "" { + billingProject = config.BillingProject + } + + _, err = sendRequest(config, "GET", billingProject, url, config.userAgent, nil) if err == nil { return fmt.Errorf("ComputeTargetInstance still exists at %s", url) } diff --git a/google/resource_compute_target_ssl_proxy_generated_test.go b/google/resource_compute_target_ssl_proxy_generated_test.go index 5fc39106aab..97bb6139566 100644 --- a/google/resource_compute_target_ssl_proxy_generated_test.go +++ b/google/resource_compute_target_ssl_proxy_generated_test.go @@ -99,7 +99,13 @@ func testAccCheckComputeTargetSslProxyDestroyProducer(t *testing.T) func(s *terr return err } - _, err = sendRequest(config, "GET", "", url, config.userAgent, nil) + billingProject := "" + + if config.BillingProject != "" { + billingProject = config.BillingProject + } + + _, err = sendRequest(config, "GET", billingProject, url, config.userAgent, nil) if err == nil { return fmt.Errorf("ComputeTargetSslProxy still exists at %s", url) } diff --git a/google/resource_compute_target_tcp_proxy_generated_test.go b/google/resource_compute_target_tcp_proxy_generated_test.go index e42a2e98b17..b9625db551f 100644 --- a/google/resource_compute_target_tcp_proxy_generated_test.go +++ b/google/resource_compute_target_tcp_proxy_generated_test.go @@ -95,7 +95,13 @@ func testAccCheckComputeTargetTcpProxyDestroyProducer(t *testing.T) func(s *terr return err } - _, err = sendRequest(config, "GET", "", url, config.userAgent, nil) + billingProject := "" + + if config.BillingProject != "" { + billingProject = config.BillingProject + } + + _, err = sendRequest(config, "GET", billingProject, url, config.userAgent, nil) if err == nil { return fmt.Errorf("ComputeTargetTcpProxy still exists at %s", url) } diff --git a/google/resource_compute_url_map_generated_test.go b/google/resource_compute_url_map_generated_test.go index 6c70cde970f..bb8b782954a 100644 --- a/google/resource_compute_url_map_generated_test.go +++ b/google/resource_compute_url_map_generated_test.go @@ -805,7 +805,13 @@ func testAccCheckComputeUrlMapDestroyProducer(t *testing.T) func(s *terraform.St return err } - _, err = sendRequest(config, "GET", "", url, config.userAgent, nil) + billingProject := "" + + if config.BillingProject != "" { + billingProject = config.BillingProject + } + + _, err = sendRequest(config, "GET", billingProject, url, config.userAgent, nil) if err == nil { return fmt.Errorf("ComputeUrlMap still exists at %s", url) } diff --git a/google/resource_compute_vpn_gateway_generated_test.go b/google/resource_compute_vpn_gateway_generated_test.go index df3fc3ba6a5..7b7441b0926 100644 --- a/google/resource_compute_vpn_gateway_generated_test.go +++ b/google/resource_compute_vpn_gateway_generated_test.go @@ -131,7 +131,13 @@ func testAccCheckComputeVpnGatewayDestroyProducer(t *testing.T) func(s *terrafor return err } - _, err = sendRequest(config, "GET", "", url, config.userAgent, nil) + billingProject := "" + + if config.BillingProject != "" { + billingProject = config.BillingProject + } + + _, err = sendRequest(config, "GET", billingProject, url, config.userAgent, nil) if err == nil { return fmt.Errorf("ComputeVpnGateway still exists at %s", url) } diff --git a/google/resource_compute_vpn_tunnel_generated_test.go b/google/resource_compute_vpn_tunnel_generated_test.go index dd5c35d1b7c..bf4d7e083f6 100644 --- a/google/resource_compute_vpn_tunnel_generated_test.go +++ b/google/resource_compute_vpn_tunnel_generated_test.go @@ -131,7 +131,13 @@ func testAccCheckComputeVpnTunnelDestroyProducer(t *testing.T) func(s *terraform return err } - _, err = sendRequest(config, "GET", "", url, config.userAgent, nil) + billingProject := "" + + if config.BillingProject != "" { + billingProject = config.BillingProject + } + + _, err = sendRequest(config, "GET", billingProject, url, config.userAgent, nil) if err == nil { return fmt.Errorf("ComputeVpnTunnel still exists at %s", url) } diff --git a/google/resource_container_analysis_note_generated_test.go b/google/resource_container_analysis_note_generated_test.go index 895787802f1..e7261e3eaac 100644 --- a/google/resource_container_analysis_note_generated_test.go +++ b/google/resource_container_analysis_note_generated_test.go @@ -134,7 +134,13 @@ func testAccCheckContainerAnalysisNoteDestroyProducer(t *testing.T) func(s *terr return err } - _, err = sendRequest(config, "GET", "", url, config.userAgent, nil) + billingProject := "" + + if config.BillingProject != "" { + billingProject = config.BillingProject + } + + _, err = sendRequest(config, "GET", billingProject, url, config.userAgent, nil) if err == nil { return fmt.Errorf("ContainerAnalysisNote still exists at %s", url) } diff --git a/google/resource_data_catalog_entry_generated_test.go b/google/resource_data_catalog_entry_generated_test.go index e44ba7cd982..b3a3546365e 100644 --- a/google/resource_data_catalog_entry_generated_test.go +++ b/google/resource_data_catalog_entry_generated_test.go @@ -218,7 +218,13 @@ func testAccCheckDataCatalogEntryDestroyProducer(t *testing.T) func(s *terraform return err } - _, err = sendRequest(config, "GET", "", url, config.userAgent, nil) + billingProject := "" + + if config.BillingProject != "" { + billingProject = config.BillingProject + } + + _, err = sendRequest(config, "GET", billingProject, url, config.userAgent, nil) if err == nil { return fmt.Errorf("DataCatalogEntry still exists at %s", url) } diff --git a/google/resource_data_catalog_entry_group_generated_test.go b/google/resource_data_catalog_entry_group_generated_test.go index b1de3170030..13df0b35d3a 100644 --- a/google/resource_data_catalog_entry_group_generated_test.go +++ b/google/resource_data_catalog_entry_group_generated_test.go @@ -115,7 +115,13 @@ func testAccCheckDataCatalogEntryGroupDestroyProducer(t *testing.T) func(s *terr return err } - _, err = sendRequest(config, "GET", "", url, config.userAgent, nil) + billingProject := "" + + if config.BillingProject != "" { + billingProject = config.BillingProject + } + + _, err = sendRequest(config, "GET", billingProject, url, config.userAgent, nil) if err == nil { return fmt.Errorf("DataCatalogEntryGroup still exists at %s", url) } diff --git a/google/resource_data_catalog_tag_generated_test.go b/google/resource_data_catalog_tag_generated_test.go index 2ceda6a9f53..6c8f9d46d1f 100644 --- a/google/resource_data_catalog_tag_generated_test.go +++ b/google/resource_data_catalog_tag_generated_test.go @@ -509,7 +509,13 @@ func testAccCheckDataCatalogTagDestroyProducer(t *testing.T) func(s *terraform.S return err } - _, err = sendRequest(config, "GET", "", url, config.userAgent, nil) + billingProject := "" + + if config.BillingProject != "" { + billingProject = config.BillingProject + } + + _, err = sendRequest(config, "GET", billingProject, url, config.userAgent, nil) if err == nil { return fmt.Errorf("DataCatalogTag still exists at %s", url) } diff --git a/google/resource_data_catalog_tag_template_generated_test.go b/google/resource_data_catalog_tag_template_generated_test.go index 21e9adba0a7..69392abae42 100644 --- a/google/resource_data_catalog_tag_template_generated_test.go +++ b/google/resource_data_catalog_tag_template_generated_test.go @@ -116,7 +116,13 @@ func testAccCheckDataCatalogTagTemplateDestroyProducer(t *testing.T) func(s *ter return err } - _, err = sendRequest(config, "GET", "", url, config.userAgent, nil) + billingProject := "" + + if config.BillingProject != "" { + billingProject = config.BillingProject + } + + _, err = sendRequest(config, "GET", billingProject, url, config.userAgent, nil) if err == nil { return fmt.Errorf("DataCatalogTagTemplate still exists at %s", url) } diff --git a/google/resource_data_loss_prevention_deidentify_template_generated_test.go b/google/resource_data_loss_prevention_deidentify_template_generated_test.go index 7cdf57c9a52..698f96daafb 100644 --- a/google/resource_data_loss_prevention_deidentify_template_generated_test.go +++ b/google/resource_data_loss_prevention_deidentify_template_generated_test.go @@ -138,7 +138,13 @@ func testAccCheckDataLossPreventionDeidentifyTemplateDestroyProducer(t *testing. return err } - _, err = sendRequest(config, "GET", "", url, config.userAgent, nil) + billingProject := "" + + if config.BillingProject != "" { + billingProject = config.BillingProject + } + + _, err = sendRequest(config, "GET", billingProject, url, config.userAgent, nil) if err == nil { return fmt.Errorf("DataLossPreventionDeidentifyTemplate still exists at %s", url) } diff --git a/google/resource_data_loss_prevention_inspect_template_generated_test.go b/google/resource_data_loss_prevention_inspect_template_generated_test.go index 8ed2a4edd2c..3888e569c6d 100644 --- a/google/resource_data_loss_prevention_inspect_template_generated_test.go +++ b/google/resource_data_loss_prevention_inspect_template_generated_test.go @@ -274,7 +274,13 @@ func testAccCheckDataLossPreventionInspectTemplateDestroyProducer(t *testing.T) return err } - _, err = sendRequest(config, "GET", "", url, config.userAgent, nil) + billingProject := "" + + if config.BillingProject != "" { + billingProject = config.BillingProject + } + + _, err = sendRequest(config, "GET", billingProject, url, config.userAgent, nil) if err == nil { return fmt.Errorf("DataLossPreventionInspectTemplate still exists at %s", url) } diff --git a/google/resource_data_loss_prevention_job_trigger_generated_test.go b/google/resource_data_loss_prevention_job_trigger_generated_test.go index 090cdf95447..9067dd826fc 100644 --- a/google/resource_data_loss_prevention_job_trigger_generated_test.go +++ b/google/resource_data_loss_prevention_job_trigger_generated_test.go @@ -106,7 +106,13 @@ func testAccCheckDataLossPreventionJobTriggerDestroyProducer(t *testing.T) func( return err } - _, err = sendRequest(config, "GET", "", url, config.userAgent, nil) + billingProject := "" + + if config.BillingProject != "" { + billingProject = config.BillingProject + } + + _, err = sendRequest(config, "GET", billingProject, url, config.userAgent, nil) if err == nil { return fmt.Errorf("DataLossPreventionJobTrigger still exists at %s", url) } diff --git a/google/resource_data_loss_prevention_stored_info_type_generated_test.go b/google/resource_data_loss_prevention_stored_info_type_generated_test.go index 9ad2a25532d..23a22d40ea8 100644 --- a/google/resource_data_loss_prevention_stored_info_type_generated_test.go +++ b/google/resource_data_loss_prevention_stored_info_type_generated_test.go @@ -188,7 +188,13 @@ func testAccCheckDataLossPreventionStoredInfoTypeDestroyProducer(t *testing.T) f return err } - _, err = sendRequest(config, "GET", "", url, config.userAgent, nil) + billingProject := "" + + if config.BillingProject != "" { + billingProject = config.BillingProject + } + + _, err = sendRequest(config, "GET", billingProject, url, config.userAgent, nil) if err == nil { return fmt.Errorf("DataLossPreventionStoredInfoType still exists at %s", url) } diff --git a/google/resource_dataproc_autoscaling_policy_generated_test.go b/google/resource_dataproc_autoscaling_policy_generated_test.go index c5f4680adce..1ef844bd810 100644 --- a/google/resource_dataproc_autoscaling_policy_generated_test.go +++ b/google/resource_dataproc_autoscaling_policy_generated_test.go @@ -101,7 +101,13 @@ func testAccCheckDataprocAutoscalingPolicyDestroyProducer(t *testing.T) func(s * return err } - _, err = sendRequest(config, "GET", "", url, config.userAgent, nil) + billingProject := "" + + if config.BillingProject != "" { + billingProject = config.BillingProject + } + + _, err = sendRequest(config, "GET", billingProject, url, config.userAgent, nil) if err == nil { return fmt.Errorf("DataprocAutoscalingPolicy still exists at %s", url) } diff --git a/google/resource_datastore_index_generated_test.go b/google/resource_datastore_index_generated_test.go index fc1566f77dc..92b6cd8f519 100644 --- a/google/resource_datastore_index_generated_test.go +++ b/google/resource_datastore_index_generated_test.go @@ -83,7 +83,13 @@ func testAccCheckDatastoreIndexDestroyProducer(t *testing.T) func(s *terraform.S return err } - _, err = sendRequest(config, "GET", "", url, config.userAgent, nil, datastoreIndex409Contention) + billingProject := "" + + if config.BillingProject != "" { + billingProject = config.BillingProject + } + + _, err = sendRequest(config, "GET", billingProject, url, config.userAgent, nil, datastoreIndex409Contention) if err == nil { return fmt.Errorf("DatastoreIndex still exists at %s", url) } diff --git a/google/resource_dialogflow_agent_generated_test.go b/google/resource_dialogflow_agent_generated_test.go index 76cbe91fc8c..a063b4f8680 100644 --- a/google/resource_dialogflow_agent_generated_test.go +++ b/google/resource_dialogflow_agent_generated_test.go @@ -86,7 +86,13 @@ func testAccCheckDialogflowAgentDestroyProducer(t *testing.T) func(s *terraform. return err } - _, err = sendRequest(config, "GET", "", url, config.userAgent, nil) + billingProject := "" + + if config.BillingProject != "" { + billingProject = config.BillingProject + } + + _, err = sendRequest(config, "GET", billingProject, url, config.userAgent, nil) if err == nil { return fmt.Errorf("DialogflowAgent still exists at %s", url) } diff --git a/google/resource_dialogflow_intent_generated_test.go b/google/resource_dialogflow_intent_generated_test.go index c823105ec7e..71505ddba1e 100644 --- a/google/resource_dialogflow_intent_generated_test.go +++ b/google/resource_dialogflow_intent_generated_test.go @@ -116,7 +116,13 @@ func testAccCheckDialogflowIntentDestroyProducer(t *testing.T) func(s *terraform return err } - _, err = sendRequest(config, "GET", "", url, config.userAgent, nil) + billingProject := "" + + if config.BillingProject != "" { + billingProject = config.BillingProject + } + + _, err = sendRequest(config, "GET", billingProject, url, config.userAgent, nil) if err == nil { return fmt.Errorf("DialogflowIntent still exists at %s", url) } diff --git a/google/resource_dns_managed_zone_generated_test.go b/google/resource_dns_managed_zone_generated_test.go index 609d02fe2cf..8be3725ef9c 100644 --- a/google/resource_dns_managed_zone_generated_test.go +++ b/google/resource_dns_managed_zone_generated_test.go @@ -207,7 +207,13 @@ func testAccCheckDNSManagedZoneDestroyProducer(t *testing.T) func(s *terraform.S return err } - _, err = sendRequest(config, "GET", "", url, config.userAgent, nil) + billingProject := "" + + if config.BillingProject != "" { + billingProject = config.BillingProject + } + + _, err = sendRequest(config, "GET", billingProject, url, config.userAgent, nil) if err == nil { return fmt.Errorf("DNSManagedZone still exists at %s", url) } diff --git a/google/resource_dns_policy_generated_test.go b/google/resource_dns_policy_generated_test.go index bba9c2f7dfa..54d4c66c22c 100644 --- a/google/resource_dns_policy_generated_test.go +++ b/google/resource_dns_policy_generated_test.go @@ -105,7 +105,13 @@ func testAccCheckDNSPolicyDestroyProducer(t *testing.T) func(s *terraform.State) return err } - _, err = sendRequest(config, "GET", "", url, config.userAgent, nil) + billingProject := "" + + if config.BillingProject != "" { + billingProject = config.BillingProject + } + + _, err = sendRequest(config, "GET", billingProject, url, config.userAgent, nil) if err == nil { return fmt.Errorf("DNSPolicy still exists at %s", url) } diff --git a/google/resource_filestore_instance_generated_test.go b/google/resource_filestore_instance_generated_test.go index e64a3f2d5bc..2944f167a5b 100644 --- a/google/resource_filestore_instance_generated_test.go +++ b/google/resource_filestore_instance_generated_test.go @@ -88,7 +88,13 @@ func testAccCheckFilestoreInstanceDestroyProducer(t *testing.T) func(s *terrafor return err } - _, err = sendRequest(config, "GET", "", url, config.userAgent, nil) + billingProject := "" + + if config.BillingProject != "" { + billingProject = config.BillingProject + } + + _, err = sendRequest(config, "GET", billingProject, url, config.userAgent, nil) if err == nil { return fmt.Errorf("FilestoreInstance still exists at %s", url) } diff --git a/google/resource_firestore_document_generated_test.go b/google/resource_firestore_document_generated_test.go index 34c16eda8e9..ca2f5cbddb0 100644 --- a/google/resource_firestore_document_generated_test.go +++ b/google/resource_firestore_document_generated_test.go @@ -134,7 +134,13 @@ func testAccCheckFirestoreDocumentDestroyProducer(t *testing.T) func(s *terrafor return err } - _, err = sendRequest(config, "GET", "", url, config.userAgent, nil) + billingProject := "" + + if config.BillingProject != "" { + billingProject = config.BillingProject + } + + _, err = sendRequest(config, "GET", billingProject, url, config.userAgent, nil) if err == nil { return fmt.Errorf("FirestoreDocument still exists at %s", url) } diff --git a/google/resource_firestore_index_generated_test.go b/google/resource_firestore_index_generated_test.go index c570fcee5f7..88c471d78be 100644 --- a/google/resource_firestore_index_generated_test.go +++ b/google/resource_firestore_index_generated_test.go @@ -94,7 +94,13 @@ func testAccCheckFirestoreIndexDestroyProducer(t *testing.T) func(s *terraform.S return err } - _, err = sendRequest(config, "GET", "", url, config.userAgent, nil) + billingProject := "" + + if config.BillingProject != "" { + billingProject = config.BillingProject + } + + _, err = sendRequest(config, "GET", billingProject, url, config.userAgent, nil) if err == nil { return fmt.Errorf("FirestoreIndex still exists at %s", url) } diff --git a/google/resource_game_services_game_server_cluster_generated_test.go b/google/resource_game_services_game_server_cluster_generated_test.go index 49f1245be41..c2e9dbad61d 100644 --- a/google/resource_game_services_game_server_cluster_generated_test.go +++ b/google/resource_game_services_game_server_cluster_generated_test.go @@ -93,7 +93,13 @@ func testAccCheckGameServicesGameServerClusterDestroyProducer(t *testing.T) func return err } - _, err = sendRequest(config, "GET", "", url, config.userAgent, nil) + billingProject := "" + + if config.BillingProject != "" { + billingProject = config.BillingProject + } + + _, err = sendRequest(config, "GET", billingProject, url, config.userAgent, nil) if err == nil { return fmt.Errorf("GameServicesGameServerCluster still exists at %s", url) } diff --git a/google/resource_game_services_game_server_config_generated_test.go b/google/resource_game_services_game_server_config_generated_test.go index e9c63ddd6d8..d477059f7a6 100644 --- a/google/resource_game_services_game_server_config_generated_test.go +++ b/google/resource_game_services_game_server_config_generated_test.go @@ -103,7 +103,13 @@ func testAccCheckGameServicesGameServerConfigDestroyProducer(t *testing.T) func( return err } - _, err = sendRequest(config, "GET", "", url, config.userAgent, nil) + billingProject := "" + + if config.BillingProject != "" { + billingProject = config.BillingProject + } + + _, err = sendRequest(config, "GET", billingProject, url, config.userAgent, nil) if err == nil { return fmt.Errorf("GameServicesGameServerConfig still exists at %s", url) } diff --git a/google/resource_game_services_game_server_deployment_generated_test.go b/google/resource_game_services_game_server_deployment_generated_test.go index 40469d4720a..d4736cf9e67 100644 --- a/google/resource_game_services_game_server_deployment_generated_test.go +++ b/google/resource_game_services_game_server_deployment_generated_test.go @@ -77,7 +77,13 @@ func testAccCheckGameServicesGameServerDeploymentDestroyProducer(t *testing.T) f return err } - _, err = sendRequest(config, "GET", "", url, config.userAgent, nil) + billingProject := "" + + if config.BillingProject != "" { + billingProject = config.BillingProject + } + + _, err = sendRequest(config, "GET", billingProject, url, config.userAgent, nil) if err == nil { return fmt.Errorf("GameServicesGameServerDeployment still exists at %s", url) } diff --git a/google/resource_game_services_game_server_deployment_rollout_generated_test.go b/google/resource_game_services_game_server_deployment_rollout_generated_test.go index 3ea7fd8383e..8735cacff23 100644 --- a/google/resource_game_services_game_server_deployment_rollout_generated_test.go +++ b/google/resource_game_services_game_server_deployment_rollout_generated_test.go @@ -96,7 +96,13 @@ func testAccCheckGameServicesGameServerDeploymentRolloutDestroyProducer(t *testi return err } - _, err = sendRequest(config, "GET", "", url, config.userAgent, nil) + billingProject := "" + + if config.BillingProject != "" { + billingProject = config.BillingProject + } + + _, err = sendRequest(config, "GET", billingProject, url, config.userAgent, nil) if err == nil { return fmt.Errorf("GameServicesGameServerDeploymentRollout still exists at %s", url) } diff --git a/google/resource_game_services_realm_generated_test.go b/google/resource_game_services_realm_generated_test.go index 51c08f7e59d..b99fcb0839c 100644 --- a/google/resource_game_services_realm_generated_test.go +++ b/google/resource_game_services_realm_generated_test.go @@ -80,7 +80,13 @@ func testAccCheckGameServicesRealmDestroyProducer(t *testing.T) func(s *terrafor return err } - _, err = sendRequest(config, "GET", "", url, config.userAgent, nil) + billingProject := "" + + if config.BillingProject != "" { + billingProject = config.BillingProject + } + + _, err = sendRequest(config, "GET", billingProject, url, config.userAgent, nil) if err == nil { return fmt.Errorf("GameServicesRealm still exists at %s", url) } diff --git a/google/resource_healthcare_dataset_generated_test.go b/google/resource_healthcare_dataset_generated_test.go index 861bb81bc3f..4d5021c0ba3 100644 --- a/google/resource_healthcare_dataset_generated_test.go +++ b/google/resource_healthcare_dataset_generated_test.go @@ -78,7 +78,13 @@ func testAccCheckHealthcareDatasetDestroyProducer(t *testing.T) func(s *terrafor return err } - _, err = sendRequest(config, "GET", "", url, config.userAgent, nil) + billingProject := "" + + if config.BillingProject != "" { + billingProject = config.BillingProject + } + + _, err = sendRequest(config, "GET", billingProject, url, config.userAgent, nil) if err == nil { return fmt.Errorf("HealthcareDataset still exists at %s", url) } diff --git a/google/resource_healthcare_dicom_store_generated_test.go b/google/resource_healthcare_dicom_store_generated_test.go index 63067bbb03d..3fdaa95be1e 100644 --- a/google/resource_healthcare_dicom_store_generated_test.go +++ b/google/resource_healthcare_dicom_store_generated_test.go @@ -94,7 +94,13 @@ func testAccCheckHealthcareDicomStoreDestroyProducer(t *testing.T) func(s *terra return err } - _, err = sendRequest(config, "GET", "", url, config.userAgent, nil) + billingProject := "" + + if config.BillingProject != "" { + billingProject = config.BillingProject + } + + _, err = sendRequest(config, "GET", billingProject, url, config.userAgent, nil) if err == nil { return fmt.Errorf("HealthcareDicomStore still exists at %s", url) } diff --git a/google/resource_healthcare_fhir_store_generated_test.go b/google/resource_healthcare_fhir_store_generated_test.go index c2d1042d23b..803fa0ccd1a 100644 --- a/google/resource_healthcare_fhir_store_generated_test.go +++ b/google/resource_healthcare_fhir_store_generated_test.go @@ -174,7 +174,13 @@ func testAccCheckHealthcareFhirStoreDestroyProducer(t *testing.T) func(s *terraf return err } - _, err = sendRequest(config, "GET", "", url, config.userAgent, nil) + billingProject := "" + + if config.BillingProject != "" { + billingProject = config.BillingProject + } + + _, err = sendRequest(config, "GET", billingProject, url, config.userAgent, nil) if err == nil { return fmt.Errorf("HealthcareFhirStore still exists at %s", url) } diff --git a/google/resource_healthcare_hl7_v2_store_generated_test.go b/google/resource_healthcare_hl7_v2_store_generated_test.go index c9eb0ff70d4..af2050656f1 100644 --- a/google/resource_healthcare_hl7_v2_store_generated_test.go +++ b/google/resource_healthcare_hl7_v2_store_generated_test.go @@ -94,7 +94,13 @@ func testAccCheckHealthcareHl7V2StoreDestroyProducer(t *testing.T) func(s *terra return err } - _, err = sendRequest(config, "GET", "", url, config.userAgent, nil) + billingProject := "" + + if config.BillingProject != "" { + billingProject = config.BillingProject + } + + _, err = sendRequest(config, "GET", billingProject, url, config.userAgent, nil) if err == nil { return fmt.Errorf("HealthcareHl7V2Store still exists at %s", url) } diff --git a/google/resource_iap_client_generated_test.go b/google/resource_iap_client_generated_test.go index 2316687a790..0bc9862cbe1 100644 --- a/google/resource_iap_client_generated_test.go +++ b/google/resource_iap_client_generated_test.go @@ -96,7 +96,13 @@ func testAccCheckIapClientDestroyProducer(t *testing.T) func(s *terraform.State) return err } - _, err = sendRequest(config, "GET", "", url, config.userAgent, nil, iapClient409Operation) + billingProject := "" + + if config.BillingProject != "" { + billingProject = config.BillingProject + } + + _, err = sendRequest(config, "GET", billingProject, url, config.userAgent, nil, iapClient409Operation) if err == nil { return fmt.Errorf("IapClient still exists at %s", url) } diff --git a/google/resource_identity_platform_inbound_saml_config_generated_test.go b/google/resource_identity_platform_inbound_saml_config_generated_test.go index a21b317b4c4..c1347e7a70f 100644 --- a/google/resource_identity_platform_inbound_saml_config_generated_test.go +++ b/google/resource_identity_platform_inbound_saml_config_generated_test.go @@ -90,7 +90,13 @@ func testAccCheckIdentityPlatformInboundSamlConfigDestroyProducer(t *testing.T) return err } - _, err = sendRequest(config, "GET", "", url, config.userAgent, nil) + billingProject := "" + + if config.BillingProject != "" { + billingProject = config.BillingProject + } + + _, err = sendRequest(config, "GET", billingProject, url, config.userAgent, nil) if err == nil { return fmt.Errorf("IdentityPlatformInboundSamlConfig still exists at %s", url) } diff --git a/google/resource_identity_platform_oauth_idp_config_generated_test.go b/google/resource_identity_platform_oauth_idp_config_generated_test.go index 549e48d1fbe..1b2f9c7618b 100644 --- a/google/resource_identity_platform_oauth_idp_config_generated_test.go +++ b/google/resource_identity_platform_oauth_idp_config_generated_test.go @@ -81,7 +81,13 @@ func testAccCheckIdentityPlatformOauthIdpConfigDestroyProducer(t *testing.T) fun return err } - _, err = sendRequest(config, "GET", "", url, config.userAgent, nil) + billingProject := "" + + if config.BillingProject != "" { + billingProject = config.BillingProject + } + + _, err = sendRequest(config, "GET", billingProject, url, config.userAgent, nil) if err == nil { return fmt.Errorf("IdentityPlatformOauthIdpConfig still exists at %s", url) } diff --git a/google/resource_identity_platform_tenant_default_supported_idp_config_generated_test.go b/google/resource_identity_platform_tenant_default_supported_idp_config_generated_test.go index 7dbb7a5d183..9ab508f4f77 100644 --- a/google/resource_identity_platform_tenant_default_supported_idp_config_generated_test.go +++ b/google/resource_identity_platform_tenant_default_supported_idp_config_generated_test.go @@ -84,7 +84,13 @@ func testAccCheckIdentityPlatformTenantDefaultSupportedIdpConfigDestroyProducer( return err } - _, err = sendRequest(config, "GET", "", url, config.userAgent, nil) + billingProject := "" + + if config.BillingProject != "" { + billingProject = config.BillingProject + } + + _, err = sendRequest(config, "GET", billingProject, url, config.userAgent, nil) if err == nil { return fmt.Errorf("IdentityPlatformTenantDefaultSupportedIdpConfig still exists at %s", url) } diff --git a/google/resource_identity_platform_tenant_generated_test.go b/google/resource_identity_platform_tenant_generated_test.go index 9abf39126f8..2b5944e1668 100644 --- a/google/resource_identity_platform_tenant_generated_test.go +++ b/google/resource_identity_platform_tenant_generated_test.go @@ -76,7 +76,13 @@ func testAccCheckIdentityPlatformTenantDestroyProducer(t *testing.T) func(s *ter return err } - _, err = sendRequest(config, "GET", "", url, config.userAgent, nil) + billingProject := "" + + if config.BillingProject != "" { + billingProject = config.BillingProject + } + + _, err = sendRequest(config, "GET", billingProject, url, config.userAgent, nil) if err == nil { return fmt.Errorf("IdentityPlatformTenant still exists at %s", url) } diff --git a/google/resource_identity_platform_tenant_inbound_saml_config_generated_test.go b/google/resource_identity_platform_tenant_inbound_saml_config_generated_test.go index 119587dfff5..111373b968d 100644 --- a/google/resource_identity_platform_tenant_inbound_saml_config_generated_test.go +++ b/google/resource_identity_platform_tenant_inbound_saml_config_generated_test.go @@ -96,7 +96,13 @@ func testAccCheckIdentityPlatformTenantInboundSamlConfigDestroyProducer(t *testi return err } - _, err = sendRequest(config, "GET", "", url, config.userAgent, nil) + billingProject := "" + + if config.BillingProject != "" { + billingProject = config.BillingProject + } + + _, err = sendRequest(config, "GET", billingProject, url, config.userAgent, nil) if err == nil { return fmt.Errorf("IdentityPlatformTenantInboundSamlConfig still exists at %s", url) } diff --git a/google/resource_identity_platform_tenant_oauth_idp_config_generated_test.go b/google/resource_identity_platform_tenant_oauth_idp_config_generated_test.go index 5dfcd535640..858ae10576d 100644 --- a/google/resource_identity_platform_tenant_oauth_idp_config_generated_test.go +++ b/google/resource_identity_platform_tenant_oauth_idp_config_generated_test.go @@ -87,7 +87,13 @@ func testAccCheckIdentityPlatformTenantOauthIdpConfigDestroyProducer(t *testing. return err } - _, err = sendRequest(config, "GET", "", url, config.userAgent, nil) + billingProject := "" + + if config.BillingProject != "" { + billingProject = config.BillingProject + } + + _, err = sendRequest(config, "GET", billingProject, url, config.userAgent, nil) if err == nil { return fmt.Errorf("IdentityPlatformTenantOauthIdpConfig still exists at %s", url) } diff --git a/google/resource_logging_metric_generated_test.go b/google/resource_logging_metric_generated_test.go index 2b862308e1b..2c76e4fc5f5 100644 --- a/google/resource_logging_metric_generated_test.go +++ b/google/resource_logging_metric_generated_test.go @@ -192,7 +192,13 @@ func testAccCheckLoggingMetricDestroyProducer(t *testing.T) func(s *terraform.St return err } - _, err = sendRequest(config, "GET", "", url, config.userAgent, nil) + billingProject := "" + + if config.BillingProject != "" { + billingProject = config.BillingProject + } + + _, err = sendRequest(config, "GET", billingProject, url, config.userAgent, nil) if err == nil { return fmt.Errorf("LoggingMetric still exists at %s", url) } diff --git a/google/resource_ml_engine_model_generated_test.go b/google/resource_ml_engine_model_generated_test.go index 7db3269456f..bf727fb172a 100644 --- a/google/resource_ml_engine_model_generated_test.go +++ b/google/resource_ml_engine_model_generated_test.go @@ -119,7 +119,13 @@ func testAccCheckMLEngineModelDestroyProducer(t *testing.T) func(s *terraform.St return err } - _, err = sendRequest(config, "GET", "", url, config.userAgent, nil) + billingProject := "" + + if config.BillingProject != "" { + billingProject = config.BillingProject + } + + _, err = sendRequest(config, "GET", billingProject, url, config.userAgent, nil) if err == nil { return fmt.Errorf("MLEngineModel still exists at %s", url) } diff --git a/google/resource_monitoring_group_generated_test.go b/google/resource_monitoring_group_generated_test.go index d33c7e4c1f3..544d85fd6c9 100644 --- a/google/resource_monitoring_group_generated_test.go +++ b/google/resource_monitoring_group_generated_test.go @@ -119,7 +119,13 @@ func testAccCheckMonitoringGroupDestroyProducer(t *testing.T) func(s *terraform. return err } - _, err = sendRequest(config, "GET", "", url, config.userAgent, nil, isMonitoringConcurrentEditError) + billingProject := "" + + if config.BillingProject != "" { + billingProject = config.BillingProject + } + + _, err = sendRequest(config, "GET", billingProject, url, config.userAgent, nil, isMonitoringConcurrentEditError) if err == nil { return fmt.Errorf("MonitoringGroup still exists at %s", url) } diff --git a/google/resource_monitoring_metric_descriptor_generated_test.go b/google/resource_monitoring_metric_descriptor_generated_test.go index 01830370ad2..1a908f3acc9 100644 --- a/google/resource_monitoring_metric_descriptor_generated_test.go +++ b/google/resource_monitoring_metric_descriptor_generated_test.go @@ -145,7 +145,13 @@ func testAccCheckMonitoringMetricDescriptorDestroyProducer(t *testing.T) func(s return err } - _, err = sendRequest(config, "GET", "", url, config.userAgent, nil, isMonitoringConcurrentEditError) + billingProject := "" + + if config.BillingProject != "" { + billingProject = config.BillingProject + } + + _, err = sendRequest(config, "GET", billingProject, url, config.userAgent, nil, isMonitoringConcurrentEditError) if err == nil { return fmt.Errorf("MonitoringMetricDescriptor still exists at %s", url) } diff --git a/google/resource_monitoring_notification_channel_generated_test.go b/google/resource_monitoring_notification_channel_generated_test.go index 18795936c6e..972941aacd6 100644 --- a/google/resource_monitoring_notification_channel_generated_test.go +++ b/google/resource_monitoring_notification_channel_generated_test.go @@ -80,7 +80,13 @@ func testAccCheckMonitoringNotificationChannelDestroyProducer(t *testing.T) func return err } - _, err = sendRequest(config, "GET", "", url, config.userAgent, nil, isMonitoringConcurrentEditError) + billingProject := "" + + if config.BillingProject != "" { + billingProject = config.BillingProject + } + + _, err = sendRequest(config, "GET", billingProject, url, config.userAgent, nil, isMonitoringConcurrentEditError) if err == nil { return fmt.Errorf("MonitoringNotificationChannel still exists at %s", url) } diff --git a/google/resource_monitoring_service_generated_test.go b/google/resource_monitoring_service_generated_test.go index 9fc2b2efc48..ac15b04297f 100644 --- a/google/resource_monitoring_service_generated_test.go +++ b/google/resource_monitoring_service_generated_test.go @@ -80,7 +80,13 @@ func testAccCheckMonitoringServiceDestroyProducer(t *testing.T) func(s *terrafor return err } - _, err = sendRequest(config, "GET", "", url, config.userAgent, nil, isMonitoringConcurrentEditError) + billingProject := "" + + if config.BillingProject != "" { + billingProject = config.BillingProject + } + + _, err = sendRequest(config, "GET", billingProject, url, config.userAgent, nil, isMonitoringConcurrentEditError) if err == nil { return fmt.Errorf("MonitoringService still exists at %s", url) } diff --git a/google/resource_monitoring_slo_generated_test.go b/google/resource_monitoring_slo_generated_test.go index 9b695fa3b76..f4d237c6f9b 100644 --- a/google/resource_monitoring_slo_generated_test.go +++ b/google/resource_monitoring_slo_generated_test.go @@ -385,7 +385,13 @@ func testAccCheckMonitoringSloDestroyProducer(t *testing.T) func(s *terraform.St return err } - _, err = sendRequest(config, "GET", "", url, config.userAgent, nil) + billingProject := "" + + if config.BillingProject != "" { + billingProject = config.BillingProject + } + + _, err = sendRequest(config, "GET", billingProject, url, config.userAgent, nil) if err == nil { return fmt.Errorf("MonitoringSlo still exists at %s", url) } diff --git a/google/resource_monitoring_uptime_check_config_generated_test.go b/google/resource_monitoring_uptime_check_config_generated_test.go index 845e034de66..331aa45c4c5 100644 --- a/google/resource_monitoring_uptime_check_config_generated_test.go +++ b/google/resource_monitoring_uptime_check_config_generated_test.go @@ -203,7 +203,13 @@ func testAccCheckMonitoringUptimeCheckConfigDestroyProducer(t *testing.T) func(s return err } - _, err = sendRequest(config, "GET", "", url, config.userAgent, nil, isMonitoringConcurrentEditError) + billingProject := "" + + if config.BillingProject != "" { + billingProject = config.BillingProject + } + + _, err = sendRequest(config, "GET", billingProject, url, config.userAgent, nil, isMonitoringConcurrentEditError) if err == nil { return fmt.Errorf("MonitoringUptimeCheckConfig still exists at %s", url) } diff --git a/google/resource_network_management_connectivity_test_resource_generated_test.go b/google/resource_network_management_connectivity_test_resource_generated_test.go index 39d1dfe1d79..56aba2c417f 100644 --- a/google/resource_network_management_connectivity_test_resource_generated_test.go +++ b/google/resource_network_management_connectivity_test_resource_generated_test.go @@ -203,7 +203,13 @@ func testAccCheckNetworkManagementConnectivityTestDestroyProducer(t *testing.T) return err } - _, err = sendRequest(config, "GET", "", url, config.userAgent, nil) + billingProject := "" + + if config.BillingProject != "" { + billingProject = config.BillingProject + } + + _, err = sendRequest(config, "GET", billingProject, url, config.userAgent, nil) if err == nil { return fmt.Errorf("NetworkManagementConnectivityTest still exists at %s", url) } diff --git a/google/resource_notebooks_environment_generated_test.go b/google/resource_notebooks_environment_generated_test.go index 186f0e14631..bee030f69a8 100644 --- a/google/resource_notebooks_environment_generated_test.go +++ b/google/resource_notebooks_environment_generated_test.go @@ -81,7 +81,13 @@ func testAccCheckNotebooksEnvironmentDestroyProducer(t *testing.T) func(s *terra return err } - _, err = sendRequest(config, "GET", "", url, config.userAgent, nil) + billingProject := "" + + if config.BillingProject != "" { + billingProject = config.BillingProject + } + + _, err = sendRequest(config, "GET", billingProject, url, config.userAgent, nil) if err == nil { return fmt.Errorf("NotebooksEnvironment still exists at %s", url) } diff --git a/google/resource_notebooks_instance_generated_test.go b/google/resource_notebooks_instance_generated_test.go index 95c1c38a5ca..7ad2dc01111 100644 --- a/google/resource_notebooks_instance_generated_test.go +++ b/google/resource_notebooks_instance_generated_test.go @@ -252,7 +252,13 @@ func testAccCheckNotebooksInstanceDestroyProducer(t *testing.T) func(s *terrafor return err } - _, err = sendRequest(config, "GET", "", url, config.userAgent, nil) + billingProject := "" + + if config.BillingProject != "" { + billingProject = config.BillingProject + } + + _, err = sendRequest(config, "GET", billingProject, url, config.userAgent, nil) if err == nil { return fmt.Errorf("NotebooksInstance still exists at %s", url) } diff --git a/google/resource_os_config_patch_deployment_generated_test.go b/google/resource_os_config_patch_deployment_generated_test.go index ccc5f6a1241..a0b804d8eef 100644 --- a/google/resource_os_config_patch_deployment_generated_test.go +++ b/google/resource_os_config_patch_deployment_generated_test.go @@ -313,7 +313,13 @@ func testAccCheckOSConfigPatchDeploymentDestroyProducer(t *testing.T) func(s *te return err } - _, err = sendRequest(config, "GET", "", url, config.userAgent, nil) + billingProject := "" + + if config.BillingProject != "" { + billingProject = config.BillingProject + } + + _, err = sendRequest(config, "GET", billingProject, url, config.userAgent, nil) if err == nil { return fmt.Errorf("OSConfigPatchDeployment still exists at %s", url) } diff --git a/google/resource_os_login_ssh_public_key_generated_test.go b/google/resource_os_login_ssh_public_key_generated_test.go index c882ae67f48..145d7f5a58e 100644 --- a/google/resource_os_login_ssh_public_key_generated_test.go +++ b/google/resource_os_login_ssh_public_key_generated_test.go @@ -80,7 +80,13 @@ func testAccCheckOSLoginSSHPublicKeyDestroyProducer(t *testing.T) func(s *terraf return err } - _, err = sendRequest(config, "GET", "", url, config.userAgent, nil) + billingProject := "" + + if config.BillingProject != "" { + billingProject = config.BillingProject + } + + _, err = sendRequest(config, "GET", billingProject, url, config.userAgent, nil) if err == nil { return fmt.Errorf("OSLoginSSHPublicKey still exists at %s", url) } diff --git a/google/resource_pubsub_lite_subscription_generated_test.go b/google/resource_pubsub_lite_subscription_generated_test.go index 0bb20b68fd0..ac70b0c50ef 100644 --- a/google/resource_pubsub_lite_subscription_generated_test.go +++ b/google/resource_pubsub_lite_subscription_generated_test.go @@ -99,7 +99,13 @@ func testAccCheckPubsubLiteSubscriptionDestroyProducer(t *testing.T) func(s *ter return err } - _, err = sendRequest(config, "GET", "", url, config.userAgent, nil) + billingProject := "" + + if config.BillingProject != "" { + billingProject = config.BillingProject + } + + _, err = sendRequest(config, "GET", billingProject, url, config.userAgent, nil) if err == nil { return fmt.Errorf("PubsubLiteSubscription still exists at %s", url) } diff --git a/google/resource_pubsub_lite_topic_generated_test.go b/google/resource_pubsub_lite_topic_generated_test.go index ddd320e6852..c264f6b9e7b 100644 --- a/google/resource_pubsub_lite_topic_generated_test.go +++ b/google/resource_pubsub_lite_topic_generated_test.go @@ -92,7 +92,13 @@ func testAccCheckPubsubLiteTopicDestroyProducer(t *testing.T) func(s *terraform. return err } - _, err = sendRequest(config, "GET", "", url, config.userAgent, nil) + billingProject := "" + + if config.BillingProject != "" { + billingProject = config.BillingProject + } + + _, err = sendRequest(config, "GET", billingProject, url, config.userAgent, nil) if err == nil { return fmt.Errorf("PubsubLiteTopic still exists at %s", url) } diff --git a/google/resource_pubsub_subscription_generated_test.go b/google/resource_pubsub_subscription_generated_test.go index b402ad48986..652ac997861 100644 --- a/google/resource_pubsub_subscription_generated_test.go +++ b/google/resource_pubsub_subscription_generated_test.go @@ -205,7 +205,13 @@ func testAccCheckPubsubSubscriptionDestroyProducer(t *testing.T) func(s *terrafo return err } - _, err = sendRequest(config, "GET", "", url, config.userAgent, nil) + billingProject := "" + + if config.BillingProject != "" { + billingProject = config.BillingProject + } + + _, err = sendRequest(config, "GET", billingProject, url, config.userAgent, nil) if err == nil { return fmt.Errorf("PubsubSubscription still exists at %s", url) } diff --git a/google/resource_pubsub_topic_generated_test.go b/google/resource_pubsub_topic_generated_test.go index 186dc7a6f47..b559985c16e 100644 --- a/google/resource_pubsub_topic_generated_test.go +++ b/google/resource_pubsub_topic_generated_test.go @@ -120,7 +120,13 @@ func testAccCheckPubsubTopicDestroyProducer(t *testing.T) func(s *terraform.Stat return err } - _, err = sendRequest(config, "GET", "", url, config.userAgent, nil, pubsubTopicProjectNotReady) + billingProject := "" + + if config.BillingProject != "" { + billingProject = config.BillingProject + } + + _, err = sendRequest(config, "GET", billingProject, url, config.userAgent, nil, pubsubTopicProjectNotReady) if err == nil { return fmt.Errorf("PubsubTopic still exists at %s", url) } diff --git a/google/resource_redis_instance_generated_test.go b/google/resource_redis_instance_generated_test.go index 37eaca901f8..855fa2d370e 100644 --- a/google/resource_redis_instance_generated_test.go +++ b/google/resource_redis_instance_generated_test.go @@ -210,7 +210,13 @@ func testAccCheckRedisInstanceDestroyProducer(t *testing.T) func(s *terraform.St return err } - _, err = sendRequest(config, "GET", "", url, config.userAgent, nil) + billingProject := "" + + if config.BillingProject != "" { + billingProject = config.BillingProject + } + + _, err = sendRequest(config, "GET", billingProject, url, config.userAgent, nil) if err == nil { return fmt.Errorf("RedisInstance still exists at %s", url) } diff --git a/google/resource_secret_manager_secret_generated_test.go b/google/resource_secret_manager_secret_generated_test.go index 044049469ba..bcbfa04535c 100644 --- a/google/resource_secret_manager_secret_generated_test.go +++ b/google/resource_secret_manager_secret_generated_test.go @@ -91,7 +91,13 @@ func testAccCheckSecretManagerSecretDestroyProducer(t *testing.T) func(s *terraf return err } - _, err = sendRequest(config, "GET", "", url, config.userAgent, nil) + billingProject := "" + + if config.BillingProject != "" { + billingProject = config.BillingProject + } + + _, err = sendRequest(config, "GET", billingProject, url, config.userAgent, nil) if err == nil { return fmt.Errorf("SecretManagerSecret still exists at %s", url) } diff --git a/google/resource_secret_manager_secret_version_generated_test.go b/google/resource_secret_manager_secret_version_generated_test.go index 87c767cc9f4..3e72e2911f0 100644 --- a/google/resource_secret_manager_secret_version_generated_test.go +++ b/google/resource_secret_manager_secret_version_generated_test.go @@ -91,7 +91,13 @@ func testAccCheckSecretManagerSecretVersionDestroyProducer(t *testing.T) func(s return err } - _, err = sendRequest(config, "GET", "", url, config.userAgent, nil) + billingProject := "" + + if config.BillingProject != "" { + billingProject = config.BillingProject + } + + _, err = sendRequest(config, "GET", billingProject, url, config.userAgent, nil) if err == nil { return fmt.Errorf("SecretManagerSecretVersion still exists at %s", url) } diff --git a/google/resource_source_repo_repository_generated_test.go b/google/resource_source_repo_repository_generated_test.go index 709b2ff3b57..54acf89d77f 100644 --- a/google/resource_source_repo_repository_generated_test.go +++ b/google/resource_source_repo_repository_generated_test.go @@ -124,7 +124,13 @@ func testAccCheckSourceRepoRepositoryDestroyProducer(t *testing.T) func(s *terra return err } - _, err = sendRequest(config, "GET", "", url, config.userAgent, nil) + billingProject := "" + + if config.BillingProject != "" { + billingProject = config.BillingProject + } + + _, err = sendRequest(config, "GET", billingProject, url, config.userAgent, nil) if err == nil { return fmt.Errorf("SourceRepoRepository still exists at %s", url) } diff --git a/google/resource_spanner_database_generated_test.go b/google/resource_spanner_database_generated_test.go index 78265c53b62..0221931cecf 100644 --- a/google/resource_spanner_database_generated_test.go +++ b/google/resource_spanner_database_generated_test.go @@ -88,7 +88,13 @@ func testAccCheckSpannerDatabaseDestroyProducer(t *testing.T) func(s *terraform. return err } - _, err = sendRequest(config, "GET", "", url, config.userAgent, nil) + billingProject := "" + + if config.BillingProject != "" { + billingProject = config.BillingProject + } + + _, err = sendRequest(config, "GET", billingProject, url, config.userAgent, nil) if err == nil { return fmt.Errorf("SpannerDatabase still exists at %s", url) } diff --git a/google/resource_spanner_instance_generated_test.go b/google/resource_spanner_instance_generated_test.go index 42dbbdd0e55..15b934cf3d2 100644 --- a/google/resource_spanner_instance_generated_test.go +++ b/google/resource_spanner_instance_generated_test.go @@ -124,7 +124,13 @@ func testAccCheckSpannerInstanceDestroyProducer(t *testing.T) func(s *terraform. return err } - _, err = sendRequest(config, "GET", "", url, config.userAgent, nil) + billingProject := "" + + if config.BillingProject != "" { + billingProject = config.BillingProject + } + + _, err = sendRequest(config, "GET", billingProject, url, config.userAgent, nil) if err == nil { return fmt.Errorf("SpannerInstance still exists at %s", url) } diff --git a/google/resource_sql_database_generated_test.go b/google/resource_sql_database_generated_test.go index 8b6fc237b45..3d635a8caa2 100644 --- a/google/resource_sql_database_generated_test.go +++ b/google/resource_sql_database_generated_test.go @@ -87,7 +87,13 @@ func testAccCheckSQLDatabaseDestroyProducer(t *testing.T) func(s *terraform.Stat return err } - _, err = sendRequest(config, "GET", "", url, config.userAgent, nil) + billingProject := "" + + if config.BillingProject != "" { + billingProject = config.BillingProject + } + + _, err = sendRequest(config, "GET", billingProject, url, config.userAgent, nil) if err == nil { return fmt.Errorf("SQLDatabase still exists at %s", url) } diff --git a/google/resource_sql_source_representation_instance_generated_test.go b/google/resource_sql_source_representation_instance_generated_test.go index e70417faf73..2918ba393af 100644 --- a/google/resource_sql_source_representation_instance_generated_test.go +++ b/google/resource_sql_source_representation_instance_generated_test.go @@ -79,7 +79,13 @@ func testAccCheckSQLSourceRepresentationInstanceDestroyProducer(t *testing.T) fu return err } - _, err = sendRequest(config, "GET", "", url, config.userAgent, nil) + billingProject := "" + + if config.BillingProject != "" { + billingProject = config.BillingProject + } + + _, err = sendRequest(config, "GET", billingProject, url, config.userAgent, nil) if err == nil { return fmt.Errorf("SQLSourceRepresentationInstance still exists at %s", url) } diff --git a/google/resource_storage_bucket_access_control_generated_test.go b/google/resource_storage_bucket_access_control_generated_test.go index 6d0447784e9..c73b0e5186d 100644 --- a/google/resource_storage_bucket_access_control_generated_test.go +++ b/google/resource_storage_bucket_access_control_generated_test.go @@ -82,7 +82,13 @@ func testAccCheckStorageBucketAccessControlDestroyProducer(t *testing.T) func(s return err } - _, err = sendRequest(config, "GET", "", url, config.userAgent, nil) + billingProject := "" + + if config.BillingProject != "" { + billingProject = config.BillingProject + } + + _, err = sendRequest(config, "GET", billingProject, url, config.userAgent, nil) if err == nil { return fmt.Errorf("StorageBucketAccessControl still exists at %s", url) } diff --git a/google/resource_storage_default_object_access_control_generated_test.go b/google/resource_storage_default_object_access_control_generated_test.go index f165565c14b..bf723eee601 100644 --- a/google/resource_storage_default_object_access_control_generated_test.go +++ b/google/resource_storage_default_object_access_control_generated_test.go @@ -82,7 +82,13 @@ func testAccCheckStorageDefaultObjectAccessControlDestroyProducer(t *testing.T) return err } - _, err = sendRequest(config, "GET", "", url, config.userAgent, nil) + billingProject := "" + + if config.BillingProject != "" { + billingProject = config.BillingProject + } + + _, err = sendRequest(config, "GET", billingProject, url, config.userAgent, nil) if err == nil { return fmt.Errorf("StorageDefaultObjectAccessControl still exists at %s", url) } diff --git a/google/resource_storage_object_access_control_generated_test.go b/google/resource_storage_object_access_control_generated_test.go index c12c3120e13..f433643d62f 100644 --- a/google/resource_storage_object_access_control_generated_test.go +++ b/google/resource_storage_object_access_control_generated_test.go @@ -89,7 +89,13 @@ func testAccCheckStorageObjectAccessControlDestroyProducer(t *testing.T) func(s return err } - _, err = sendRequest(config, "GET", "", url, config.userAgent, nil) + billingProject := "" + + if config.BillingProject != "" { + billingProject = config.BillingProject + } + + _, err = sendRequest(config, "GET", billingProject, url, config.userAgent, nil) if err == nil { return fmt.Errorf("StorageObjectAccessControl still exists at %s", url) } diff --git a/google/resource_tpu_node_generated_test.go b/google/resource_tpu_node_generated_test.go index 4e6a3123e41..d594b88028d 100644 --- a/google/resource_tpu_node_generated_test.go +++ b/google/resource_tpu_node_generated_test.go @@ -160,7 +160,13 @@ func testAccCheckTPUNodeDestroyProducer(t *testing.T) func(s *terraform.State) e return err } - _, err = sendRequest(config, "GET", "", url, config.userAgent, nil) + billingProject := "" + + if config.BillingProject != "" { + billingProject = config.BillingProject + } + + _, err = sendRequest(config, "GET", billingProject, url, config.userAgent, nil) if err == nil { return fmt.Errorf("TPUNode still exists at %s", url) } diff --git a/google/resource_vpc_access_connector_generated_test.go b/google/resource_vpc_access_connector_generated_test.go index e4c25b66ef1..d9b0de5de13 100644 --- a/google/resource_vpc_access_connector_generated_test.go +++ b/google/resource_vpc_access_connector_generated_test.go @@ -79,7 +79,13 @@ func testAccCheckVPCAccessConnectorDestroyProducer(t *testing.T) func(s *terrafo return err } - _, err = sendRequest(config, "GET", "", url, config.userAgent, nil) + billingProject := "" + + if config.BillingProject != "" { + billingProject = config.BillingProject + } + + _, err = sendRequest(config, "GET", billingProject, url, config.userAgent, nil) if err == nil { return fmt.Errorf("VPCAccessConnector still exists at %s", url) } diff --git a/website/docs/r/billing_budget.html.markdown b/website/docs/r/billing_budget.html.markdown index b8d870ab1de..f2f967476a5 100644 --- a/website/docs/r/billing_budget.html.markdown +++ b/website/docs/r/billing_budget.html.markdown @@ -24,15 +24,19 @@ description: |- Budget configuration for a billing account. -~> **Warning:** This resource is in beta, and should be used with the terraform-provider-google-beta provider. -See [Provider Versions](https://terraform.io/docs/providers/google/guides/provider_versions.html) for more details on beta resources. To get more information about Budget, see: -* [API documentation](https://cloud.google.com/billing/docs/reference/budget/rest/v1beta1/billingAccounts.budgets) +* [API documentation](https://cloud.google.com/billing/docs/reference/budget/rest/v1/billingAccounts.budgets) * How-to Guides * [Creating a budget](https://cloud.google.com/billing/docs/how-to/budgets) +~> **Warning:** If you are using User ADCs (Application Default Credentials) with this resource, +you must specify a `billing_project` and set `user_project_override` to true +in the provider configuration. Otherwise the Billing Budgets API will return a 403 error. +Your account must have the `serviceusage.services.use` permission on the +`billing_project` you defined. +