-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add resources importer
- Loading branch information
Showing
5 changed files
with
74 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package launchdarkly | ||
|
||
import ( | ||
"fmt" | ||
"github.com/hashicorp/terraform/helper/schema" | ||
"strings" | ||
) | ||
|
||
func parseCompositeID(id string) (p1 string, p2 string, err error) { | ||
parts := strings.SplitN(id, ":", 2) | ||
if len(parts) == 2 { | ||
p1 = parts[0] | ||
p2 = parts[1] | ||
} else { | ||
err = fmt.Errorf("error: Import composite ID requires two parts separated by colon, eg x:y") | ||
} | ||
return | ||
} | ||
|
||
type importFunc func(d *schema.ResourceData, meta interface{}) error | ||
|
||
func resourceImport(readMethod importFunc, d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) { | ||
projectKey, resourceKey, err := parseCompositeID(d.Id()) | ||
if err != nil { | ||
return nil, err | ||
} | ||
d.SetId(resourceKey) | ||
d.Set("project_key", projectKey) | ||
d.Set("key", resourceKey) | ||
|
||
readMethod(d, meta) | ||
|
||
return []*schema.ResourceData{d}, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters