Skip to content

Commit

Permalink
Merge pull request #8122 from nwwebb/import-forwarding-rule
Browse files Browse the repository at this point in the history
provider/google: Support Import of 'google_compute_forwarding_rule'
  • Loading branch information
lwander authored Aug 11, 2016
2 parents 01fb6c7 + b45650c commit 4d631d5
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
32 changes: 32 additions & 0 deletions builtin/providers/google/import_compute_forwarding_rule_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package google

import (
"fmt"
"testing"

"github.com/hashicorp/terraform/helper/acctest"
"github.com/hashicorp/terraform/helper/resource"
)

func TestAccComputeForwardingRule_importBasic(t *testing.T) {
resourceName := "google_compute_forwarding_rule.foobar"
poolName := fmt.Sprintf("tf-%s", acctest.RandString(10))
ruleName := fmt.Sprintf("tf-%s", acctest.RandString(10))

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckComputeForwardingRuleDestroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: testAccComputeForwardingRule_basic(poolName, ruleName),
},

resource.TestStep{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
},
},
})
}
12 changes: 11 additions & 1 deletion builtin/providers/google/resource_compute_forwarding_rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ func resourceComputeForwardingRule() *schema.Resource {
Read: resourceComputeForwardingRuleRead,
Delete: resourceComputeForwardingRuleDelete,
Update: resourceComputeForwardingRuleUpdate,
Importer: &schema.ResourceImporter{
State: schema.ImportStatePassthrough,
},

Schema: map[string]*schema.Schema{
"name": &schema.Schema{
Expand Down Expand Up @@ -59,12 +62,14 @@ func resourceComputeForwardingRule() *schema.Resource {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
Computed: true,
},

"region": &schema.Schema{
Type: schema.TypeString,
Optional: true,
ForceNew: true,
Computed: true,
},

"self_link": &schema.Schema{
Expand Down Expand Up @@ -179,10 +184,15 @@ func resourceComputeForwardingRuleRead(d *schema.ResourceData, meta interface{})
return fmt.Errorf("Error reading ForwardingRule: %s", err)
}

d.Set("name", frule.Name)
d.Set("target", frule.Target)
d.Set("description", frule.Description)
d.Set("port_range", frule.PortRange)
d.Set("project", project)
d.Set("region", region)
d.Set("ip_address", frule.IPAddress)
d.Set("ip_protocol", frule.IPProtocol)
d.Set("self_link", frule.SelfLink)

return nil
}

Expand Down

0 comments on commit 4d631d5

Please sign in to comment.