Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/530/migrate to plugin framework #567

Merged
merged 107 commits into from
Feb 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
107 commits
Select commit Hold shift + click to select a range
0627d93
Introduce mux and port the provider to v6.
dimuon Sep 6, 2022
2213f86
Update required version of CLI in examples
dimuon Sep 6, 2022
cf373db
Increase TF verson in github workflow
dimuon Sep 6, 2022
043bbe7
Merge pull request #1 from dimuon/feature/530/ec-deployment
dimuon Sep 7, 2022
2194ad3
Migrate data sources to terraform-provider-framework
pascal-hofmann Aug 31, 2022
1c61d77
Merge pull request #3 from dimuon/feature/530/port-datasources
dimuon Sep 8, 2022
a5de6e9
Migrate resource ec_deployment_traffic_filter_association to terrafor…
dimuon Sep 7, 2022
b7c8e23
Merge pull request #5 from dimuon/feature/530/ec-trafficfilterassoc-only
dimuon Sep 15, 2022
8a79970
Update to terraform-plugin-framework 0.12 and fix import order
pascal-hofmann Sep 15, 2022
6136a1c
Merge pull request #6 from dimuon/feature/530/terraform-plugin-framew…
dimuon Sep 15, 2022
c197f28
Migrate resource ec_deployment_traffic_filter to terraform-provider-f…
pascal-hofmann Sep 18, 2022
c4aebde
Merge pull request #8 from dimuon/feature/530/trafficfilterresource
dimuon Sep 21, 2022
2084e39
Use blocks and ListNestedAttributes for nested schemas in datasources
pascal-hofmann Sep 21, 2022
993d47d
Migrate resource ec_deployment_elasticsearch_keystore to terraform-pl…
pascal-hofmann Sep 23, 2022
b00e28a
Update dependencies and remove external provider workaround from migr…
pascal-hofmann Sep 23, 2022
07aecc1
Merge pull request #11 from dimuon/update-dependencies
dimuon Sep 23, 2022
f310127
Migrate resource ec_deployment_extension to terraform-plugin-framewor…
pascal-hofmann Oct 18, 2022
320fb77
Feature/530/migrate to plugin framework (#2)
dimuon Dec 7, 2022
40f4e5d
skip acceptance tests for checking upgrade from 0.4.1
dimuon Dec 7, 2022
9d7c37b
Merge remote-tracking branch 'upstream/master' into feature/530/migra…
dimuon Dec 7, 2022
0f9eab6
remove leftovers that came after 0.4.1
dimuon Dec 7, 2022
a52f732
update go.mod
dimuon Dec 7, 2022
548a37b
Update changelog
dimuon Dec 7, 2022
50623f9
address PR comments in README
dimuon Dec 7, 2022
e244094
remove obsolete space
dimuon Dec 7, 2022
58b16d5
Address PR comments in provider_config.go
dimuon Dec 13, 2022
51f1eaa
Improve default_value plan modifier
dimuon Dec 13, 2022
d449931
remove obsolete var
dimuon Dec 13, 2022
b51e74a
improve schemas
dimuon Dec 13, 2022
34daf0f
remove obsolete code
dimuon Dec 14, 2022
dd0508b
remove incorrect comment
dimuon Dec 14, 2022
947e8b2
remove obsolete var
dimuon Dec 14, 2022
dfd6060
address PR comments
dimuon Dec 14, 2022
7f676f5
Remove obsolete function
dimuon Dec 19, 2022
345a341
Move provider data to an anonymous struct
dimuon Dec 20, 2022
bd05967
unit test for provider Config
dimuon Dec 20, 2022
f90f2c8
improve provider tests + address PR comments
dimuon Dec 21, 2022
b0bda3b
Refactor provider + address PR comments
dimuon Dec 21, 2022
99b3745
address PR comments
dimuon Dec 21, 2022
8c396b2
use plan modifiers from Hashicorp where possible
dimuon Dec 21, 2022
0df8f99
refactor ExtractEndpointsTF
dimuon Dec 21, 2022
f194f76
conversion funcs renaming
dimuon Dec 21, 2022
0675863
remove obsolete comment
dimuon Dec 21, 2022
4fa42b2
Apply suggestions from code review
dimuon Dec 22, 2022
0556078
remove obsolete comments in v1 schemas
dimuon Dec 22, 2022
7277f41
split apm and deployment in deploymentresource to read and payload files
dimuon Dec 22, 2022
d992a89
renaming and removing obsolete code
dimuon Dec 22, 2022
8cf3c54
split elasticsearch to read and payload files
dimuon Dec 22, 2022
c8ad85e
split enterprise_search files to read and payload
dimuon Dec 22, 2022
f323cf1
split integrations_server files to read and payload
dimuon Dec 22, 2022
a312dca
split kibana files to read and payload
dimuon Dec 22, 2022
3000ee3
split observability files to read and payload
dimuon Dec 22, 2022
4ae31c9
fix description
dimuon Dec 22, 2022
a624e68
renaming and removing obsolete code
dimuon Dec 22, 2022
4edcc2d
Apply suggestions from code review
dimuon Dec 22, 2022
39a1c43
endpoints extractions: use the converter func instead of the one from…
dimuon Dec 22, 2022
ebc05cf
moving code around and some renaming
dimuon Dec 22, 2022
71c9660
fix lint errors
dimuon Dec 22, 2022
cca7a75
renaming
dimuon Dec 22, 2022
42a7c92
renaming and obsolete code removing
dimuon Dec 22, 2022
2d108e5
renaming according to PR comments
dimuon Dec 27, 2022
b460efb
renaming + incorrect comment removal
dimuon Dec 27, 2022
b1862d4
fix unit test
dimuon Dec 27, 2022
8c938b1
convert 'elasticsearch' 'autoscale' attribute to bool type
dimuon Dec 27, 2022
395a3bc
remove TODOs for DiffSupressFunc
dimuon Dec 27, 2022
894bdb5
unit test for handling traffic rules
dimuon Dec 27, 2022
6a92321
move files from utils to dedicated resource packages
dimuon Dec 28, 2022
a2ce9d4
unit tests for UseNodeRoles
dimuon Dec 28, 2022
663167f
(WIP) Bring back logic of migrating node_types to node_roles
dimuon Dec 30, 2022
f0ca456
Improve node_type detection
dimuon Jan 3, 2023
8f14a40
improve and rearrange node_types plan modifier
dimuon Jan 4, 2023
0e50ae7
enable test for UseNodeRoles + minor refactoring
dimuon Jan 4, 2023
e11db61
unit tests for node_types and node_roles modifiers
dimuon Jan 4, 2023
4800d9d
renaming + obsolete code removal
dimuon Jan 5, 2023
3b4e53c
unit test for topology plan modifer + some refactoring
dimuon Jan 5, 2023
8d90524
deploymentdatasource: change flatteners to return the result
dimuon Jan 11, 2023
7400f7c
remove obsolete utility funcs
dimuon Jan 11, 2023
c0924dd
renaming local var
dimuon Jan 11, 2023
6c507cf
fix converion to attr.Value in deploymentdatasource
dimuon Jan 12, 2023
fc8a6cf
deploymentresource read - remove conversion to TF types
dimuon Jan 13, 2023
8e8a85c
Fix description an error messages. Remove obsolete TODO
dimuon Jan 13, 2023
07a5908
minor improvements for deploymentresource tests
dimuon Jan 13, 2023
a36caba
Replace any interface arg with returned type in stackdatasource
dimuon Jan 13, 2023
d1208af
Renaming
dimuon Jan 13, 2023
dda3586
move ResourceKind to util
dimuon Jan 13, 2023
2b07835
Replace any interface arg with returned type in trafficfilterresource
dimuon Jan 13, 2023
b30c207
add missing file
dimuon Jan 13, 2023
42fd243
Update NOTICE
dimuon Jan 13, 2023
ed86516
Merge branch 'master' into feature/530/migrate-to-plugin-framework
dimuon Jan 13, 2023
c60b15c
Update NOTICE
dimuon Jan 13, 2023
d3263ff
Fixing description for Enterprise Search
dimuon Jan 16, 2023
ef276f8
Update README - add a note for updaint the TF client
dimuon Jan 18, 2023
a2d6a62
Fix examples
dimuon Jan 19, 2023
422d45e
Apply suggestions from code review
dimuon Jan 23, 2023
ef67aa5
Addres PR comments - fix descriptions and scope of definitions
dimuon Jan 23, 2023
2fef8e6
update comment
dimuon Jan 23, 2023
5e31465
fix description
dimuon Jan 24, 2023
75c16c3
remove incorrect comments
dimuon Jan 24, 2023
e221610
Remove obsolete plan modifier for elasticsearch topology zone_count
dimuon Jan 24, 2023
511a7b7
fix validations for elasticsearch remote_cluster
dimuon Jan 25, 2023
1bfd39e
fix regex expressions in acc tests for pre node_roles
dimuon Feb 6, 2023
b420c80
explicit separation between plan and state in read
dimuon Feb 7, 2023
06bf06e
Update TF Framework to 1.1.1
dimuon Feb 7, 2023
172c654
Merge remote-tracking branch 'upstream/master' into feature/530/migra…
dimuon Feb 22, 2023
432ce9b
Address PR review comments
dimuon Feb 23, 2023
9b6cc51
Revert "Update TF Framework to 1.1.1" and "Address PR review comments"
dimuon Feb 24, 2023
35c633c
Update README and CHANGELOG
dimuon Feb 27, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
3 changes: 2 additions & 1 deletion .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ jobs:
- name: Install terraform
uses: hashicorp/setup-terraform@v2
with:
terraform_version: "0.14.x"
terraform_version: "1.x.x"
terraform_wrapper: false

- name: Cache Go Modules
uses: actions/cache@v3
Expand Down
28 changes: 27 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,37 @@
# 0.6.0 (Unreleased)
# 0.7.0 (Unreleased)

# 0.5.1 (Feb 15, 2023)

FEATURES:

* 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))

