Skip to content

Commit

Permalink
Adding Import Functionality (#35)
Browse files Browse the repository at this point in the history
* adding importer and testing
(cherry picked from commit db9c342)

* complete
(cherry picked from commit 8965802)

* sed needs -e when running on Mac OS X

* govendor remove +v ; govendor add +e
  • Loading branch information
pdxfixit authored Nov 22, 2016
1 parent 59ee261 commit 3c675f2
Show file tree
Hide file tree
Showing 821 changed files with 18,129 additions and 316,574 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ bin: test
go get github.com/mitchellh/gox; \
fi
@cp main.go "$(BIGIP_BIN_PATH)/main.go"
@sed -i'' "s|github.com/DealerDotCom/terraform-provider-bigip|github.com/hashicorp/terraform/builtin/providers|" "$(BIGIP_BIN_PATH)/main.go"
@sed -i'' -e "s|github.com/DealerDotCom/terraform-provider-bigip|github.com/hashicorp/terraform/builtin/providers|" "$(BIGIP_BIN_PATH)/main.go"
@cp -r bigip "$(TF_DIR)/builtin/providers"
@gox -output="$(BIN_DIR)/{{.OS}}_{{.Arch}}/terraform-{{.Dir}}" -arch="$(ARCHS)" -os="$(OS)" "github.com/hashicorp/terraform/builtin/bins/provider-bigip"

Expand Down
9 changes: 8 additions & 1 deletion bigip/resource_bigip_ltm_irule.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ func resourceBigipLtmIRule() *schema.Resource {
Update: resourceBigipLtmIRuleUpdate,
Delete: resourceBigipLtmIRuleDelete,
Exists: resourceBigipLtmIRuleExists,
Importer: &schema.ResourceImporter{
State: resourceBigipLtmIRuleImporter,
},

Schema: map[string]*schema.Schema{
"name": &schema.Schema{
Expand Down Expand Up @@ -60,7 +63,7 @@ func resourceBigipLtmIRuleRead(d *schema.ResourceData, meta interface{}) error {
return err
}
d.Set("irule", irule.Rule)

d.Set("name", name)
return nil
}

Expand Down Expand Up @@ -96,3 +99,7 @@ func resourceBigipLtmIRuleDelete(d *schema.ResourceData, meta interface{}) error
name := d.Id()
return client.DeleteIRule(name)
}

func resourceBigipLtmIRuleImporter(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) {
return []*schema.ResourceData{d}, nil
}
21 changes: 21 additions & 0 deletions bigip/resource_bigip_ltm_irule_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,27 @@ func TestBigipLtmIRule_create(t *testing.T) {
})
}

func TestBigipLtmIRule_import(t *testing.T) {
resource.Test(t, resource.TestCase{
PreCheck: func() {
testAcctPreCheck(t)
},
Providers: testAccProviders,
CheckDestroy: testCheckIRulesDestroyed,
Steps: []resource.TestStep{
resource.TestStep{
Config: TEST_IRULE_RESOURCE,
Check: resource.ComposeTestCheckFunc(
testCheckIRuleExists(TEST_IRULE_NAME),
),
ResourceName: TEST_IRULE_NAME,
ImportState: true,
ImportStateVerify: true,
},
},
})
}

