Skip to content

Commit

Permalink
import project test and func.
Browse files Browse the repository at this point in the history
  • Loading branch information
Evan Farrell authored and sepek committed Feb 16, 2023
1 parent 0004c84 commit 47fb70f
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 0 deletions.
32 changes: 32 additions & 0 deletions rundeck/import_resource_project_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package rundeck

import (
"testing"

"github.com/hashicorp/terraform/helper/resource"
"github.com/rundeck/go-rundeck/rundeck"
)

func TestAccProject_Import(t *testing.T) {
name := "rundeck_project.main"
project_name := "terraform-acc-test-basic"
var project rundeck.Project

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccProjectCheckDestroy(&project),
Steps: []resource.TestStep{
{
Config: testAccProjectConfig_basic,
Check: testAccProjectCheckExists(name, &project),
},
{
ResourceName: name,
ImportStateId: project_name,
ImportState: true,
ImportStateVerify: true,
},
},
})
}
23 changes: 23 additions & 0 deletions rundeck/resource_project.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ func resourceRundeckProject() *schema.Resource {
Delete: DeleteProject,
Exists: ProjectExists,
Read: ReadProject,
Importer: &schema.ResourceImporter{
State: resourceProjectImport,
},

Schema: map[string]*schema.Schema{
"name": {
Expand Down Expand Up @@ -307,3 +310,23 @@ func DeleteProject(d *schema.ResourceData, meta interface{}) error {

return err
}

func resourceProjectImport(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) {
name := d.Id()

ok, err := ProjectExists(d, meta)
if err != nil {
return nil, err
}
if !ok {
return nil, fmt.Errorf("Project doesn't exist. Please try again.")
}
d.SetId(name)

err = ReadProject(d, meta)
if err != nil {
return nil, err
}

return []*schema.ResourceData{d}, nil
}

0 comments on commit 47fb70f

Please sign in to comment.