Skip to content

Commit 3c1c0f6

Browse files
author
k-yomo
committed
Merge branch 'main' into add-script-resource
2 parents 3633a63 + 95ab711 commit 3c1c0f6

File tree

30 files changed

+593
-27
lines changed

30 files changed

+593
-27
lines changed

.ci/Makefile.ci

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ ELASTICSEARCH_MEM ?= 1024m
1212

1313
SOURCE_LOCATION ?= $(shell pwd)
1414

15+
.PHONY: build-ci
16+
build-ci: ## build the terraform provider
17+
go build -o ${BINARY}
18+
1519
# Retry command - first argumment is how many attempts are required, second argument is the command to run
1620
# Backoff starts with 1 second and double with next itteration
1721
retry = until [ $$(if [ -z "$$attempt" ]; then echo -n "0"; else echo -n "$$attempt"; fi) -ge $(1) ]; do \

.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ jobs:
2828
run: go mod download
2929

3030
- name: Build
31-
run: make build
31+
run: make build-ci
3232

3333
lint:
3434
name: Lint

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@
33
### Added
44
- New resource `elasticstack_elasticsearch_logstash_pipeline` to manage Logstash pipelines ([Centralized Pipeline Management](https://www.elastic.co/guide/en/logstash/current/logstash-centralized-pipeline-management.html)) ([#151](https://github.com/elastic/terraform-provider-elasticstack/pull/151))
55
- Add `elasticstack_elasticsearch_script` resource ([#173](https://github.com/elastic/terraform-provider-elasticstack/pull/173))
6+
- Add `elasticstack_elasticsearch_security_role` data source ([#177](https://github.com/elastic/terraform-provider-elasticstack/pull/177))
7+
- Add `elasticstack_elasticsearch_security_role_mapping` data source ([#178](https://github.com/elastic/terraform-provider-elasticstack/pull/178))
8+
9+
### Fixed
10+
- Remove unnecessary unsetting id on delete ([#174](https://github.com/elastic/terraform-provider-elasticstack/pull/174))
11+
- Fix not found handling for snapshot repository ([#175](https://github.com/elastic/terraform-provider-elasticstack/pull/175))
612

713
## [0.4.0] - 2022-10-07
814
### Added

Makefile

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@ $(GOBIN): ## create bin/ in the current directory
2020

2121

2222
.PHONY: build
23-
build: lint ## build the terraform provider
24-
go build -o ${BINARY}
23+
build: lint build-ci ## build the terraform provider
2524

2625

2726
.PHONY: testacc
@@ -30,7 +29,7 @@ testacc: ## Run acceptance tests
3029

3130

3231
.PHONY: test
33-
test: lint ## Run unit tests
32+
test: ## Run unit tests
3433
go test -v $(TEST) $(TESTARGS) -timeout=5m -parallel=4
3534

3635

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Terraform Provider Elastic Stack
22

3-
[![Acceptance Status](https://devops-ci.elastic.co/job/elastic+terraform-provider-elasticstack+main/badge/icon?subject=acceptance)](https://devops-ci.elastic.co/job/elastic+terraform-provider-elasticstack+main/)
3+
[![Acceptance Status](https://github.com/elastic/terraform-provider-elasticstack/actions/workflows/test.yml/badge.svg)](https://github.com/elastic/terraform-provider-elasticstack/actions/workflows/test.yml)
44

55
## Use of the provider
66
The Elastic Stack provider allows you to manage and configure the Elastic stack (Elasticsearch, Kibana, etc) as code using `terraform`.
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
---
2+
subcategory: "Security"
3+
layout: ""
4+
page_title: "Elasticstack: elasticstack_elasticsearch_security_role Data Source"
5+
description: |-
6+
Retrieves roles in the native realm.
7+
---
8+
9+
# Data Source: elasticstack_elasticsearch_security_role
10+
11+
Use this data source to get information about an existing Elasticsearch role. See, https://www.elastic.co/guide/en/elasticsearch/reference/current/security-api-get-role.html
12+
13+
## Example Usage
14+
15+
```terraform
16+
provider "elasticstack" {
17+
elasticsearch {}
18+
}
19+
20+
data "elasticstack_elasticsearch_security_role" "role" {
21+
name = "testrole"
22+
}
23+
24+
output "role" {
25+
value = data.elasticstack_elasticsearch_security_role.role.name
26+
}
27+
```
28+
29+
<!-- schema generated by tfplugindocs -->
30+
## Schema
31+
32+
### Required
33+
34+
- `name` (String) The name of the role.
35+
36+
### Optional
37+
38+
- `elasticsearch_connection` (Block List, Max: 1) Used to establish connection to Elasticsearch server. Overrides environment variables if present. (see [below for nested schema](#nestedblock--elasticsearch_connection))
39+
- `run_as` (Set of String) A list of users that the owners of this role can impersonate.
40+
41+
### Read-Only
42+
43+
- `applications` (Set of Object) A list of application privilege entries. (see [below for nested schema](#nestedatt--applications))
44+
- `cluster` (Set of String) A list of cluster privileges. These privileges define the cluster level actions that users with this role are able to execute.
45+
- `global` (String) An object defining global privileges.
46+
- `id` (String) Internal identifier of the resource
47+
- `indices` (Set of Object) A list of indices permissions entries. (see [below for nested schema](#nestedatt--indices))
48+
- `metadata` (String) Optional meta-data.
49+
50+
<a id="nestedblock--elasticsearch_connection"></a>
51+
### Nested Schema for `elasticsearch_connection`
52+
53+
Optional:
54+
55+
- `api_key` (String, Sensitive) API Key to use for authentication to Elasticsearch
56+
- `ca_data` (String) PEM-encoded custom Certificate Authority certificate
57+
- `ca_file` (String) Path to a custom Certificate Authority certificate
58+
- `endpoints` (List of String, Sensitive) A list of endpoints the Terraform provider will point to. They must include the http(s) schema and port number.
59+
- `insecure` (Boolean) Disable TLS certificate validation
60+
- `password` (String, Sensitive) A password to use for API authentication to Elasticsearch.
61+
- `username` (String) A username to use for API authentication to Elasticsearch.
62+
63+
64+
<a id="nestedatt--applications"></a>
65+
### Nested Schema for `applications`
66+
67+
Read-Only:
68+
69+
- `application` (String)
70+
- `privileges` (Set of String)
71+
- `resources` (Set of String)
72+
73+
74+
<a id="nestedatt--indices"></a>
75+
### Nested Schema for `indices`
76+
77+
Read-Only:
78+
79+
- `allow_restricted_indices` (Boolean)
80+
- `field_security` (List of Object) (see [below for nested schema](#nestedobjatt--indices--field_security))
81+
- `names` (Set of String)
82+
- `privileges` (Set of String)
83+
- `query` (String)
84+
85+
<a id="nestedobjatt--indices--field_security"></a>
86+
### Nested Schema for `indices.field_security`
87+
88+
Read-Only:
89+
90+
- `except` (Set of String)
91+
- `grant` (Set of String)
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
---
2+
subcategory: "Security"
3+
layout: ""
4+
page_title: "Elasticstack: elasticstack_elasticsearch_security_role_mapping Data Source"
5+
description: |-
6+
Retrieves role mappings.
7+
---
8+
9+
# Data Source: elasticstack_elasticsearch_security_role_mapping
10+
11+
Retrieves role mappings. See, https://www.elastic.co/guide/en/elasticsearch/reference/current/security-api-get-role-mapping.html
12+
13+
## Example Usage
14+
15+
```terraform
16+
provider "elasticstack" {
17+
elasticsearch {}
18+
}
19+
20+
data "elasticstack_elasticsearch_security_role_mapping" "mapping" {
21+
name = "my_mapping"
22+
}
23+
24+
output "user" {
25+
value = data.elasticstack_elasticsearch_security_role_mapping.mapping.name
26+
}
27+
```
28+
29+
<!-- schema generated by tfplugindocs -->
30+
## Schema
31+
32+
### Required
33+
34+
- `name` (String) The distinct name that identifies the role mapping, used solely as an identifier.
35+
36+
### Optional
37+
38+
- `elasticsearch_connection` (Block List, Max: 1) Used to establish connection to Elasticsearch server. Overrides environment variables if present. (see [below for nested schema](#nestedblock--elasticsearch_connection))
39+
40+
### Read-Only
41+
42+
- `enabled` (Boolean) Mappings that have `enabled` set to `false` are ignored when role mapping is performed.
43+
- `id` (String) Internal identifier of the resource
44+
- `metadata` (String) Additional metadata that helps define which roles are assigned to each user. Keys beginning with `_` are reserved for system usage.
45+
- `role_templates` (String) A list of mustache templates that will be evaluated to determine the roles names that should granted to the users that match the role mapping rules.
46+
- `roles` (Set of String) A list of role names that are granted to the users that match the role mapping rules.
47+
- `rules` (String) The rules that determine which users should be matched by the mapping. A rule is a logical condition that is expressed by using a JSON DSL.
48+
49+
<a id="nestedblock--elasticsearch_connection"></a>
50+
### Nested Schema for `elasticsearch_connection`
51+
52+
Optional:
53+
54+
- `api_key` (String, Sensitive) API Key to use for authentication to Elasticsearch
55+
- `ca_data` (String) PEM-encoded custom Certificate Authority certificate
56+
- `ca_file` (String) Path to a custom Certificate Authority certificate
57+
- `endpoints` (List of String, Sensitive) A list of endpoints the Terraform provider will point to. They must include the http(s) schema and port number.
58+
- `insecure` (Boolean) Disable TLS certificate validation
59+
- `password` (String, Sensitive) A password to use for API authentication to Elasticsearch.
60+
- `username` (String) A username to use for API authentication to Elasticsearch.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
provider "elasticstack" {
2+
elasticsearch {}
3+
}
4+
5+
data "elasticstack_elasticsearch_security_role" "role" {
6+
name = "testrole"
7+
}
8+
9+
output "role" {
10+
value = data.elasticstack_elasticsearch_security_role.role.name
11+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
provider "elasticstack" {
2+
elasticsearch {}
3+
}
4+
5+
data "elasticstack_elasticsearch_security_role_mapping" "mapping" {
6+
name = "my_mapping"
7+
}
8+
9+
output "user" {
10+
value = data.elasticstack_elasticsearch_security_role_mapping.mapping.name
11+
}

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module github.com/elastic/terraform-provider-elasticstack
33
go 1.19
44

55
require (
6-
github.com/elastic/go-elasticsearch/v7 v7.17.1
6+
github.com/elastic/go-elasticsearch/v7 v7.17.7
77
github.com/hashicorp/go-cty v1.4.1-0.20200414143053-d3edf31b6320
88
github.com/hashicorp/terraform-plugin-log v0.7.0
99
github.com/hashicorp/terraform-plugin-sdk/v2 v2.24.0

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ3
3333
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
3434
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
3535
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
36-
github.com/elastic/go-elasticsearch/v7 v7.17.1 h1:49mHcHx7lpCL8cW1aioEwSEVKQF3s+Igi4Ye/QTWwmk=
37-
github.com/elastic/go-elasticsearch/v7 v7.17.1/go.mod h1:OJ4wdbtDNk5g503kvlHLyErCgQwwzmDtaFC4XyOxXA4=
36+
github.com/elastic/go-elasticsearch/v7 v7.17.7 h1:pcYNfITNPusl+cLwLN6OLmVT+F73Els0nbaWOmYachs=
37+
github.com/elastic/go-elasticsearch/v7 v7.17.7/go.mod h1:OJ4wdbtDNk5g503kvlHLyErCgQwwzmDtaFC4XyOxXA4=
3838
github.com/emirpasic/gods v1.12.0 h1:QAUIPSaCu4G+POclxeqb3F+WPpdKqFGlw36+yOzGlrg=
3939
github.com/emirpasic/gods v1.12.0/go.mod h1:YfzfFFoVP/catgzJb4IKIqXjX78Ha8FMSDh3ymbK86o=
4040
github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=

internal/clients/cluster.go

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,7 @@ func (a *ApiClient) GetElasticsearchSnapshotRepository(ctx context.Context, name
3939
}
4040
defer res.Body.Close()
4141
if res.StatusCode == http.StatusNotFound {
42-
diags = append(diags, diag.Diagnostic{
43-
Severity: diag.Error,
44-
Summary: "Unable to find requested repository",
45-
Detail: fmt.Sprintf(`Repository "%s" is missing in the ES API response`, name),
46-
})
47-
return nil, diags
42+
return nil, nil
4843
}
4944
if diags := utils.CheckError(res, fmt.Sprintf("Unable to get the information about snapshot repository: %s", name)); diags.HasError() {
5045
return nil, diags
@@ -113,10 +108,10 @@ func (a *ApiClient) GetElasticsearchSlm(ctx context.Context, slmName string) (*m
113108
if diags := utils.CheckError(res, "Unable to get SLM policy from ES API"); diags.HasError() {
114109
return nil, diags
115110
}
116-
type SlmReponse = map[string]struct {
111+
type SlmResponse = map[string]struct {
117112
Policy models.SnapshotPolicy `json:"policy"`
118113
}
119-
var slmResponse SlmReponse
114+
var slmResponse SlmResponse
120115
if err := json.NewDecoder(res.Body).Decode(&slmResponse); err != nil {
121116
return nil, diag.FromErr(err)
122117
}

internal/elasticsearch/cluster/settings.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,5 @@ func resourceClusterSettingsDelete(ctx context.Context, d *schema.ResourceData,
287287
return diags
288288
}
289289

290-
d.SetId("")
291290
return diags
292291
}

internal/elasticsearch/cluster/slm.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,5 @@ func resourceSlmDelete(ctx context.Context, d *schema.ResourceData, meta interfa
339339
if diags := client.DeleteElasticsearchSlm(ctx, id.ResourceId); diags.HasError() {
340340
return diags
341341
}
342-
d.SetId("")
343342
return diags
344343
}

internal/elasticsearch/cluster/snapshot_repository.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"github.com/elastic/terraform-provider-elasticstack/internal/clients"
1111
"github.com/elastic/terraform-provider-elasticstack/internal/models"
1212
"github.com/elastic/terraform-provider-elasticstack/internal/utils"
13+
"github.com/hashicorp/terraform-plugin-log/tflog"
1314
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
1415
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
1516
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
@@ -374,6 +375,7 @@ func resourceSnapRepoRead(ctx context.Context, d *schema.ResourceData, meta inte
374375

375376
currentRepo, diags := client.GetElasticsearchSnapshotRepository(ctx, compId.ResourceId)
376377
if currentRepo == nil && diags == nil {
378+
tflog.Warn(ctx, fmt.Sprintf(`Snapshot repository "%s" not found, removing from state`, compId.ResourceId))
377379
d.SetId("")
378380
return diags
379381
}
@@ -454,6 +456,5 @@ func resourceSnapRepoDelete(ctx context.Context, d *schema.ResourceData, meta in
454456
if diags := client.DeleteElasticsearchSnapshotRepository(ctx, compId.ResourceId); diags.HasError() {
455457
return diags
456458
}
457-
d.SetId("")
458459
return diags
459460
}

internal/elasticsearch/index/component_template.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,5 @@ func resourceComponentTemplateDelete(ctx context.Context, d *schema.ResourceData
293293
if diags := client.DeleteElasticsearchComponentTemplate(ctx, compId.ResourceId); diags.HasError() {
294294
return diags
295295
}
296-
d.SetId("")
297296
return diags
298297
}

internal/elasticsearch/index/data_stream.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,5 @@ func resourceDataStreamDelete(ctx context.Context, d *schema.ResourceData, meta
222222
return diags
223223
}
224224

225-
d.SetId("")
226225
return diags
227226
}

internal/elasticsearch/index/ilm.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -651,6 +651,5 @@ func resourceIlmDelete(ctx context.Context, d *schema.ResourceData, meta interfa
651651
return diags
652652
}
653653

654-
d.SetId("")
655654
return diags
656655
}

internal/elasticsearch/index/index.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -927,6 +927,5 @@ func resourceIndexDelete(ctx context.Context, d *schema.ResourceData, meta inter
927927
if diags := client.DeleteElasticsearchIndex(ctx, compId.ResourceId); diags.HasError() {
928928
return diags
929929
}
930-
d.SetId("")
931930
return diags
932931
}

internal/elasticsearch/index/template.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,5 @@ func resourceIndexTemplateDelete(ctx context.Context, d *schema.ResourceData, me
420420
if diags := client.DeleteElasticsearchIndexTemplate(ctx, compId.ResourceId); diags.HasError() {
421421
return diags
422422
}
423-
d.SetId("")
424423
return diags
425424
}

internal/elasticsearch/ingest/pipeline.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,5 @@ func resourceIngestPipelineTemplateDelete(ctx context.Context, d *schema.Resourc
218218
return diags
219219
}
220220

221-
d.SetId("")
222221
return diags
223222
}

internal/elasticsearch/security/role.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -431,6 +431,5 @@ func resourceSecurityRoleDelete(ctx context.Context, d *schema.ResourceData, met
431431
return diags
432432
}
433433

434-
d.SetId("")
435434
return diags
436435
}

0 commit comments

Comments
 (0)