Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions docs/resources/ruler_namespace.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,10 @@ EOT

- `id` (String) The ID of this resource.

## Import

Import is supported using the following syntax:

```shell
terraform import mimirtool_ruler_namespace.demo demo
```
1 change: 1 addition & 0 deletions examples/resources/mimirtool_ruler_namespace/import.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
terraform import mimirtool_ruler_namespace.demo demo
12 changes: 11 additions & 1 deletion mimirtool/resource_ruler_namespace.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func resourceRulerNamespace() *schema.Resource {
UpdateContext: rulerNamespaceUpdate,
DeleteContext: rulerNamespaceDelete,
Importer: &schema.ResourceImporter{
StateContext: schema.ImportStatePassthroughContext,
StateContext: rulerNamespaceImport,
},

Schema: map[string]*schema.Schema{
Expand Down Expand Up @@ -213,6 +213,16 @@ func rulerNamespaceDelete(ctx context.Context, d *schema.ResourceData, meta any)
return diags
}

func rulerNamespaceImport(ctx context.Context, d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) {
namespace := d.Id()
d.Set("namespace", namespace)
d.SetId(hash(namespace))

results := make([]*schema.ResourceData, 1)
results[0] = d
return results, nil
}

// Borrowed from https://github.com/grafana/terraform-provider-grafana/blob/master/grafana/resource_dashboard.go
func normalizeNamespaceYAML(config any) string {
configYAML := config.(string)
Expand Down
8 changes: 8 additions & 0 deletions mimirtool/resource_ruler_namespace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,14 @@ func TestAccResourceNamespace(t *testing.T) {
"mimirtool_ruler_namespace.demo", "config_yaml", testAccResourceNamespaceYamlAfterUpdate),
),
},
{
ResourceName: "mimirtool_ruler_namespace.demo",
ImportStateId: "demo",
ImportState: true,
ImportStateVerify: true,
// These fields can't be retrieved from mimir ruler
ImportStateVerifyIgnore: []string{"recording_rule_check", "strict_recording_rule_check"},
},
},
})
}
Expand Down
Loading