-
Notifications
You must be signed in to change notification settings - Fork 102
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
job: import jobs from non-default namespace
Since the `nomad_job` resource does not have a `namespace` attribute, it's currently impossible to import jobs from a non-default namespace. This commit adds a new helper that imports jobs using the `<job>@<namespace>` ID syntax. Since `@` is not a valid character for namespaces, the last `@` character (if found) represents the separator.
- Loading branch information
Showing
3 changed files
with
45 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package helper | ||
|
||
import ( | ||
"context" | ||
"strings" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||
) | ||
|
||
// NamespacedImporterContext allows importing resources under a namespace where | ||
// the namespace is not passed as an attribute. | ||
func NamespacedImporterContext(_ context.Context, d *schema.ResourceData, a any) ([]*schema.ResourceData, error) { | ||
namespacedID := d.Id() | ||
sepIdx := strings.LastIndex(d.Id(), "@") | ||
if sepIdx == -1 { | ||
return []*schema.ResourceData{d}, nil | ||
} | ||
|
||
d.SetId(namespacedID[:sepIdx]) | ||
d.Set("namespace", namespacedID[sepIdx+1:]) | ||
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