Skip to content

Commit 2de87c6

Browse files
authored
Feature/530/migrate to plugin framework (#2)
1 parent 04c3cb6 commit 2de87c6

File tree

282 files changed

+24962
-17761
lines changed

Some content is hidden

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

282 files changed

+24962
-17761
lines changed

.changelog/507.txt

Lines changed: 0 additions & 3 deletions
This file was deleted.

.changelog/547.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:feature
2+
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.
3+
```

.github/workflows/branch.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ jobs:
3535
echo ::set-output name=BRANCH::$(echo ${BRANCH} | cut -d '.' -f1-2 | tr -d 'v')
3636
3737
- name: Create a github branch
38-
uses: peterjgrainger/action-create-branch@v2.2.0
38+
uses: peterjgrainger/action-create-branch@v2.3.0
3939
env:
4040
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
4141
with:

CHANGELOG.md

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,23 @@
1-
# 0.5.0 (Unreleased)
1+
# 0.6.0 (Unreleased)
22

33
FEATURES:
44

5+
* 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))
6+
7+
# 0.5.0 (Oct 12, 2022)
8+
9+
FEATURES:
10+
11+
* datasource/privatelink: Adds data sources to obtain AWS/Azure Private Link, and GCP Private Service Connect configuration data. ([#533](https://github.com/elastic/terraform-provider-ec/issues/533))
12+
* resource/deployment: Adds fleet_https_endpoint and apm_https_endpoint to integrations server resources. This allows consumers to explicitly capture service urls for dependent modules. ([#548](https://github.com/elastic/terraform-provider-ec/issues/548))
513
* resource/elasticsearch: Adds support for the `strategy` property to the `elasticsearch` resource. This allows users to define how different plan changes are coordinated. ([#507](https://github.com/elastic/terraform-provider-ec/issues/507))
614

15+
BUG FIXES:
16+
17+
* resource/deployment: Correctly restrict stateless (Kibana/Enterprise Search/Integrations Server) resources to a single topology element. Fixes a provider crash when multiple elements without an instance_configuration_id were specified. ([#536](https://github.com/elastic/terraform-provider-ec/issues/536))
18+
* resource/elasticsearchkeystore: Correctly delete keystore items when removed from the module definition. ([#546](https://github.com/elastic/terraform-provider-ec/issues/546))
19+
* resource: Updates all nested field accesses to validate type casts. This prevents a provider crash when a field is explicitly set to `null`. ([#534](https://github.com/elastic/terraform-provider-ec/issues/534))
20+
721
# 0.4.1 (May 11, 2022)
822

923
BREAKING CHANGES:

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
SHELL := /bin/bash
22
export GO111MODULE ?= on
3-
export VERSION := 0.5.0-dev
3+
export VERSION := 0.6.0-dev
44
export BINARY := terraform-provider-ec
55
export GOBIN = $(shell pwd)/bin
66

NOTICE

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ third-party software developed by the licenses listed below.
88

99
github.com/davecgh/go-spew 0BSD
1010
github.com/agext/levenshtein Apache-2.0
11-
github.com/apparentlymart/go-textseg/v13 Apache-2.0
1211
github.com/elastic/cloud-sdk-go Apache-2.0
1312
github.com/go-openapi/analysis Apache-2.0
1413
github.com/go-openapi/errors Apache-2.0
@@ -60,22 +59,23 @@ github.com/mitchellh/reflectwalk MIT
6059
github.com/stretchr/testify MIT
6160
github.com/zclconf/go-cty MIT
6261
github.com/hashicorp/errwrap MPL-2.0
63-
github.com/hashicorp/go-checkpoint MPL-2.0
64-
github.com/hashicorp/go-cleanhttp MPL-2.0
6562
github.com/hashicorp/go-multierror MPL-2.0
66-
github.com/hashicorp/go-plugin MPL-2.0
6763
github.com/hashicorp/go-uuid MPL-2.0
68-
github.com/hashicorp/go-version MPL-2.0
69-
github.com/hashicorp/hc-install MPL-2.0
7064
github.com/hashicorp/hcl/v2 MPL-2.0
65+
github.com/hashicorp/logutils MPL-2.0
66+
github.com/hashicorp/terraform-exec MPL-2.0
7167
github.com/hashicorp/terraform-json MPL-2.0
7268
github.com/hashicorp/terraform-plugin-go MPL-2.0
73-
github.com/hashicorp/terraform-plugin-log MPL-2.0
74-
github.com/hashicorp/terraform-plugin-sdk/v2 MPL-2.0
7569
github.com/hashicorp/terraform-registry-address MPL-2.0
76-
github.com/hashicorp/logutils MPL-2.0-no-copyleft-exception
77-
github.com/hashicorp/terraform-exec MPL-2.0-no-copyleft-exception
70+
github.com/hashicorp/yamux MPL-2.0
71+
github.com/hashicorp/go-checkpoint MPL-2.0-no-copyleft-exception
72+
github.com/hashicorp/go-cleanhttp MPL-2.0-no-copyleft-exception
73+
github.com/hashicorp/go-plugin MPL-2.0-no-copyleft-exception
74+
github.com/hashicorp/go-version MPL-2.0-no-copyleft-exception
75+
github.com/hashicorp/hc-install MPL-2.0-no-copyleft-exception
76+
github.com/hashicorp/terraform-plugin-log MPL-2.0-no-copyleft-exception
77+
github.com/hashicorp/terraform-plugin-sdk/v2 MPL-2.0-no-copyleft-exception
7878
github.com/hashicorp/terraform-svchost MPL-2.0-no-copyleft-exception
79-
github.com/hashicorp/yamux MPL-2.0-no-copyleft-exception
79+
github.com/apparentlymart/go-textseg/v13 Unicode-TOU
8080

8181
=========================================================================

README.md

Lines changed: 125 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ terraform {
3232
required_providers {
3333
ec = {
3434
source = "elastic/ec"
35-
version = "0.5.0"
35+
version = "0.6.0"
3636
}
3737
}
3838
}
@@ -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,119 @@ $ 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+
v6.0.0 contains migration to [the TF Plugin Framework](https://developer.hashicorp.com/terraform/plugin/framework) and intoducing version 2 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 `config {}` has to be changed to `config = {}`, 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 configuration explicitly mentions `hot` tier and the tier has `autoscaling` and `config` attributes even despite the fact that they are empty. If they were omitted, TF (at least up to version 1.3.3) could complain `Error: Provider produced inconsistent result after apply`.
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+
#### Migration guide.
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 user perspective
228+
229+
Currently the state upgrade functionality is still in development so importing existing resources is the recommended way to deal with existing TF states.
230+
231+
#### Known issues.
232+
233+
For the migrated version (0.6.0 or higher), `terraform plan` output can contain more changes comparing to the older versions of the provider (that use TF SDK).
234+
This happens because TF Framework treats all `computed` attributes as `unknown` (known after apply) once configuration changes.
235+
`ec_deployment` schema contains quite a few of such attributes, so `terraform plan`'s output can be quite big for the resource due to the mentioned reason.
236+
However, it doesn't mean that all attributes that marked as `unknown` in the plan will get new values after apply.
237+
To mitigitate the problem, the provider uses plan modifiers that is a recommended way to reduce plan output.
238+
However, currently plan modifiers don't cover the all `computed` attributes.

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.2.5
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 30s -p 4 -race -cover -coverprofile=reports/c.out
6+
TESTUNITARGS ?= -timeout 5m -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)

build/Makefile.tools

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11

22
VERSION_TFPROVIDERDOCS:=v0.6.0
3-
VERSION_TERRAFMT:=12db38d
3+
VERSION_TERRAFMT:=v0.5.2
44
VERSION_TFPROVIDERLINT:=v0.28.1
55

66
## Installs the required static checks for terraform.

0 commit comments

Comments
 (0)