Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Add long form project property #14996

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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changelog/8200.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
```release-note:bug
compute: fixed an issue with setting project field to long form in `google_compute_forwarding_rule` and `google_compute_global_forwarding_rule`
```
```release-note:bug
gkehub: fixed an issue with setting project field to long form in `google_gke_hub_feature`
```
9 changes: 5 additions & 4 deletions google/resource_gke_hub_feature_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,9 +178,10 @@ func TestAccGKEHubFeature_gkehubFeatureMcsd(t *testing.T) {
Config: testAccGKEHubFeature_gkehubFeatureMcsd(context),
},
{
ResourceName: "google_gke_hub_feature.feature",
ImportState: true,
ImportStateVerify: true,
ResourceName: "google_gke_hub_feature.feature",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"project"},
},
{
Config: testAccGKEHubFeature_gkehubFeatureMcsdUpdate(context),
Expand All @@ -199,7 +200,7 @@ func testAccGKEHubFeature_gkehubFeatureMcsd(context map[string]interface{}) stri
resource "google_gke_hub_feature" "feature" {
name = "multiclusterservicediscovery"
location = "global"
project = google_project.project.project_id
project = "projects/${google_project.project.project_id}"
labels = {
foo = "bar"
}
Expand Down
16 changes: 12 additions & 4 deletions google/services/compute/resource_compute_forwarding_rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -601,6 +601,7 @@ func resourceComputeForwardingRuleCreate(d *schema.ResourceData, meta interface{
if err != nil {
return err
}
url = strings.ReplaceAll(url, "projects/projects/", "projects/")

log.Printf("[DEBUG] Creating new ForwardingRule: %#v", obj)
billingProject := ""
Expand All @@ -609,7 +610,7 @@ func resourceComputeForwardingRuleCreate(d *schema.ResourceData, meta interface{
if err != nil {
return fmt.Errorf("Error fetching project for ForwardingRule: %s", err)
}
billingProject = project
billingProject = strings.TrimPrefix(project, "projects/")

// err == nil indicates that the billing_project value was found
if bp, err := tpgresource.GetBillingProject(d, config); err == nil {
Expand All @@ -634,6 +635,7 @@ func resourceComputeForwardingRuleCreate(d *schema.ResourceData, meta interface{
if err != nil {
return fmt.Errorf("Error constructing id: %s", err)
}
id = strings.ReplaceAll(id, "projects/projects/", "projects/")
d.SetId(id)

err = ComputeOperationWaitTime(
Expand Down Expand Up @@ -705,14 +707,15 @@ func resourceComputeForwardingRuleRead(d *schema.ResourceData, meta interface{})
if err != nil {
return err
}
url = strings.ReplaceAll(url, "projects/projects/", "projects/")

billingProject := ""

project, err := tpgresource.GetProject(d, config)
if err != nil {
return fmt.Errorf("Error fetching project for ForwardingRule: %s", err)
}
billingProject = project
billingProject = strings.TrimPrefix(project, "projects/")

// err == nil indicates that the billing_project value was found
if bp, err := tpgresource.GetBillingProject(d, config); err == nil {
Expand Down Expand Up @@ -835,7 +838,7 @@ func resourceComputeForwardingRuleUpdate(d *schema.ResourceData, meta interface{
if err != nil {
return fmt.Errorf("Error fetching project for ForwardingRule: %s", err)
}
billingProject = project
billingProject = strings.TrimPrefix(project, "projects/")

d.Partial(true)

Expand All @@ -853,6 +856,7 @@ func resourceComputeForwardingRuleUpdate(d *schema.ResourceData, meta interface{
if err != nil {
return err
}
url = strings.ReplaceAll(url, "projects/projects/", "projects/")

// err == nil indicates that the billing_project value was found
if bp, err := tpgresource.GetBillingProject(d, config); err == nil {
Expand Down Expand Up @@ -895,6 +899,7 @@ func resourceComputeForwardingRuleUpdate(d *schema.ResourceData, meta interface{
if err != nil {
return err
}
url = strings.ReplaceAll(url, "projects/projects/", "projects/")

// err == nil indicates that the billing_project value was found
if bp, err := tpgresource.GetBillingProject(d, config); err == nil {
Expand Down Expand Up @@ -943,6 +948,7 @@ func resourceComputeForwardingRuleUpdate(d *schema.ResourceData, meta interface{
if err != nil {
return err
}
url = strings.ReplaceAll(url, "projects/projects/", "projects/")

// err == nil indicates that the billing_project value was found
if bp, err := tpgresource.GetBillingProject(d, config); err == nil {
Expand Down Expand Up @@ -990,12 +996,13 @@ func resourceComputeForwardingRuleDelete(d *schema.ResourceData, meta interface{
if err != nil {
return fmt.Errorf("Error fetching project for ForwardingRule: %s", err)
}
billingProject = project
billingProject = strings.TrimPrefix(project, "projects/")

url, err := tpgresource.ReplaceVars(d, config, "{{ComputeBasePath}}projects/{{project}}/regions/{{region}}/forwardingRules/{{name}}")
if err != nil {
return err
}
url = strings.ReplaceAll(url, "projects/projects/", "projects/")

var obj map[string]interface{}
log.Printf("[DEBUG] Deleting ForwardingRule %q", d.Id())
Expand Down Expand Up @@ -1046,6 +1053,7 @@ func resourceComputeForwardingRuleImport(d *schema.ResourceData, meta interface{
if err != nil {
return nil, fmt.Errorf("Error constructing id: %s", err)
}
id = strings.ReplaceAll(id, "projects/projects/", "projects/")
d.SetId(id)

return []*schema.ResourceData{d}, nil
Expand Down
16 changes: 12 additions & 4 deletions google/services/compute/resource_compute_global_forwarding_rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"fmt"
"log"
"reflect"
"strings"
"time"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
Expand Down Expand Up @@ -425,6 +426,7 @@ func resourceComputeGlobalForwardingRuleCreate(d *schema.ResourceData, meta inte
if err != nil {
return err
}
url = strings.ReplaceAll(url, "projects/projects/", "projects/")

log.Printf("[DEBUG] Creating new GlobalForwardingRule: %#v", obj)
billingProject := ""
Expand All @@ -433,7 +435,7 @@ func resourceComputeGlobalForwardingRuleCreate(d *schema.ResourceData, meta inte
if err != nil {
return fmt.Errorf("Error fetching project for GlobalForwardingRule: %s", err)
}
billingProject = project
billingProject = strings.TrimPrefix(project, "projects/")

// err == nil indicates that the billing_project value was found
if bp, err := tpgresource.GetBillingProject(d, config); err == nil {
Expand All @@ -458,6 +460,7 @@ func resourceComputeGlobalForwardingRuleCreate(d *schema.ResourceData, meta inte
if err != nil {
return fmt.Errorf("Error constructing id: %s", err)
}
id = strings.ReplaceAll(id, "projects/projects/", "projects/")
d.SetId(id)

err = ComputeOperationWaitTime(
Expand Down Expand Up @@ -529,14 +532,15 @@ func resourceComputeGlobalForwardingRuleRead(d *schema.ResourceData, meta interf
if err != nil {
return err
}
url = strings.ReplaceAll(url, "projects/projects/", "projects/")

billingProject := ""

project, err := tpgresource.GetProject(d, config)
if err != nil {
return fmt.Errorf("Error fetching project for GlobalForwardingRule: %s", err)
}
billingProject = project
billingProject = strings.TrimPrefix(project, "projects/")

// err == nil indicates that the billing_project value was found
if bp, err := tpgresource.GetBillingProject(d, config); err == nil {
Expand Down Expand Up @@ -626,7 +630,7 @@ func resourceComputeGlobalForwardingRuleUpdate(d *schema.ResourceData, meta inte
if err != nil {
return fmt.Errorf("Error fetching project for GlobalForwardingRule: %s", err)
}
billingProject = project
billingProject = strings.TrimPrefix(project, "projects/")

d.Partial(true)

Expand All @@ -650,6 +654,7 @@ func resourceComputeGlobalForwardingRuleUpdate(d *schema.ResourceData, meta inte
if err != nil {
return err
}
url = strings.ReplaceAll(url, "projects/projects/", "projects/")

// err == nil indicates that the billing_project value was found
if bp, err := tpgresource.GetBillingProject(d, config); err == nil {
Expand Down Expand Up @@ -692,6 +697,7 @@ func resourceComputeGlobalForwardingRuleUpdate(d *schema.ResourceData, meta inte
if err != nil {
return err
}
url = strings.ReplaceAll(url, "projects/projects/", "projects/")

// err == nil indicates that the billing_project value was found
if bp, err := tpgresource.GetBillingProject(d, config); err == nil {
Expand Down Expand Up @@ -739,12 +745,13 @@ func resourceComputeGlobalForwardingRuleDelete(d *schema.ResourceData, meta inte
if err != nil {
return fmt.Errorf("Error fetching project for GlobalForwardingRule: %s", err)
}
billingProject = project
billingProject = strings.TrimPrefix(project, "projects/")

url, err := tpgresource.ReplaceVars(d, config, "{{ComputeBasePath}}projects/{{project}}/global/forwardingRules/{{name}}")
if err != nil {
return err
}
url = strings.ReplaceAll(url, "projects/projects/", "projects/")

var obj map[string]interface{}
log.Printf("[DEBUG] Deleting GlobalForwardingRule %q", d.Id())
Expand Down Expand Up @@ -794,6 +801,7 @@ func resourceComputeGlobalForwardingRuleImport(d *schema.ResourceData, meta inte
if err != nil {
return nil, fmt.Errorf("Error constructing id: %s", err)
}
id = strings.ReplaceAll(id, "projects/projects/", "projects/")
d.SetId(id)

return []*schema.ResourceData{d}, nil
Expand Down
15 changes: 11 additions & 4 deletions google/services/gkehub2/resource_gke_hub_feature.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ func resourceGKEHub2FeatureCreate(d *schema.ResourceData, meta interface{}) erro
if err != nil {
return err
}
url = strings.ReplaceAll(url, "projects/projects/", "projects/")

log.Printf("[DEBUG] Creating new Feature: %#v", obj)
billingProject := ""
Expand All @@ -203,7 +204,7 @@ func resourceGKEHub2FeatureCreate(d *schema.ResourceData, meta interface{}) erro
if err != nil {
return fmt.Errorf("Error fetching project for Feature: %s", err)
}
billingProject = project
billingProject = strings.TrimPrefix(project, "projects/")

// err == nil indicates that the billing_project value was found
if bp, err := tpgresource.GetBillingProject(d, config); err == nil {
Expand All @@ -228,6 +229,7 @@ func resourceGKEHub2FeatureCreate(d *schema.ResourceData, meta interface{}) erro
if err != nil {
return fmt.Errorf("Error constructing id: %s", err)
}
id = strings.ReplaceAll(id, "projects/projects/", "projects/")
d.SetId(id)

// Use the resource in the operation response to populate
Expand All @@ -248,6 +250,7 @@ func resourceGKEHub2FeatureCreate(d *schema.ResourceData, meta interface{}) erro
if err != nil {
return fmt.Errorf("Error constructing id: %s", err)
}
id = strings.ReplaceAll(id, "projects/projects/", "projects/")
d.SetId(id)

log.Printf("[DEBUG] Finished creating Feature %q: %#v", d.Id(), res)
Expand All @@ -266,14 +269,15 @@ func resourceGKEHub2FeatureRead(d *schema.ResourceData, meta interface{}) error
if err != nil {
return err
}
url = strings.ReplaceAll(url, "projects/projects/", "projects/")

billingProject := ""

project, err := tpgresource.GetProject(d, config)
if err != nil {
return fmt.Errorf("Error fetching project for Feature: %s", err)
}
billingProject = project
billingProject = strings.TrimPrefix(project, "projects/")

// err == nil indicates that the billing_project value was found
if bp, err := tpgresource.GetBillingProject(d, config); err == nil {
Expand Down Expand Up @@ -333,7 +337,7 @@ func resourceGKEHub2FeatureUpdate(d *schema.ResourceData, meta interface{}) erro
if err != nil {
return fmt.Errorf("Error fetching project for Feature: %s", err)
}
billingProject = project
billingProject = strings.TrimPrefix(project, "projects/")

obj := make(map[string]interface{})
labelsProp, err := expandGKEHub2FeatureLabels(d.Get("labels"), d, config)
Expand All @@ -353,6 +357,7 @@ func resourceGKEHub2FeatureUpdate(d *schema.ResourceData, meta interface{}) erro
if err != nil {
return err
}
url = strings.ReplaceAll(url, "projects/projects/", "projects/")

log.Printf("[DEBUG] Updating Feature %q: %#v", d.Id(), obj)
updateMask := []string{}
Expand Down Expand Up @@ -416,12 +421,13 @@ func resourceGKEHub2FeatureDelete(d *schema.ResourceData, meta interface{}) erro
if err != nil {
return fmt.Errorf("Error fetching project for Feature: %s", err)
}
billingProject = project
billingProject = strings.TrimPrefix(project, "projects/")

url, err := tpgresource.ReplaceVars(d, config, "{{GKEHub2BasePath}}projects/{{project}}/locations/{{location}}/features/{{name}}")
if err != nil {
return err
}
url = strings.ReplaceAll(url, "projects/projects/", "projects/")

var obj map[string]interface{}
log.Printf("[DEBUG] Deleting Feature %q", d.Id())
Expand Down Expand Up @@ -471,6 +477,7 @@ func resourceGKEHub2FeatureImport(d *schema.ResourceData, meta interface{}) ([]*
if err != nil {
return nil, fmt.Errorf("Error constructing id: %s", err)
}
id = strings.ReplaceAll(id, "projects/projects/", "projects/")
d.SetId(id)

return []*schema.ResourceData{d}, nil
Expand Down