@@ -24,8 +24,8 @@ import (
2424)
2525
2626const (
27- testOrgID = "4e4cd9eb-82eb-407e-a926-e5fef81cab50"
28- testClusterID = "b6bfc074-a267-400f-b8f1-db0850c369b1"
27+ testOrgID = "4e4cd9eb-82eb-407e-a926-e5fef81cab50"
28+ testClusterID = "b6bfc074-a267-400f-b8f1-db0850c369b1"
2929 testMutationID = "a1b2c3d4-e5f6-7890-abcd-ef1234567890"
3030)
3131
@@ -301,6 +301,39 @@ func TestPodMutation_UpdateContext(t *testing.T) {
301301 })
302302}
303303
304+ func TestPodMutation_StateImporter (t * testing.T ) {
305+ t .Parallel ()
306+
307+ t .Run ("three part ID sets organization_id, cluster_id, and mutation_id" , func (t * testing.T ) {
308+ r := require .New (t )
309+ res := resourcePodMutation ()
310+ d := res .Data (nil )
311+ d .SetId ("org-123/cluster-456/mutation-789" )
312+
313+ result , err := res .Importer .StateContext (t .Context (), d , nil )
314+
315+ r .NoError (err )
316+ r .Len (result , 1 )
317+ r .Equal ("mutation-789" , d .Id ())
318+ r .Equal ("org-123" , d .Get (FieldPodMutationOrganizationID ))
319+ r .Equal ("cluster-456" , d .Get (FieldPodMutationClusterID ))
320+ })
321+
322+ for _ , id := range []string {"mutation-789" , "org-123/mutation-789" , "a/b/c/d" } {
323+ t .Run ("invalid import ID " + id , func (t * testing.T ) {
324+ r := require .New (t )
325+ res := resourcePodMutation ()
326+ d := res .Data (nil )
327+ d .SetId (id )
328+
329+ _ , err := res .Importer .StateContext (t .Context (), d , nil )
330+
331+ r .Error (err )
332+ r .Contains (err .Error (), "invalid import ID" )
333+ })
334+ }
335+ }
336+
304337func TestAccCloudAgnostic_ResourcePodMutation (t * testing.T ) {
305338 rName := fmt .Sprintf ("%v-pod-mutation-%v" , ResourcePrefix , acctest .RandString (8 ))
306339 resourceName := "castai_pod_mutation.test"
@@ -343,6 +376,17 @@ func TestAccCloudAgnostic_ResourcePodMutation(t *testing.T) {
343376 resource .TestCheckResourceAttr (resourceName , "object_filter_v2.0.namespaces.0.value" , "^prod-.*$" ),
344377 ),
345378 },
379+ {
380+ // Test import with organization_id/cluster_id/mutation_id
381+ ResourceName : resourceName ,
382+ ImportStateIdFunc : func (s * tfterraform.State ) (string , error ) {
383+ rs := s .RootModule ().Resources [resourceName ]
384+ clusterID := rs .Primary .Attributes ["cluster_id" ]
385+ return fmt .Sprintf ("%s/%s/%s" , organizationID , clusterID , rs .Primary .ID ), nil
386+ },
387+ ImportState : true ,
388+ ImportStateVerify : true ,
389+ },
346390 {
347391 // Test update to zero values - verifies no drift on next plan
348392 Config : testAccPodMutationConfigZeroValues (rName , clusterName , organizationID ),
0 commit comments