@@ -5,6 +5,7 @@ package catalogmanagement_test
55
66import (
77 "fmt"
8+ "regexp"
89 "testing"
910
1011 "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest"
@@ -62,11 +63,55 @@ func testAccCheckIBMCmObjectConfig(name string, parentID string, label string, s
6263 short_description = "%s"
6364 kind = "%s"
6465 tags = ["test1", "test2"]
65- data = jsonencode(local.catalog_object_data)
6666 }
6767 ` , kind , name , parentID , label , shortDescription , kind )
6868}
6969
70+ func TestAccIBMCmObjectImport (t * testing.T ) {
71+ var conf catalogmanagementv1.CatalogObject
72+ name := fmt .Sprintf ("tf_name_%d" , acctest .RandIntRange (10 , 100 ))
73+ parentID := "us-south"
74+ label := fmt .Sprintf ("tf_label_%d" , acctest .RandIntRange (10 , 100 ))
75+ shortDescription := fmt .Sprintf ("tf_short_description_%d" , acctest .RandIntRange (10 , 100 ))
76+ kind := "vpe"
77+
78+ badID := "this-id-does-not-exist-12345"
79+
80+ resource .Test (t , resource.TestCase {
81+ PreCheck : func () { acc .TestAccPreCheck (t ) },
82+ Providers : acc .TestAccProviders ,
83+ CheckDestroy : testAccCheckIBMCmObjectDestroy ,
84+ Steps : []resource.TestStep {
85+ {
86+ Config : testAccCheckIBMCmObjectConfig (name , parentID , label , shortDescription , kind ),
87+ Check : resource .ComposeAggregateTestCheckFunc (
88+ testAccCheckIBMCmObjectExists ("ibm_cm_object.cm_object" , conf ),
89+ resource .TestCheckResourceAttr ("ibm_cm_object.cm_object" , "name" , name ),
90+ resource .TestCheckResourceAttr ("ibm_cm_object.cm_object" , "parent_id" , parentID ),
91+ resource .TestCheckResourceAttr ("ibm_cm_object.cm_object" , "label" , label ),
92+ resource .TestCheckResourceAttr ("ibm_cm_object.cm_object" , "short_description" , shortDescription ),
93+ resource .TestCheckResourceAttr ("ibm_cm_object.cm_object" , "kind" , kind ),
94+ ),
95+ },
96+
97+ {
98+ ResourceName : "ibm_cm_object.cm_object" ,
99+ ImportState : true ,
100+ ImportStateId : badID ,
101+ ExpectError : regexp .MustCompile (
102+ `ibm_cm_object with id "` + badID + `" not found in any catalog` ,
103+ ),
104+ },
105+
106+ {
107+ ResourceName : "ibm_cm_object.cm_object" ,
108+ ImportState : true ,
109+ ImportStateVerify : true ,
110+ },
111+ },
112+ })
113+ }
114+
70115func testAccCheckIBMCmObjectExists (n string , obj catalogmanagementv1.CatalogObject ) resource.TestCheckFunc {
71116
72117 return func (s * terraform.State ) error {
0 commit comments