func testCheckIRuleExists(name string) resource.TestCheckFunc {
return func(s *terraform.State) error {
client := testAccProvider.Meta().(*bigip.BigIP)
Expand Down
7 changes: 7 additions & 0 deletions bigip/resource_bigip_ltm_monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ func resourceBigipLtmMonitor() *schema.Resource {
Update: resourceBigipLtmMonitorUpdate,
Delete: resourceBigipLtmMonitorDelete,
Exists: resourceBigipLtmMonitorExists,
Importer: &schema.ResourceImporter{
State: resourceBigipLtmMonitorImporter,
},

Schema: map[string]*schema.Schema{
"name": &schema.Schema{
Expand Down Expand Up @@ -215,3 +218,7 @@ func validateParent(v interface{}, k string) ([]string, []error) {
func monitorParent(s string) string {
return strings.TrimPrefix(s, "/Common/")
}

func resourceBigipLtmMonitorImporter(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) {
return []*schema.ResourceData{d}, nil
}
21 changes: 21 additions & 0 deletions bigip/resource_bigip_ltm_monitor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,27 @@ func TestBigipLtmMonitor_create(t *testing.T) {
})
}

func TestBigipLtmMonitor_import(t *testing.T) {
resource.Test(t, resource.TestCase{
PreCheck: func() {
testAcctPreCheck(t)
},
Providers: testAccProviders,
CheckDestroy: testMonitorsDestroyed,
Steps: []resource.TestStep{
resource.TestStep{
Config: TEST_MONITOR_RESOURCE,
Check: resource.ComposeTestCheckFunc(
testCheckMonitorExists(TEST_MONITOR_NAME),
),
ResourceName: TEST_MONITOR_NAME,
ImportState: true,
ImportStateVerify: true,
},
},
})
}

func testCheckMonitorExists(name string) resource.TestCheckFunc {
return func(s *terraform.State) error {
client := testAccProvider.Meta().(*bigip.BigIP)
Expand Down
8 changes: 8 additions & 0 deletions bigip/resource_bigip_ltm_node.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ func resourceBigipLtmNode() *schema.Resource {
//Update: resourceBigipLtmNodeUpdate,
Delete: resourceBigipLtmNodeDelete,
Exists: resourceBigipLtmNodeExists,
Importer: &schema.ResourceImporter{
State: resourceBigipLtmNodeImporter,
},

Schema: map[string]*schema.Schema{
"name": &schema.Schema{
Expand Down Expand Up @@ -72,6 +75,7 @@ func resourceBigipLtmNodeRead(d *schema.ResourceData, meta interface{}) error {
}

d.Set("address", node.Address)
d.Set("name", name)

return nil
}
Expand Down Expand Up @@ -137,3 +141,7 @@ func resourceBigipLtmNodeDelete(d *schema.ResourceData, meta interface{}) error
}
return err
}

func resourceBigipLtmNodeImporter(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) {
return []*schema.ResourceData{d}, nil
}
21 changes: 21 additions & 0 deletions bigip/resource_bigip_ltm_node_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,27 @@ func TestBigipLtmNode_create(t *testing.T) {
})
}

func TestBigipLtmNode_import(t *testing.T) {
resource.Test(t, resource.TestCase{
PreCheck: func() {
testAcctPreCheck(t)
},
Providers: testAccProviders,
CheckDestroy: testCheckNodesDestroyed,
Steps: []resource.TestStep{
resource.TestStep{
Config: TEST_NODE_RESOURCE,
Check: resource.ComposeTestCheckFunc(
testCheckNodeExists(TEST_NODE_NAME, true),
),
ResourceName: TEST_NODE_NAME,
ImportState: true,
ImportStateVerify: true,
},
},
})
}

//var TEST_NODE_IN_POOL_RESOURCE = `
//resource "bigip_ltm_pool" "test-pool" {
// name = "` + TEST_POOL_NAME + `"
Expand Down
8 changes: 8 additions & 0 deletions bigip/resource_bigip_ltm_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ func resourceBigipLtmPolicy() *schema.Resource {
Update: resourceBigipLtmPolicyUpdate,
Delete: resourceBigipLtmPolicyDelete,
Exists: resourceBigipLtmPolicyExists,
Importer: &schema.ResourceImporter{
State: resourceBigipLtmPolicyImporter,
},

Schema: map[string]*schema.Schema{
"name": &schema.Schema{
Expand Down Expand Up @@ -1071,6 +1074,7 @@ func resourceBigipLtmPolicyRead(d *schema.ResourceData, meta interface{}) error

log.Println("[INFO] Fetching policy " + name)
p, err := client.GetPolicy(name)

if err != nil {
return err
}
Expand Down Expand Up @@ -1175,3 +1179,7 @@ func interfaceToResourceData(obj interface{}, d *schema.ResourceData, prefix str
}
}
}

func resourceBigipLtmPolicyImporter(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) {
return []*schema.ResourceData{d}, nil
}
21 changes: 21 additions & 0 deletions bigip/resource_bigip_ltm_policy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,27 @@ func TestBigipLtmPolicy_create(t *testing.T) {
})
}

func TestBigipLtmPolicy_import(t *testing.T) {
resource.Test(t, resource.TestCase{
PreCheck: func() {
testAcctPreCheck(t)
},
Providers: testAccProviders,
CheckDestroy: testCheckPolicyDestroyed,
Steps: []resource.TestStep{
resource.TestStep{
Config: TEST_POLICY_RESOURCE,
Check: resource.ComposeTestCheckFunc(
testCheckPolicyExists(TEST_POLICY_NAME, true),
),
ResourceName: TEST_POLICY_NAME,
ImportState: true,
ImportStateVerify: true,
},
},
})
}

func testCheckPolicyExists(name string, exists bool) resource.TestCheckFunc {
return func(s *terraform.State) error {
client := testAccProvider.Meta().(*bigip.BigIP)
Expand Down
9 changes: 8 additions & 1 deletion bigip/resource_bigip_ltm_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ func resourceBigipLtmPool() *schema.Resource {
Update: resourceBigipLtmPoolUpdate,
Delete: resourceBigipLtmPoolDelete,
Exists: resourceBigipLtmPoolExists,
Importer: &schema.ResourceImporter{
State: resourceBigIpLtmPoolImporter,
},

Schema: map[string]*schema.Schema{
"name": &schema.Schema{
Expand All @@ -27,7 +30,6 @@ func resourceBigipLtmPool() *schema.Resource {
ForceNew: true,
ValidateFunc: validateF5Name,
},

"nodes": &schema.Schema{
Type: schema.TypeSet,
Elem: &schema.Schema{Type: schema.TypeString},
Expand Down Expand Up @@ -109,6 +111,7 @@ func resourceBigipLtmPoolRead(d *schema.ResourceData, meta interface{}) error {
d.Set("allow_snat", pool.AllowSNAT)
d.Set("load_balancing_mode", pool.LoadBalancingMode)
d.Set("nodes", makeStringSet(&nodes))
d.Set("name", name)

monitors := strings.Split(strings.TrimSpace(pool.Monitor), " and ")
d.Set("monitors", makeStringSet(&monitors))
Expand Down Expand Up @@ -190,3 +193,7 @@ func resourceBigipLtmPoolDelete(d *schema.ResourceData, meta interface{}) error

return client.DeletePool(name)
}

func resourceBigIpLtmPoolImporter(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) {
return []*schema.ResourceData{d}, nil
}
21 changes: 21 additions & 0 deletions bigip/resource_bigip_ltm_pool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,27 @@ func TestBigipLtmPool_create(t *testing.T) {
})
}

func TestBigipLtmPool_import(t *testing.T) {
resource.Test(t, resource.TestCase{
PreCheck: func() {
testAcctPreCheck(t)
},
Providers: testAccProviders,
CheckDestroy: testCheckPoolsDestroyed,
Steps: []resource.TestStep{
resource.TestStep{
Config: TEST_POOL_RESOURCE,
Check: resource.ComposeTestCheckFunc(
testCheckPoolExists(TEST_POOL_NAME, true),
),
ResourceName: TEST_POOL_RESOURCE,
ImportState: true,
ImportStateVerify: true,
},
},
})
}

//TODO: test adding/removing nodes

func testCheckPoolExists(name string, exists bool) resource.TestCheckFunc {
Expand Down
7 changes: 7 additions & 0 deletions bigip/resource_bigip_ltm_virtual_address.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ func resourceBigipLtmVirtualAddress() *schema.Resource {
Update: resourceBigipLtmVirtualAddressUpdate,
Delete: resourceBigipLtmVirtualAddressDelete,
Exists: resourceBigipLtmVirtualAddressExists,
Importer: &schema.ResourceImporter{
State: resourceBigipLtmVirtualAddressImporter,
},

Schema: map[string]*schema.Schema{
"name": &schema.Schema{
Expand Down Expand Up @@ -181,3 +184,7 @@ func resourceBigipLtmVirtualAddressDelete(d *schema.ResourceData, meta interface
client := meta.(*bigip.BigIP)
return client.DeleteVirtualAddress(name)
}

func resourceBigipLtmVirtualAddressImporter(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) {
return []*schema.ResourceData{d}, nil
}
21 changes: 21 additions & 0 deletions bigip/resource_bigip_ltm_virtual_address_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,27 @@ func TestBigipLtmVA_create(t *testing.T) {
})
}

func TestBigipLtmVA_import(t *testing.T) {
resource.Test(t, resource.TestCase{
PreCheck: func() {
testAcctPreCheck(t)
},
Providers: testAccProviders,
CheckDestroy: testCheckVAsDestroyed,
Steps: []resource.TestStep{
resource.TestStep{
Config: TEST_VA_RESOURCE,
Check: resource.ComposeTestCheckFunc(
testCheckVAExists(TEST_VA_NAME, true),
),
ResourceName: TEST_VA_NAME,
ImportState: true,
ImportStateVerify: true,
},
},
})
}

func testCheckVAExists(name string, exists bool) resource.TestCheckFunc {
return func(s *terraform.State) error {
client := testAccProvider.Meta().(*bigip.BigIP)
Expand Down
7 changes: 7 additions & 0 deletions bigip/resource_bigip_ltm_virtual_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ func resourceBigipLtmVirtualServer() *schema.Resource {
Update: resourceBigipLtmVirtualServerUpdate,
Delete: resourceBigipLtmVirtualServerDelete,
Exists: resourceBigipLtmVirtualServerExists,
Importer: &schema.ResourceImporter{
State: resourceBigipLtmVirtualServerImporter,
},

Schema: map[string]*schema.Schema{
"name": &schema.Schema{
Expand Down Expand Up @@ -301,3 +304,7 @@ func resourceBigipLtmVirtualServerDelete(d *schema.ResourceData, meta interface{

return client.DeleteVirtualServer(name)
}

func resourceBigipLtmVirtualServerImporter(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) {
return []*schema.ResourceData{d}, nil
}
21 changes: 21 additions & 0 deletions bigip/resource_bigip_ltm_virtual_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,27 @@ func TestBigipLtmVS_create(t *testing.T) {
})
}

func TestBigipLtmVS_import(t *testing.T) {
resource.Test(t, resource.TestCase{
PreCheck: func() {
testAcctPreCheck(t)
},
Providers: testAccProviders,
CheckDestroy: testCheckVSsDestroyed,
Steps: []resource.TestStep{
resource.TestStep{
Config: TEST_VS_RESOURCE,
Check: resource.ComposeTestCheckFunc(
testCheckVSExists(TEST_VS_NAME, true),
),
ResourceName: TEST_VS_NAME,
ImportState: true,
ImportStateVerify: true,
},
},
})
}

//TODO: test adding rules, profiles, policies, etc

func testCheckVSExists(name string, exists bool) resource.TestCheckFunc {
Expand Down
20 changes: 0 additions & 20 deletions vendor/github.com/armon/go-radix/LICENSE

This file was deleted.

Loading

0 comments on commit 3c675f2

Please sign in to comment.