Skip to content

Commit

Permalink
Remove google_compute_global_forwarding_rule.labels (#2399)
Browse files Browse the repository at this point in the history
<!-- This change is generated by MagicModules. -->
/cc @rileykarson
  • Loading branch information
modular-magician authored and nat-henderson committed Dec 21, 2018
1 parent 187a1bd commit 9b7c346
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 256 deletions.
71 changes: 8 additions & 63 deletions google/resource_compute_global_forwarding_rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,15 @@ func resourceComputeGlobalForwardingRule() *schema.Resource {
},

"labels": &schema.Schema{
Deprecated: "This field is in beta and will be removed from this provider. Use it in the the google-beta provider instead. See https://terraform.io/docs/providers/google/provider_versions.html for more details.",
Type: schema.TypeMap,
Optional: true,
Elem: &schema.Schema{Type: schema.TypeString},
Set: schema.HashString,
Removed: "This field is in beta. Use it in the the google-beta provider instead. See https://terraform.io/docs/providers/google/provider_versions.html for more details.",
Type: schema.TypeMap,
Optional: true,
Elem: &schema.Schema{Type: schema.TypeString},
Set: schema.HashString,
},

"label_fingerprint": &schema.Schema{
Removed: "This field is in beta. Use it in the the google-beta provider instead. See https://terraform.io/docs/providers/google/provider_versions.html for more details.",
Type: schema.TypeString,
Computed: true,
},
Expand Down Expand Up @@ -135,21 +136,6 @@ func resourceComputeGlobalForwardingRuleCreate(d *schema.ResourceData, meta inte
return err
}

// If we have labels to set, try to set those too
if _, ok := d.GetOk("labels"); ok {
labels := expandLabels(d)
// Do a read to get the fingerprint value so we can update
fingerprint, err := resourceComputeGlobalForwardingRuleReadLabelFingerprint(config, project, frule.Name)
if err != nil {
return err
}

err = resourceComputeGlobalForwardingRuleSetLabels(config, project, frule.Name, labels, fingerprint)
if err != nil {
return err
}
}

return resourceComputeGlobalForwardingRuleRead(d, meta)
}

Expand Down Expand Up @@ -180,17 +166,6 @@ func resourceComputeGlobalForwardingRuleUpdate(d *schema.ResourceData, meta inte

d.SetPartial("target")
}
if d.HasChange("labels") {
labels := expandLabels(d)
fingerprint := d.Get("label_fingerprint").(string)

err = resourceComputeGlobalForwardingRuleSetLabels(config, project, d.Get("name").(string), labels, fingerprint)
if err != nil {
return err
}

d.SetPartial("labels")
}

d.Partial(false)

Expand Down Expand Up @@ -218,8 +193,8 @@ func resourceComputeGlobalForwardingRuleRead(d *schema.ResourceData, meta interf
d.Set("ip_protocol", frule.IPProtocol)
d.Set("ip_version", frule.IpVersion)
d.Set("self_link", ConvertSelfLinkToV1(frule.SelfLink))
d.Set("labels", frule.Labels)
d.Set("label_fingerprint", frule.LabelFingerprint)
// removed lists need something set
d.Set("labels", nil)
d.Set("project", project)

return nil
Expand Down Expand Up @@ -247,33 +222,3 @@ func resourceComputeGlobalForwardingRuleDelete(d *schema.ResourceData, meta inte
d.SetId("")
return nil
}

// resourceComputeGlobalForwardingRuleReadLabelFingerprint performs a read on the remote resource and returns only the
// fingerprint. Used on create when setting labels as we don't know the label fingerprint initially.
func resourceComputeGlobalForwardingRuleReadLabelFingerprint(config *Config, project, name string) (string, error) {
frule, err := config.clientComputeBeta.GlobalForwardingRules.Get(project, name).Do()
if err != nil {
return "", fmt.Errorf("Unable to read global forwarding rule to update labels: %s", err)
}

return frule.LabelFingerprint, nil
}

// resourceComputeGlobalForwardingRuleSetLabels sets the Labels attribute on a forwarding rule.
func resourceComputeGlobalForwardingRuleSetLabels(config *Config, project, name string, labels map[string]string, fingerprint string) error {
setLabels := computeBeta.GlobalSetLabelsRequest{
Labels: labels,
LabelFingerprint: fingerprint,
}
op, err := config.clientComputeBeta.GlobalForwardingRules.SetLabels(project, name, &setLabels).Do()
if err != nil {
return err
}

err = computeSharedOperationWait(config.clientCompute, op, project, "Setting labels on Global Forwarding Rule")
if err != nil {
return err
}

return nil
}
193 changes: 0 additions & 193 deletions google/resource_compute_global_forwarding_rule_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,47 +113,6 @@ func TestAccComputeGlobalForwardingRule_ipv6(t *testing.T) {
})
}

