Skip to content

Commit

Permalink
Merge pull request #89 from sepek/master
Browse files Browse the repository at this point in the history
Ability to import projects
  • Loading branch information
imjaroiswebdev authored Oct 6, 2023
2 parents 0004c84 + da62491 commit 3b5da17
Show file tree
Hide file tree
Showing 3 changed files with 63 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-plugin-sdk/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
}
8 changes: 8 additions & 0 deletions website/docs/r/project.html.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,3 +90,11 @@ The following attributes are exported:

* `name` - The unique name that identifies the project, as set in the arguments.
* `ui_url` - The URL of the index page for this project in the Rundeck UI.

## Import

Rundeck Project can be imported using the `name`, e.g.

```
$ terraform import rundeck_project.main project-name
```

0 comments on commit 3b5da17

Please sign in to comment.