Skip to content

Commit 269648d

Browse files
dimuonpascal-hofmanntobio
authored
Feature/530/migrate to plugin framework (#567)
Migration to TF Framework. A breaking schema change. Please see relevant NOTES in CHANGELOG for v0.6.0 and README for more info. State upgrade is not supported, please use import instead. --------- Co-authored-by: Pascal Hofmann <[email protected]> Co-authored-by: Pascal Hofmann <[email protected]> Co-authored-by: Toby Brain <[email protected]>
1 parent b9c45c5 commit 269648d

File tree

388 files changed

+31735
-23074
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

388 files changed

+31735
-23074
lines changed

.github/workflows/go.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ jobs:
2121
- name: Install terraform
2222
uses: hashicorp/setup-terraform@v2
2323
with:
24-
terraform_version: "0.14.x"
24+
terraform_version: "1.x.x"
25+
terraform_wrapper: false
2526

2627
- name: Cache Go Modules
2728
uses: actions/cache@v3

CHANGELOG.md

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,37 @@
1-
# 0.6.0 (Unreleased)
1+
# 0.7.0 (Unreleased)
22

33
# 0.5.1 (Feb 15, 2023)
44

55
FEATURES:
66

77
* resource/deployment: Utilise the template migration API to build the base update request when changing `deployment_template_id`. This results in more reliable changes between deployment templates. ([#547](https://github.com/elastic/terraform-provider-ec/issues/547))
88

9+
# 0.6.0 (Unreleased)
10+
11+
FEATURES:
12+
13+
Migration to [TF Plugin Framework](https://developer.hashicorp.com/terraform/plugin/framework)
14+
15+
**BREAKING CHANGES**:
16+
17+
New schema for `ec_deployment`. Existing resources should be imported. Please see NOTES below and README for more details.
18+
19+
BUG FIXES:
20+
21+
[#336](https://github.com/elastic/terraform-provider-ec/issues/336)
22+
[#467](https://github.com/elastic/terraform-provider-ec/issues/467)
23+
[#445](https://github.com/elastic/terraform-provider-ec/issues/445)
24+
25+
NOTES
26+
27+
* Older versions of terraform CLI can report errors with the provider 0.6.0 and higher. Please make sure to update Terraform CLI to the latest version.
28+
* State upgrade is not implemented for `ec_deployment`.
29+
The recommended way to proceed with existing TF resources is [state import](https://developer.hashicorp.com/terraform/cli/import#state-only).
30+
However, this doesn't import user passwords and secret tokens.
31+
* After import, the next plan command can output more elements that the actual configuration defines, e.g. plan command can output `cold` Elasticsearch tier with 0 size or empty `config` block for configuration that doesn't specify `cold` tier and `config` for `elasticsearch`.
32+
It should not be a problem. You can eigher execute the plan (the only result should be updated Terraform state while the deployment should stay the same) or add empty `cold` tier and `confg` to the configuration.
33+
* The migration is based on 0.4.1, so all changes from 0.5.0 are omitted.
34+
935
# 0.5.0 (Oct 12, 2022)
1036

1137
FEATURES:

NOTICE

100755100644
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
terraform-provider-ec
2-
Copyright 2023 Elasticsearch B.V.
2+
Copyright 2022-2023 Elasticsearch B.V.
33

44
This product includes software developed at Elasticsearch B.V. and
55
third-party software developed by the licenses listed below.

README.md

Lines changed: 130 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,15 @@ resource "ec_deployment" "example_minimal" {
7272
deployment_template_id = "aws-io-optimized-v2"
7373
7474
# Use the deployment template defaults
75-
elasticsearch {}
75+
elasticsearch = {
76+
hot = {
77+
autoscaling = {}
78+
}
79+
}
7680
77-
kibana {}
81+
kibana = {
82+
topology = {}
83+
}
7884
}
7985
```
8086

@@ -114,3 +120,125 @@ $ export EC_API_KEY="<apikey value>"
114120
```
115121

116122
After doing so, you can navigate to any of our examples in `./examples` and try one.
123+
124+
### Moving to TF Framework and schema change for `ec_deployment` resource.
125+
126+
v0.6.0 contains migration to [TF Plugin Framework](https://developer.hashicorp.com/terraform/plugin/framework) and intoduces new schema for `ec_deployment` resource:
127+
128+
- switching to attributes syntax instead of blocks for almost all definitions that used to be blocks. It means that, for example, a definition like `elasticsearch {...}` has to be changed to `elasticsearch = {...}`, e.g.
129+
130+
```hcl
131+
resource "ec_deployment" "defaults" {
132+
name = "example"
133+
region = "us-east-1"
134+
version = data.ec_stack.latest.version
135+
deployment_template_id = "aws-io-optimized-v2"
136+
137+
elasticsearch = {
138+
hot = {
139+
autoscaling = {}
140+
}
141+
}
142+
143+
kibana = {
144+
topology = {}
145+
}
146+
147+
enterprise_search = {
148+
zone_count = 1
149+
}
150+
}
151+
```
152+
153+
- `topology` attribute of `elasticsearch` is replaced with a number of dedicated attributes, one per tier, e.g.
154+
155+
```
156+
elasticsearch {
157+
topology {
158+
id = "hot_content"
159+
size = "1g"
160+
autoscaling {
161+
max_size = "8g"
162+
}
163+
}
164+
topology {
165+
id = "warm"
166+
size = "2g"
167+
autoscaling {
168+
max_size = "15g"
169+
}
170+
}
171+
}
172+
```
173+
174+
has to be converted to
175+
176+
```
177+
elasticsearch = {
178+
hot = {
179+
size = "1g"
180+
autoscaling = {
181+
max_size = "8g"
182+
}
183+
}
184+
185+
warm = {
186+
size = "2g"
187+
autoscaling = {
188+
max_size = "15g"
189+
}
190+
}
191+
}
192+
193+
```
194+
195+
- due to some existing limitations of TF, nested attributes that are nested inside other nested attributes cannot be `Computed`. It means that all such attributes have to be mentioned in configurations even if they are empty. E.g., a definition of `elasticsearch` has to include all topology elements (tiers) that have non-zero size or can be scaled up (if autoscaling is enabled) in the corresponding template. For example, the simplest definition of `elasticsearch` for `aws-io-optimized-v2` template is
196+
197+
```hcl
198+
resource "ec_deployment" "defaults" {
199+
name = "example"
200+
region = "us-east-1"
201+
version = data.ec_stack.latest.version
202+
deployment_template_id = "aws-io-optimized-v2"
203+
204+
elasticsearch = {
205+
hot = {
206+
autoscaling = {}
207+
}
208+
}
209+
}
210+
```
211+
212+
Please note that the snippet explicitly mentions `hot` tier with `autoscaling` attribute even despite the fact that they are empty.
213+
214+
- a lot of attributes that used to be collections (e.g. lists and sets) are converted to sigletons, e.g. `elasticsearch`, `apm`, `kibana`, `enterprise_search`, `observability`, `topology`, `autoscaling`, etc. Please note that, generally, users are not expected to make any change to their existing configuration to address this particular change (besides moving from block to attribute syntax). All these components used to exist in single instances, so the change is mostly syntactical, taking into account the switch to attributes instead of blocks (otherwise if we kept list for configs, `config {}` had to be rewritten in `config = [{}]` with the move to the attribute syntax). However this change is a breaking one from the schema perspective and requires state upgrade for existing resources that is performed by TF (by calling the provider's API).
215+
216+
- [`strategy` attribute](https://registry.terraform.io/providers/elastic/ec/latest/docs/resources/ec_deployment#strategy) is converted to string with the same set of values that was used for its `type` attribute previously;
217+
218+
- switching to TF protocol 6. From user perspective it should not require any change in their existing configurations.
219+
220+
#### Moving to the provider v0.6.0.
221+
222+
The schema modifications means that a current TF state cannot work as is with the provider version 0.6.0 and higher.
223+
224+
There are 2 ways to tackle this
225+
226+
- import existing resource using deployment ID, e.g `terraform import 'ec_deployment.test' <deployment_id>`
227+
- state upgrade that is performed by TF by calling the provider's API so no action is required from users
228+
229+
Currently the state upgrade functionality is not implemented so importing existing resources is the recommended way to deal with existing TF states.
230+
Please mind the fact that state import doesn't import user passwords and secret tokens that can be the case if your TF modules make use of them.
231+
State upgrade doesn't have this limitation.
232+
233+
#### Known issues of moving to the provider v0.6.0
234+
235+
- Older versions of terraform CLI can report errors with the provider 0.6.0 and higher. Please make sure to update Terraform CLI to the latest version.
236+
237+
- Starting from the provider v0.6.0, `terraform plan` output can contain more changes comparing to the older versions of the provider (that use TF SDK v2).
238+
This happens because TF Framework treats all `computed` attributes as `unknown` (known after apply) once configuration changes.
239+
However, it doesn't mean that all attributes that marked as `unknown` in the plan will get new values after apply.
240+
241+
- After import, the next plan command can output more elements that the actual configuration defines, e.g. plan command can output `cold` Elasticsearch tier with 0 size or empty `config` block for configuration that doesn't specify `cold` tier and `config` for `elasticsearch`.
242+
It should not be a problem. You can eigher execute the plan (the only result should be updated Terraform state while the deployment should stay the same) or add empty `cold` tier and `confg` to the configuration.
243+
244+
- The migration is based on 0.4.1, so all changes from 0.5.0 are omitted.

build/Makefile.deps

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ ARCH_GORELEASER:=$(shell $(PWD)/scripts/uname_arch_goreleaser.sh)
55
VERSION_DIR:=$(GOBIN)/versions
66

77
VERSION_GOLICENSER:=v0.3.0
8-
VERSION_GOLANGCILINT:=v1.49.0
8+
VERSION_GOLANGCILINT:=v1.50.0
99
VERSION_GORELEASER:=v1.15.2
1010
VERSION_GOCHANGELOG:=v0.0.0-20201005170154-56335215ce3a
1111
VERSION_VERSIONBUMP:=v1.1.0

build/Makefile.test

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ SWEEP_DIR ?= $(TEST_ACC)
33
SWEEP_CI_RUN_FILTER ?= ec_deployments
44
TEST ?= ./...
55
TEST_COUNT ?= 1
6-
TESTUNITARGS ?= -timeout 10s -p 4 -race -cover -coverprofile=reports/c.out
6+
TESTUNITARGS ?= -timeout 10m -race -cover -coverprofile=reports/c.out
77
TEST_ACC ?= github.com/elastic/terraform-provider-ec/ec/acc
88
TEST_NAME ?= TestAcc
99
TEST_ACC_PARALLEL = 6
@@ -26,7 +26,7 @@ unit: _report_path
2626
tests: unit
2727

2828
.PHONY: testacc
29-
## Runs the Terraform acceptance tests. Use TEST_NAME, TESTARGS, TEST_COUNT and TEST_ACC_PARALLEL to control execution.
29+
## Runs the Terraform acceptance tests. Use TEST_NAME, TESTARGS, TEST_COUNT to control execution.
3030
testacc:
3131
@ echo "-> Running terraform acceptance tests..."
3232
@ TF_ACC=1 go test $(TEST_ACC) -v -count $(TEST_COUNT) -parallel $(TEST_ACC_PARALLEL) $(TESTARGS) -timeout 120m -run $(TEST_NAME)

docs/data-sources/ec_stack.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ description: |-
44
Retrieves information about an Elastic Cloud stack.
55
---
66

7-
# Data Source: ec_deployment
7+
# Data Source: ec_stack
88

99
Use this data source to retrieve information about an existing Elastic Cloud stack.
1010

docs/guides/configuring-sso-ec-deployment.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,27 +31,27 @@ resource "ec_deployment" "elastic-sso" {
3131
version = "7.17.5"
3232
deployment_template_id = "aws-compute-optimized-v3"
3333
34-
elasticsearch {
35-
topology {
36-
id = "hot_content"
34+
elasticsearch = {
35+
hot = {
3736
size = "8g"
3837
zone_count = 2
3938
}
4039
41-
topology {
42-
id = "warm"
40+
warm = {
4341
size = "8g"
4442
zone_count = 2
4543
}
4644
47-
config {
45+
config = {
4846
# The URL domain suffix that is used in this example is often different for other Elasticsearch Service regions. Please check the appropriate domain suffix for your used region.
4947
user_settings_yaml = templatefile("./es.yml", { kibana_url = format("https://%s-%s.kb.us-east-1.aws.found.io:9243", var.name, substr("${random_uuid.uuid.result}", 0, 6)) })
5048
}
5149
}
5250
53-
kibana {
54-
config {
51+
kibana = {
52+
topology = {}
53+
54+
config = {
5555
user_settings_yaml = file("./kb.yml")
5656
}
5757
}
@@ -71,7 +71,7 @@ You will configure the deployment alias field to be the same, so if the deployme
7171
Then, by using a variable in the `es.yml` file and a terraform templating mechanism, you can generate your own `es.yml` file. Your variable is named kibana_url, as seen in the ec_deployment resource:
7272

7373
```hcl
74-
config {
74+
config = {
7575
user_settings_yaml = templatefile("./es.yml", { kibana_url = format("https://%s-%s.kb.us-east-1.aws.found.io:9243", var.name, substr("${random_uuid.uuid.result}", 0, 6)) })
7676
}
7777
```

0 commit comments

Comments
 (0)