func TestAccComputeGlobalForwardingRule_labels(t *testing.T) {
t.Parallel()

var frule computeBeta.ForwardingRule

fr := fmt.Sprintf("forwardrule-test-%s", acctest.RandString(10))
proxy1 := fmt.Sprintf("forwardrule-test-%s", acctest.RandString(10))
proxy2 := fmt.Sprintf("forwardrule-test-%s", acctest.RandString(10))
backend := fmt.Sprintf("forwardrule-test-%s", acctest.RandString(10))
hc := fmt.Sprintf("forwardrule-test-%s", acctest.RandString(10))
urlmap := fmt.Sprintf("forwardrule-test-%s", acctest.RandString(10))

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckComputeGlobalForwardingRuleDestroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: testAccComputeGlobalForwardingRule_labels(fr, proxy1, proxy2, backend, hc, urlmap),
Check: resource.ComposeTestCheckFunc(
testAccCheckComputeBetaGlobalForwardingRuleExists(
"google_compute_global_forwarding_rule.foobar", &frule),
testAccCheckComputeBetaGlobalForwardingRuleHasLabel(&frule, "my-label", "my-label-value"),
testAccCheckComputeBetaGlobalForwardingRuleHasLabel(&frule, "my-second-label", "my-second-label-value"),
testAccCheckComputeBetaGlobalForwardingRuleHasCorrectLabelFingerprint(&frule, "google_compute_global_forwarding_rule.foobar"),
),
},
resource.TestStep{
Config: testAccComputeGlobalForwardingRule_labelsUpdated(fr, proxy1, proxy2, backend, hc, urlmap),
Check: resource.ComposeTestCheckFunc(
testAccCheckComputeBetaGlobalForwardingRuleExists(
"google_compute_global_forwarding_rule.foobar", &frule),
testAccCheckComputeBetaGlobalForwardingRuleHasLabel(&frule, "my-label", "my-label-value"),
testAccCheckComputeBetaGlobalForwardingRuleHasLabel(&frule, "my-third-label", "my-third-label-value"),
testAccCheckComputeBetaGlobalForwardingRuleHasCorrectLabelFingerprint(&frule, "google_compute_global_forwarding_rule.foobar"),
),
},
},
})
}

func testAccCheckComputeGlobalForwardingRuleDestroy(s *terraform.State) error {
config := testAccProvider.Meta().(*Config)

Expand Down Expand Up @@ -254,34 +213,6 @@ func testAccCheckComputeBetaGlobalForwardingRuleIpVersion(n, version string) res
}
}

func testAccCheckComputeBetaGlobalForwardingRuleHasLabel(frule *computeBeta.ForwardingRule, key, value string) resource.TestCheckFunc {
return func(s *terraform.State) error {
val, ok := frule.Labels[key]
if !ok {
return fmt.Errorf("label with key %s not found", key)
}

if val != value {
return fmt.Errorf("label value did not match for key %s: expected %s but found %s", key, value, val)
}
return nil
}
}

func testAccCheckComputeBetaGlobalForwardingRuleHasCorrectLabelFingerprint(
frule *computeBeta.ForwardingRule, resourceName string) resource.TestCheckFunc {
return func(s *terraform.State) error {
tfLabelFingerprint := s.RootModule().Resources[resourceName].Primary.Attributes["label_fingerprint"]
remoteLabelFingerprint := frule.LabelFingerprint

if tfLabelFingerprint != remoteLabelFingerprint {
return fmt.Errorf("Label fingerprint mismatch: remote has %#v but terraform has %#v",
remoteLabelFingerprint, tfLabelFingerprint)
}
return nil
}
}

