Skip to content

Commit 3cae061

Browse files
authored
Add support for importing role mappings (#1441)
* Add support for importing role mappings * Changelog
1 parent 9ce3de5 commit 3cae061

File tree

3 files changed

+16
-0
lines changed

3 files changed

+16
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
- Add new `elasticstack_elasticsearch_ml_anomaly_detection_job` resource ([#1329](https://github.com/elastic/terraform-provider-elasticstack/pull/1329))
55
- Add new `elasticstack_elasticsearch_ml_datafeed` resource ([#1340](https://github.com/elastic/terraform-provider-elasticstack/pull/1340))
66
- Add `space_ids` attribute to all Fleet resources to support space-aware Fleet resource management ([#1390](https://github.com/elastic/terraform-provider-elasticstack/pull/1390))
7+
- Add back missing import support for `elasticstack_elasticsearch_security_role_mapping` ([#1441](https://github.com/elastic/terraform-provider-elasticstack/pull/1441))
78
- Add new `elasticstack_elasticsearch_ml_job_state` resource ([#1337](https://github.com/elastic/terraform-provider-elasticstack/pull/1337))
89
- Add new `elasticstack_elasticsearch_ml_datafeed_state` resource ([#1422](https://github.com/elastic/terraform-provider-elasticstack/pull/1422))
910
- Make `hosts` attribute required in `elasticstack_fleet_output` resource ([#1450](https://github.com/elastic/terraform-provider-elasticstack/pull/1450/files))

internal/elasticsearch/security/role_mapping/acc_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,11 @@ func TestAccResourceSecurityRoleMapping(t *testing.T) {
5656
resource.TestCheckResourceAttr("elasticstack_elasticsearch_security_role_mapping.test", "metadata", `{}`),
5757
),
5858
},
59+
{
60+
ResourceName: "elasticstack_elasticsearch_security_role_mapping.test",
61+
ImportState: true,
62+
ImportStateVerify: true,
63+
},
5964
},
6065
})
6166
})

internal/elasticsearch/security/role_mapping/resource.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,15 @@ import (
44
"context"
55

66
"github.com/elastic/terraform-provider-elasticstack/internal/clients"
7+
"github.com/hashicorp/terraform-plugin-framework/path"
78
"github.com/hashicorp/terraform-plugin-framework/resource"
89
)
910

11+
// Ensure provider defined types fully satisfy framework interfaces
12+
var _ resource.Resource = &roleMappingResource{}
13+
var _ resource.ResourceWithConfigure = &roleMappingResource{}
14+
var _ resource.ResourceWithImportState = &roleMappingResource{}
15+
1016
func NewRoleMappingResource() resource.Resource {
1117
return &roleMappingResource{}
1218
}
@@ -24,3 +30,7 @@ func (r *roleMappingResource) Configure(_ context.Context, req resource.Configur
2430
resp.Diagnostics.Append(diags...)
2531
r.client = client
2632
}
33+
34+
func (r *roleMappingResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) {
35+
resource.ImportStatePassthroughID(ctx, path.Root("id"), req, resp)
36+
}

0 commit comments

Comments
 (0)