provider/google: Support Import of 'google_compute_forwarding_rule'

This commit is contained in:
Noah Webb 2016-08-04 13:12:09 -04:00
parent 3fc119923e
commit b45650c390
2 changed files with 43 additions and 1 deletions

View File

@ -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,
},
},
})
}

View File

@ -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{
@ -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{
@ -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
}