func testAccComputeGlobalForwardingRule_basic1(fr, proxy1, proxy2, backend, hc, urlmap string) string {
return fmt.Sprintf(`
resource "google_compute_global_forwarding_rule" "foobar" {
Expand Down Expand Up @@ -339,130 +270,6 @@ func testAccComputeGlobalForwardingRule_basic1(fr, proxy1, proxy2, backend, hc,
}`, fr, proxy1, proxy2, backend, hc, urlmap)
}

func testAccComputeGlobalForwardingRule_labels(fr, proxy1, proxy2, backend, hc, urlmap string) string {
return fmt.Sprintf(`
resource "google_compute_global_forwarding_rule" "foobar" {
description = "Resource created for Terraform acceptance testing"
ip_protocol = "TCP"
name = "%s"
port_range = "80"
target = "${google_compute_target_http_proxy.foobar1.self_link}"
labels {
my-label = "my-label-value"
my-second-label = "my-second-label-value"
}
}
resource "google_compute_target_http_proxy" "foobar1" {
description = "Resource created for Terraform acceptance testing"
name = "%s"
url_map = "${google_compute_url_map.foobar.self_link}"
}
resource "google_compute_target_http_proxy" "foobar2" {
description = "Resource created for Terraform acceptance testing"
name = "%s"
url_map = "${google_compute_url_map.foobar.self_link}"
}
resource "google_compute_backend_service" "foobar" {
name = "%s"
health_checks = ["${google_compute_http_health_check.zero.self_link}"]
}
resource "google_compute_http_health_check" "zero" {
name = "%s"
request_path = "/"
check_interval_sec = 1
timeout_sec = 1
}
resource "google_compute_url_map" "foobar" {
name = "%s"
default_service = "${google_compute_backend_service.foobar.self_link}"
host_rule {
hosts = ["mysite.com", "myothersite.com"]
path_matcher = "boop"
}
path_matcher {
default_service = "${google_compute_backend_service.foobar.self_link}"
name = "boop"
path_rule {
paths = ["/*"]
service = "${google_compute_backend_service.foobar.self_link}"
}
}
test {
host = "mysite.com"
path = "/*"
service = "${google_compute_backend_service.foobar.self_link}"
}
}`, fr, proxy1, proxy2, backend, hc, urlmap)
}

func testAccComputeGlobalForwardingRule_labelsUpdated(fr, proxy1, proxy2, backend, hc, urlmap string) string {
return fmt.Sprintf(`
resource "google_compute_global_forwarding_rule" "foobar" {
description = "Resource created for Terraform acceptance testing"
ip_protocol = "TCP"
name = "%s"
port_range = "80"
target = "${google_compute_target_http_proxy.foobar1.self_link}"
labels {
my-label = "my-label-value"
my-third-label = "my-third-label-value"
}
}
resource "google_compute_target_http_proxy" "foobar1" {
description = "Resource created for Terraform acceptance testing"
name = "%s"
url_map = "${google_compute_url_map.foobar.self_link}"
}
resource "google_compute_target_http_proxy" "foobar2" {
description = "Resource created for Terraform acceptance testing"
name = "%s"
url_map = "${google_compute_url_map.foobar.self_link}"
}
resource "google_compute_backend_service" "foobar" {
name = "%s"
health_checks = ["${google_compute_http_health_check.zero.self_link}"]
}
resource "google_compute_http_health_check" "zero" {
name = "%s"
request_path = "/"
check_interval_sec = 1
timeout_sec = 1
}
resource "google_compute_url_map" "foobar" {
name = "%s"
default_service = "${google_compute_backend_service.foobar.self_link}"
host_rule {
hosts = ["mysite.com", "myothersite.com"]
path_matcher = "boop"
}
path_matcher {
default_service = "${google_compute_backend_service.foobar.self_link}"
name = "boop"
path_rule {
paths = ["/*"]
service = "${google_compute_backend_service.foobar.self_link}"
}
}
test {
host = "mysite.com"
path = "/*"
service = "${google_compute_backend_service.foobar.self_link}"
}
}`, fr, proxy1, proxy2, backend, hc, urlmap)
}

func testAccComputeGlobalForwardingRule_basic2(fr, proxy1, proxy2, backend, hc, urlmap string) string {
return fmt.Sprintf(`
resource "google_compute_global_forwarding_rule" "foobar" {
Expand Down

0 comments on commit 9b7c346

Please sign in to comment.