From 18dc5559badb76b3727410445476e13db84f8eb7 Mon Sep 17 00:00:00 2001 From: tombuildsstuff Date: Fri, 7 Apr 2017 11:06:51 +0100 Subject: [PATCH] Import support for Image Lists --- .../providers/opc/import_ip_network_test.go | 33 +++++++++++++++++++ builtin/providers/opc/resource_ip_network.go | 3 ++ .../providers/opc/resource_ip_network_test.go | 30 +++++++++++++++-- 3 files changed, 63 insertions(+), 3 deletions(-) create mode 100644 builtin/providers/opc/import_ip_network_test.go diff --git a/builtin/providers/opc/import_ip_network_test.go b/builtin/providers/opc/import_ip_network_test.go new file mode 100644 index 000000000..6311e98d4 --- /dev/null +++ b/builtin/providers/opc/import_ip_network_test.go @@ -0,0 +1,33 @@ +package opc + +import ( + "testing" + + "github.com/hashicorp/terraform/helper/acctest" + "github.com/hashicorp/terraform/helper/resource" +) + +func TestAccOPCIPNetwork_importBasic(t *testing.T) { + resourceName := "opc_compute_ip_network.test" + + rInt := acctest.RandInt() + config := testAccOPCIPNetworkConfig_Basic(rInt) + + resource.Test(t, resource.TestCase{ + PreCheck: func() { + testAccPreCheck(t) + }, + Providers: testAccProviders, + CheckDestroy: opcResourceCheck(resourceName, testAccOPCCheckIPNetworkDestroyed), + Steps: []resource.TestStep{ + { + Config: config, + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} diff --git a/builtin/providers/opc/resource_ip_network.go b/builtin/providers/opc/resource_ip_network.go index c7281f2fe..ddb0e65c3 100644 --- a/builtin/providers/opc/resource_ip_network.go +++ b/builtin/providers/opc/resource_ip_network.go @@ -13,6 +13,9 @@ func resourceOPCIPNetwork() *schema.Resource { Read: resourceOPCIPNetworkRead, Update: resourceOPCIPNetworkUpdate, Delete: resourceOPCIPNetworkDelete, + Importer: &schema.ResourceImporter{ + State: schema.ImportStatePassthrough, + }, Schema: map[string]*schema.Schema{ "name": { diff --git a/builtin/providers/opc/resource_ip_network_test.go b/builtin/providers/opc/resource_ip_network_test.go index 3f3ffce6e..baf3ed339 100644 --- a/builtin/providers/opc/resource_ip_network_test.go +++ b/builtin/providers/opc/resource_ip_network_test.go @@ -12,7 +12,31 @@ import ( func TestAccOPCIPNetwork_Basic(t *testing.T) { rInt := acctest.RandInt() - resName := "opc_compute_ip_network.foo" + resName := "opc_compute_ip_network.test" + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: opcResourceCheck(resName, testAccOPCCheckIPNetworkDestroyed), + Steps: []resource.TestStep{ + { + Config: testAccOPCIPNetworkConfig_Basic(rInt), + Check: resource.ComposeTestCheckFunc( + opcResourceCheck(resName, testAccOPCCheckIPNetworkExists), + resource.TestCheckResourceAttr(resName, "ip_address_prefix", "10.0.12.0/24"), + resource.TestCheckResourceAttr(resName, "public_napt_enabled", "false"), + resource.TestCheckResourceAttr(resName, "description", fmt.Sprintf("testing-desc-%d", rInt)), + resource.TestCheckResourceAttr(resName, "name", fmt.Sprintf("testing-ip-network-%d", rInt)), + resource.TestMatchResourceAttr(resName, "uri", regexp.MustCompile("testing-ip-network")), + ), + }, + }, + }) +} + +func TestAccOPCIPNetwork_Update(t *testing.T) { + rInt := acctest.RandInt() + resName := "opc_compute_ip_network.test" resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, @@ -46,7 +70,7 @@ func TestAccOPCIPNetwork_Basic(t *testing.T) { func testAccOPCIPNetworkConfig_Basic(rInt int) string { return fmt.Sprintf(` -resource "opc_compute_ip_network" "foo" { +resource "opc_compute_ip_network" "test" { name = "testing-ip-network-%d" description = "testing-desc-%d" ip_address_prefix = "10.0.12.0/24" @@ -55,7 +79,7 @@ resource "opc_compute_ip_network" "foo" { func testAccOPCIPNetworkConfig_BasicUpdate(rInt int) string { return fmt.Sprintf(` -resource "opc_compute_ip_network" "foo" { +resource "opc_compute_ip_network" "test" { name = "testing-ip-network-%d" description = "testing-desc-%d" ip_address_prefix = "10.0.12.0/24"