@@ -5,6 +5,7 @@ package oci
55
66import (
77 "fmt"
8+ "strconv"
89 "testing"
910
1011 "github.com/hashicorp/terraform-plugin-sdk/helper/resource"
2223 "freeform_tags" : Representation {repType : Optional , create : map [string ]string {"Department" : "Finance" }},
2324 "kms_key_id" : Representation {repType : Optional , create : `${var.kms_key_id_for_create}` , update : `` },
2425 }
26+ snapshotRepresentationNoTags = map [string ]interface {}{
27+ "file_system_id" : Representation {repType : Required , create : `${oci_file_storage_file_system.test_file_system.id}` },
28+ "name" : Representation {repType : Required , create : `snapshot-1` },
29+ "freeform_tags" : Representation {repType : Optional , create : map [string ]string {"Department" : "Finance" }, update : map [string ]string {"Department" : "Accounting" }},
30+ }
31+ fileSystemRepresentationNoTags = map [string ]interface {}{
32+ "availability_domain" : Representation {repType : Required , create : `${data.oci_identity_availability_domains.test_availability_domains.availability_domains.0.name}` },
33+ "compartment_id" : Representation {repType : Required , create : `${var.compartment_id}` },
34+ "display_name" : Representation {repType : Optional , create : `media-files-1` , update : `displayName2` },
35+ "freeform_tags" : Representation {repType : Optional , create : map [string ]string {"Department" : "Finance" }, update : map [string ]string {"Department" : "Accounting" }},
36+ "source_snapshot_id" : Representation {repType : Optional , create : `${oci_file_storage_snapshot.test_snapshot.id}` },
37+ }
38+
39+ SnapshotResourceDependenciesNoTags = generateResourceFromRepresentationMap ("oci_file_storage_file_system" , "test_file_system" , Required , Create , fileSystemRepresentationNoTags ) +
40+ AvailabilityDomainConfig
41+
42+ fileSystemRepresentationClone = map [string ]interface {}{
43+ "availability_domain" : Representation {repType : Required , create : `${data.oci_identity_availability_domains.test_availability_domains.availability_domains.0.name}` },
44+ "compartment_id" : Representation {repType : Required , create : `${var.compartment_id}` },
45+ "display_name" : Representation {repType : Optional , create : `media-files-1` , update : `displayName2` },
46+ "freeform_tags" : Representation {repType : Optional , create : map [string ]string {"Department" : "Finance" }, update : map [string ]string {"Department" : "Accounting" }},
47+ "source_snapshot_id" : Representation {repType : Optional , create : `${oci_file_storage_snapshot.test_snapshot.id}` },
48+ }
49+
50+ FileSystemResourceDependenciesNoTags = generateResourceFromRepresentationMap ("oci_file_storage_file_system" , "test_file_system" , Required , Create , fileSystemRepresentationNoTags ) +
51+ generateResourceFromRepresentationMap ("oci_file_storage_snapshot" , "test_snapshot" , Required , Create , snapshotRepresentationNoTags ) +
52+ AvailabilityDomainConfig
2553)
2654
2755func TestFileStorageFileSystemResource_removeKMSKey (t * testing.T ) {
@@ -123,3 +151,76 @@ func TestFileStorageFileSystemResource_removeKMSKey(t *testing.T) {
123151 },
124152 })
125153}
154+
155+ func TestFileStorageFileSystemResource_cloneFromSnapshot (t * testing.T ) {
156+ httpreplay .SetScenario ("TestFileStorageFileSystemResource_cloneFromSnapshot" )
157+ defer httpreplay .SaveScenario ()
158+
159+ provider := testAccProvider
160+ config := testProviderConfig ()
161+
162+ compartmentId := getEnvSettingWithBlankDefault ("compartment_ocid" )
163+ compartmentIdVariableStr := fmt .Sprintf ("variable \" compartment_id\" { default = \" %s\" }\n " , compartmentId )
164+
165+ resourceName := "oci_file_storage_snapshot.test_snapshot"
166+ resourceName2 := "oci_file_storage_file_system.test_file_system_clone"
167+
168+ var resId string
169+
170+ resource .Test (t , resource.TestCase {
171+ PreCheck : func () { testAccPreCheck (t ) },
172+ Providers : map [string ]terraform.ResourceProvider {
173+ "oci" : provider ,
174+ },
175+ CheckDestroy : testAccCheckFileStorageFileSystemDestroy ,
176+ Steps : []resource.TestStep {
177+ // verify create with optionals
178+ {
179+ Config : config + compartmentIdVariableStr + SnapshotResourceDependenciesNoTags +
180+ generateResourceFromRepresentationMap ("oci_file_storage_snapshot" , "test_snapshot" , Optional , Create , snapshotRepresentationNoTags ),
181+ Check : resource .ComposeAggregateTestCheckFunc (
182+ resource .TestCheckResourceAttrSet (resourceName , "file_system_id" ),
183+ resource .TestCheckResourceAttr (resourceName , "freeform_tags.%" , "1" ),
184+ resource .TestCheckResourceAttrSet (resourceName , "id" ),
185+ resource .TestCheckResourceAttr (resourceName , "name" , "snapshot-1" ),
186+ resource .TestCheckResourceAttrSet (resourceName , "state" ),
187+ resource .TestCheckResourceAttrSet (resourceName , "time_created" ),
188+ func (s * terraform.State ) (err error ) {
189+ resId , err = fromInstanceState (s , resourceName , "id" )
190+ if isEnableExportCompartment , _ := strconv .ParseBool (getEnvSettingWithDefault ("enable_export_compartment" , "false" )); isEnableExportCompartment {
191+ if errExport := testExportCompartmentWithResourceName (& resId , & compartmentId , resourceName ); errExport != nil {
192+ return errExport
193+ }
194+ }
195+ return err
196+ },
197+ ),
198+ },
199+ // verify create FileSystem via cloning Snapshot
200+ {
201+ Config : config + compartmentIdVariableStr + FileSystemResourceDependenciesNoTags +
202+ generateResourceFromRepresentationMap ("oci_file_storage_file_system" , "test_file_system_clone" , Optional , Create , fileSystemRepresentationClone ),
203+ Check : resource .ComposeAggregateTestCheckFunc (
204+ resource .TestCheckResourceAttrSet (resourceName2 , "availability_domain" ),
205+ resource .TestCheckResourceAttr (resourceName2 , "compartment_id" , compartmentId ),
206+ resource .TestCheckResourceAttr (resourceName2 , "display_name" , "media-files-1" ),
207+ resource .TestCheckResourceAttr (resourceName2 , "freeform_tags.%" , "1" ),
208+ resource .TestCheckResourceAttrSet (resourceName2 , "id" ),
209+ resource .TestCheckResourceAttrSet (resourceName2 , "metered_bytes" ),
210+ resource .TestCheckResourceAttrSet (resourceName2 , "source_snapshot_id" ),
211+ resource .TestCheckResourceAttrSet (resourceName2 , "state" ),
212+ resource .TestCheckResourceAttrSet (resourceName2 , "time_created" ),
213+ //verify ids match
214+ func (s * terraform.State ) (err error ) {
215+ snapshotId , err := fromInstanceState (s , resourceName2 , "source_snapshot_id" )
216+ if resId != snapshotId {
217+ return fmt .Errorf ("Resource source snapshot id [%v] was different from expected [%v]." , snapshotId , resId )
218+ }
219+
220+ return err
221+ },
222+ ),
223+ },
224+ },
225+ })
226+ }
0 commit comments