# 0.6.0 (Unreleased)

FEATURES:

Migration to [TF Plugin Framework](https://developer.hashicorp.com/terraform/plugin/framework)

**BREAKING CHANGES**:

New schema for `ec_deployment`. Existing resources should be imported. Please see NOTES below and README for more details.

BUG FIXES:

[#336](https://github.com/elastic/terraform-provider-ec/issues/336)
[#467](https://github.com/elastic/terraform-provider-ec/issues/467)
[#445](https://github.com/elastic/terraform-provider-ec/issues/445)

NOTES

* 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.
* State upgrade is not implemented for `ec_deployment`.
The recommended way to proceed with existing TF resources is [state import](https://developer.hashicorp.com/terraform/cli/import#state-only).
However, this doesn't import user passwords and secret tokens.
* 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`.
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.
* The migration is based on 0.4.1, so all changes from 0.5.0 are omitted.

# 0.5.0 (Oct 12, 2022)

FEATURES:
Expand Down
2 changes: 1 addition & 1 deletion NOTICE
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
terraform-provider-ec
Copyright 2023 Elasticsearch B.V.
Copyright 2022-2023 Elasticsearch B.V.

This product includes software developed at Elasticsearch B.V. and
third-party software developed by the licenses listed below.
Expand Down
132 changes: 130 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,15 @@ resource "ec_deployment" "example_minimal" {
deployment_template_id = "aws-io-optimized-v2"

# Use the deployment template defaults
elasticsearch {}
elasticsearch = {
hot = {
autoscaling = {}
}
}

kibana {}
kibana = {
topology = {}
}
}
```

Expand Down Expand Up @@ -114,3 +120,125 @@ $ export EC_API_KEY="<apikey value>"
```

After doing so, you can navigate to any of our examples in `./examples` and try one.

### Moving to TF Framework and schema change for `ec_deployment` resource.

v0.6.0 contains migration to [TF Plugin Framework](https://developer.hashicorp.com/terraform/plugin/framework) and intoduces new schema for `ec_deployment` resource:

- 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.

```hcl
resource "ec_deployment" "defaults" {
name = "example"
region = "us-east-1"
version = data.ec_stack.latest.version
deployment_template_id = "aws-io-optimized-v2"

elasticsearch = {
hot = {
autoscaling = {}
}
}

kibana = {
topology = {}
}

enterprise_search = {
zone_count = 1
}
}
```

- `topology` attribute of `elasticsearch` is replaced with a number of dedicated attributes, one per tier, e.g.

```
elasticsearch {
topology {
id = "hot_content"
size = "1g"
autoscaling {
max_size = "8g"
}
}
topology {
id = "warm"
size = "2g"
autoscaling {
max_size = "15g"
}
}
}
```

has to be converted to

```
elasticsearch = {
hot = {
size = "1g"
autoscaling = {
max_size = "8g"
}
}

warm = {
size = "2g"
autoscaling = {
max_size = "15g"
}
}
}

```

- 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

```hcl
resource "ec_deployment" "defaults" {
name = "example"
region = "us-east-1"
version = data.ec_stack.latest.version
deployment_template_id = "aws-io-optimized-v2"

elasticsearch = {
hot = {
autoscaling = {}
}
}
}
```

Please note that the snippet explicitly mentions `hot` tier with `autoscaling` attribute even despite the fact that they are empty.

- 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).

- [`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;

- switching to TF protocol 6. From user perspective it should not require any change in their existing configurations.

#### Moving to the provider v0.6.0.

The schema modifications means that a current TF state cannot work as is with the provider version 0.6.0 and higher.

There are 2 ways to tackle this

- import existing resource using deployment ID, e.g `terraform import 'ec_deployment.test' <deployment_id>`
dimuon marked this conversation as resolved.
Show resolved Hide resolved
- state upgrade that is performed by TF by calling the provider's API so no action is required from users

Currently the state upgrade functionality is not implemented so importing existing resources is the recommended way to deal with existing TF states.
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.
State upgrade doesn't have this limitation.

#### Known issues of moving to the provider v0.6.0

- 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.

- 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).
This happens because TF Framework treats all `computed` attributes as `unknown` (known after apply) once configuration changes.
However, it doesn't mean that all attributes that marked as `unknown` in the plan will get new values after apply.

- 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`.
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.

- The migration is based on 0.4.1, so all changes from 0.5.0 are omitted.
2 changes: 1 addition & 1 deletion build/Makefile.deps
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ ARCH_GORELEASER:=$(shell $(PWD)/scripts/uname_arch_goreleaser.sh)
VERSION_DIR:=$(GOBIN)/versions

VERSION_GOLICENSER:=v0.3.0
VERSION_GOLANGCILINT:=v1.49.0
VERSION_GOLANGCILINT:=v1.50.0
VERSION_GORELEASER:=v1.15.2
VERSION_GOCHANGELOG:=v0.0.0-20201005170154-56335215ce3a
VERSION_VERSIONBUMP:=v1.1.0
Expand Down
4 changes: 2 additions & 2 deletions build/Makefile.test
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ SWEEP_DIR ?= $(TEST_ACC)
SWEEP_CI_RUN_FILTER ?= ec_deployments
TEST ?= ./...
TEST_COUNT ?= 1
TESTUNITARGS ?= -timeout 10s -p 4 -race -cover -coverprofile=reports/c.out
TESTUNITARGS ?= -timeout 10m -race -cover -coverprofile=reports/c.out
TEST_ACC ?= github.com/elastic/terraform-provider-ec/ec/acc
TEST_NAME ?= TestAcc
TEST_ACC_PARALLEL = 6
Expand All @@ -26,7 +26,7 @@ unit: _report_path
tests: unit

.PHONY: testacc
## Runs the Terraform acceptance tests. Use TEST_NAME, TESTARGS, TEST_COUNT and TEST_ACC_PARALLEL to control execution.
## Runs the Terraform acceptance tests. Use TEST_NAME, TESTARGS, TEST_COUNT to control execution.
testacc:
@ echo "-> Running terraform acceptance tests..."
@ TF_ACC=1 go test $(TEST_ACC) -v -count $(TEST_COUNT) -parallel $(TEST_ACC_PARALLEL) $(TESTARGS) -timeout 120m -run $(TEST_NAME)
Expand Down
2 changes: 1 addition & 1 deletion docs/data-sources/ec_stack.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ description: |-
Retrieves information about an Elastic Cloud stack.
---

# Data Source: ec_deployment
# Data Source: ec_stack

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

Expand Down
18 changes: 9 additions & 9 deletions docs/guides/configuring-sso-ec-deployment.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,27 +31,27 @@ resource "ec_deployment" "elastic-sso" {
version = "7.17.5"
deployment_template_id = "aws-compute-optimized-v3"

elasticsearch {
topology {
id = "hot_content"
elasticsearch = {
hot = {
size = "8g"
zone_count = 2
}

topology {
id = "warm"
warm = {
size = "8g"
zone_count = 2
}

config {
config = {
# 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.
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)) })
}
}

kibana {
config {
kibana = {
topology = {}

config = {
user_settings_yaml = file("./kb.yml")
}
}
Expand All @@ -71,7 +71,7 @@ You will configure the deployment alias field to be the same, so if the deployme
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:

```hcl
config {
config = {
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)) })
}
```
Expand Down
Loading