@@ -11,9 +11,12 @@ import (
1111)
1212
1313var (
14- KeyResourceConfig = KeyResourceDependencies +
14+ KeyRequiredOnlyResource = KeyResourceDependencies +
1515 generateResourceFromRepresentationMap ("oci_kms_key" , "test_key" , Required , Create , keyRepresentation )
1616
17+ KeyResourceConfig = KeyResourceDependencies +
18+ generateResourceFromRepresentationMap ("oci_kms_key" , "test_key" , Optional , Update , keyRepresentation )
19+
1720 keySingularDataSourceRepresentation = map [string ]interface {}{
1821 "key_id" : Representation {repType : Required , create : `${oci_kms_key.test_key.id}` },
1922 "management_endpoint" : Representation {repType : Required , create : `${data.oci_kms_vault.test_vault.management_endpoint}` },
3437 "key_shape" : RepresentationGroup {Required , keyKeyShapeRepresentation },
3538 "management_endpoint" : Representation {repType : Required , create : `${data.oci_kms_vault.test_vault.management_endpoint}` },
3639 "desired_state" : Representation {repType : Optional , create : `ENABLED` , update : `DISABLED` },
40+ "defined_tags" : Representation {repType : Optional , create : `${map("${oci_identity_tag_namespace.tag-namespace1.name}.${oci_identity_tag.tag1.name}", "value")}` , update : `${map("${oci_identity_tag_namespace.tag-namespace1.name}.${oci_identity_tag.tag1.name}", "updatedValue")}` },
41+ "freeform_tags" : Representation {repType : Optional , create : map [string ]string {"bar-key" : "value" }, update : map [string ]string {"Department" : "Accounting" }},
3742 }
3843 keyKeyShapeRepresentation = map [string ]interface {}{
3944 "algorithm" : Representation {repType : Required , create : `AES` },
@@ -88,7 +93,7 @@ func TestKmsKeyResource_basic(t *testing.T) {
8893 Steps : []resource.TestStep {
8994 // verify create
9095 {
91- Config : config + compartmentIdVariableStr + KeyResourceDependencies +
96+ Config : config + compartmentIdVariableStr + KeyResourceDependencies + DefinedTagsDependencies +
9297 generateResourceFromRepresentationMap ("oci_kms_key" , "test_key" , Required , Create , keyRepresentation ),
9398 Check : resource .ComposeAggregateTestCheckFunc (
9499 resource .TestCheckResourceAttr (resourceName , "compartment_id" , tenancyId ),
@@ -104,14 +109,46 @@ func TestKmsKeyResource_basic(t *testing.T) {
104109 ),
105110 },
106111
112+ // delete before next create
113+ {
114+ Config : config + compartmentIdVariableStr + KeyResourceDependencies ,
115+ },
116+ // verify create with optionals
117+ {
118+ Config : config + compartmentIdVariableStr + KeyResourceDependencies + DefinedTagsDependencies +
119+ generateResourceFromRepresentationMap ("oci_kms_key" , "test_key" , Optional , Create , keyRepresentation ),
120+ Check : resource .ComposeAggregateTestCheckFunc (
121+ resource .TestCheckResourceAttr (resourceName , "compartment_id" , tenancyId ),
122+ resource .TestCheckResourceAttrSet (resourceName , "current_key_version" ),
123+ resource .TestCheckResourceAttr (resourceName , "defined_tags.%" , "1" ),
124+ resource .TestCheckResourceAttr (resourceName , "display_name" , "Key C" ),
125+ resource .TestCheckResourceAttr (resourceName , "freeform_tags.%" , "1" ),
126+ resource .TestCheckResourceAttrSet (resourceName , "id" ),
127+ resource .TestCheckResourceAttr (resourceName , "key_shape.#" , "1" ),
128+ resource .TestCheckResourceAttr (resourceName , "key_shape.0.algorithm" , "AES" ),
129+ resource .TestCheckResourceAttr (resourceName , "key_shape.0.length" , "16" ),
130+ resource .TestCheckResourceAttrSet (resourceName , "management_endpoint" ),
131+ resource .TestCheckResourceAttrSet (resourceName , "state" ),
132+ resource .TestCheckResourceAttrSet (resourceName , "time_created" ),
133+ resource .TestCheckResourceAttrSet (resourceName , "vault_id" ),
134+
135+ func (s * terraform.State ) (err error ) {
136+ resId , err = fromInstanceState (s , resourceName , "id" )
137+ return err
138+ },
139+ ),
140+ },
141+
107142 // verify updates to updatable parameters
108143 {
109- Config : config + compartmentIdVariableStr + KeyResourceDependencies +
144+ Config : config + compartmentIdVariableStr + KeyResourceDependencies + DefinedTagsDependencies +
110145 generateResourceFromRepresentationMap ("oci_kms_key" , "test_key" , Optional , Update , keyRepresentation ),
111146 Check : resource .ComposeAggregateTestCheckFunc (
112147 resource .TestCheckResourceAttr (resourceName , "compartment_id" , tenancyId ),
113148 resource .TestCheckResourceAttrSet (resourceName , "current_key_version" ),
149+ resource .TestCheckResourceAttr (resourceName , "defined_tags.%" , "1" ),
114150 resource .TestCheckResourceAttr (resourceName , "display_name" , "displayName2" ),
151+ resource .TestCheckResourceAttr (resourceName , "freeform_tags.%" , "1" ),
115152 resource .TestCheckResourceAttrSet (resourceName , "id" ),
116153 resource .TestCheckResourceAttr (resourceName , "key_shape.#" , "1" ),
117154 resource .TestCheckResourceAttr (resourceName , "key_shape.0.algorithm" , "AES" ),
@@ -133,14 +170,16 @@ func TestKmsKeyResource_basic(t *testing.T) {
133170 {
134171 Config : config +
135172 generateDataSourceFromRepresentationMap ("oci_kms_keys" , "test_keys" , Optional , Update , keyDataSourceRepresentation ) +
136- compartmentIdVariableStr + KeyResourceDependencies +
173+ compartmentIdVariableStr + KeyResourceDependencies + DefinedTagsDependencies +
137174 generateResourceFromRepresentationMap ("oci_kms_key" , "test_key" , Optional , Update , keyRepresentation ),
138175 Check : resource .ComposeAggregateTestCheckFunc (
139176 resource .TestCheckResourceAttr (datasourceName , "compartment_id" , tenancyId ),
140177
141178 resource .TestCheckResourceAttr (datasourceName , "keys.#" , "1" ),
142179 resource .TestCheckResourceAttr (datasourceName , "keys.0.compartment_id" , tenancyId ),
180+ resource .TestCheckResourceAttr (datasourceName , "keys.0.defined_tags.%" , "1" ),
143181 resource .TestCheckResourceAttr (datasourceName , "keys.0.display_name" , "displayName2" ),
182+ resource .TestCheckResourceAttr (datasourceName , "keys.0.freeform_tags.%" , "1" ),
144183 resource .TestCheckResourceAttrSet (datasourceName , "keys.0.id" ),
145184 resource .TestCheckResourceAttrSet (datasourceName , "keys.0.state" ),
146185 resource .TestCheckResourceAttrSet (datasourceName , "keys.0.time_created" ),
@@ -151,13 +190,15 @@ func TestKmsKeyResource_basic(t *testing.T) {
151190 {
152191 Config : config +
153192 generateDataSourceFromRepresentationMap ("oci_kms_key" , "test_key" , Required , Create , keySingularDataSourceRepresentation ) +
154- compartmentIdVariableStr + KeyResourceConfig ,
193+ compartmentIdVariableStr + KeyResourceConfig + DefinedTagsDependencies ,
155194 Check : resource .ComposeAggregateTestCheckFunc (
156195 resource .TestCheckResourceAttrSet (singularDatasourceName , "key_id" ),
157196
158197 resource .TestCheckResourceAttr (singularDatasourceName , "compartment_id" , tenancyId ),
159198 resource .TestCheckResourceAttrSet (singularDatasourceName , "current_key_version" ),
199+ resource .TestCheckResourceAttr (singularDatasourceName , "defined_tags.%" , "1" ),
160200 resource .TestCheckResourceAttr (singularDatasourceName , "display_name" , "displayName2" ),
201+ resource .TestCheckResourceAttr (singularDatasourceName , "freeform_tags.%" , "1" ),
161202 resource .TestCheckResourceAttrSet (singularDatasourceName , "id" ),
162203 resource .TestCheckResourceAttr (singularDatasourceName , "key_shape.#" , "1" ),
163204 resource .TestCheckResourceAttr (singularDatasourceName , "key_shape.0.algorithm" , "AES" ),
@@ -169,11 +210,11 @@ func TestKmsKeyResource_basic(t *testing.T) {
169210 },
170211 // remove singular datasource from previous step so that it doesn't conflict with import tests
171212 {
172- Config : config + compartmentIdVariableStr + KeyResourceConfig ,
213+ Config : config + compartmentIdVariableStr + KeyResourceConfig + DefinedTagsDependencies ,
173214 },
174215 // revert the updates
175216 {
176- Config : config + compartmentIdVariableStr + KeyResourceDependencies +
217+ Config : config + compartmentIdVariableStr + KeyResourceDependencies + DefinedTagsDependencies +
177218 generateResourceFromRepresentationMap ("oci_kms_key" , "test_key" , Optional , Create , keyRepresentation ),
178219 Check : resource .ComposeAggregateTestCheckFunc (
179220 resource .TestCheckResourceAttr (resourceName , "display_name" , "Key C" ),
0 commit comments