From 47fb70fa77e89680eb20768a5ebac5b7ace49a2f Mon Sep 17 00:00:00 2001 From: Evan Farrell Date: Thu, 20 Feb 2020 16:47:15 -0500 Subject: [PATCH 1/3] import project test and func. --- rundeck/import_resource_project_test.go | 32 +++++++++++++++++++++++++ rundeck/resource_project.go | 23 ++++++++++++++++++ 2 files changed, 55 insertions(+) create mode 100644 rundeck/import_resource_project_test.go diff --git a/rundeck/import_resource_project_test.go b/rundeck/import_resource_project_test.go new file mode 100644 index 0000000000..526f77b11f --- /dev/null +++ b/rundeck/import_resource_project_test.go @@ -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, + }, + }, + }) +} diff --git a/rundeck/resource_project.go b/rundeck/resource_project.go index 273cbd4442..ad732ffe61 100644 --- a/rundeck/resource_project.go +++ b/rundeck/resource_project.go @@ -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": { @@ -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 +} From 9dd49cd1e60c0f8ae4ffe6ea9fa385684c011674 Mon Sep 17 00:00:00 2001 From: Evan Farrell Date: Thu, 20 Feb 2020 16:49:44 -0500 Subject: [PATCH 2/3] Added import to website. --- website/docs/r/project.html.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/website/docs/r/project.html.md b/website/docs/r/project.html.md index f80bd9d4e1..7d5f3d7a75 100644 --- a/website/docs/r/project.html.md +++ b/website/docs/r/project.html.md @@ -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 +``` From da624913a60f47df0b44be6a15879fdd5179ddef Mon Sep 17 00:00:00 2001 From: Paul Seidler Date: Thu, 16 Feb 2023 14:39:32 +0100 Subject: [PATCH 3/3] fix: use Terraform sdk for project import tests Required since Terraform 0.15.0 --- rundeck/import_resource_project_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rundeck/import_resource_project_test.go b/rundeck/import_resource_project_test.go index 526f77b11f..5fba7faf8b 100644 --- a/rundeck/import_resource_project_test.go +++ b/rundeck/import_resource_project_test.go @@ -3,7 +3,7 @@ package rundeck import ( "testing" - "github.com/hashicorp/terraform/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/rundeck/go-rundeck/rundeck" )