@@ -66,6 +66,7 @@ func TestAccAxiomDashboardResource_WithProvidedUID(t *testing.T) {
6666 ImportStateVerifyIgnore : []string {
6767 "dashboard" ,
6868 },
69+ ImportStateCheck : testAccCheckImportedDashboardState (uid , updatedName , nil ),
6970 },
7071 },
7172 })
@@ -136,6 +137,12 @@ func TestAccAxiomDashboardResource_ServerGeneratedUID(t *testing.T) {
136137 "dashboard" ,
137138 "overwrite" ,
138139 },
140+ ImportStateCheck : testAccCheckImportedDashboardState (generatedUID , updatedName , func (v string ) error {
141+ if v != "false" {
142+ return fmt .Errorf ("expected imported overwrite to default to false, got %q" , v )
143+ }
144+ return nil
145+ }),
139146 },
140147 },
141148 })
@@ -274,3 +281,32 @@ func testAccCaptureDashboardUID(resourceName string, out *string) resource.TestC
274281 return nil
275282 }
276283}
284+
285+ func testAccCheckImportedDashboardState (expectedUID , expectedName string , overwriteCheck func (string ) error ) resource.ImportStateCheckFunc {
286+ return func (states []* terraform.InstanceState ) error {
287+ if len (states ) != 1 {
288+ return fmt .Errorf ("expected exactly one imported instance state, got %d" , len (states ))
289+ }
290+
291+ attrs := states [0 ].Attributes
292+ if attrs ["uid" ] != expectedUID {
293+ return fmt .Errorf ("expected imported uid %q, got %q" , expectedUID , attrs ["uid" ])
294+ }
295+
296+ dashboardJSON := attrs ["dashboard" ]
297+ if dashboardJSON == "" {
298+ return fmt .Errorf ("expected imported dashboard JSON to be present" )
299+ }
300+ if ! strings .Contains (dashboardJSON , expectedName ) {
301+ return fmt .Errorf ("expected imported dashboard JSON to include name %q, got %s" , expectedName , dashboardJSON )
302+ }
303+
304+ if overwriteCheck != nil {
305+ if err := overwriteCheck (attrs ["overwrite" ]); err != nil {
306+ return err
307+ }
308+ }
309+
310+ return nil
311+ }
312+ }
0 commit comments