terraform-provider-ec icon indicating copy to clipboard operation
terraform-provider-ec copied to clipboard

ec_stack lock not working

Open jorik90 opened this issue 4 years ago • 3 comments

The lock option of the datasource ec_stack does not work.

Readiness Checklist

  • [x] I am running the latest version
  • [x] I checked the documentation and found no answer
  • [x] I checked to make sure that this issue has not already been filed
  • [x] I am reporting the issue to the correct repository (for multi-repository projects)

Expected Behavior

I expect the version of Elastic is not changed after the initial apply when I set the lock-option to true.

Current Behavior

Setting the lock option does nothing.

## Terraform definition

terraform {
  required_providers {
    ec = {
      source  = "elastic/ec"
      version = "0.4.0"
    }
  }
}

provider "ec" {
  apikey = "xx"
}


data "ec_stack" "version" {
  version_regex = "7.?"  # after initial deploy, set to "latest" and manually change the state. Only required for reproducing.
  region        = "azure-westeurope"
  lock = true
}

output "test" {
  value = data.ec_stack.version.version
}

Steps to Reproduce

To reproduce:

  1. Run the terraform code (terraform apply) to get a terraform state with an ec_stack dataresource
  2. Open the tfstate JSON and modify the version_regex value to latest
  3. In the terraform code, modify the version_regex to latest
  4. Run terraform plan (or apply) again. The version should not changed because it is locked. In stead, it is changed to the latest 8.x version.

The only other way to reproduce this is to wait for a new version, which is what will happen when using this normally.

Context

I only want Elasticcloud to update the clusters when we approve so (by removing the lock option temporary). When making other changes to the cluster, we don't want an unexpected upgrade.

The workaround is to add the version to the lifecycle ignore_changes. But this can't be managed in a dynamic way.

Possible Solution

In the code the version stored in the state is being retrieved (https://github.com/elastic/terraform-provider-ec/blob/b6ef696cdd34c302b4a0cc9c2c3edf6c95a08d7a/ec/ecdatasource/stackdatasource/datasource.go#L63). According to my understanding of Terraform it is not possible to retrieve the current state without some extra effort.

Sidenote: if this get fixed, another problem will probably arise. The API call for getting the versions only returns some versions. If the version is locked on 1.17.0 (which is replaced by 1.17.1) it will give the error failed to obtain a stack version matching 1.17.1. That way the lock option still is not really usable.

Your Environment

  • Version used: 7.x and 8.x
  • Running against Elastic Cloud SaaS
  • Environment name and version (e.g. Go 1.9): Terraform 1.1.3 with the ec provider 0.4.0 from the registry
  • Server type and version: n/a
  • Operating System and version: Mac OS X 11.6.2
  • Link to your project: n/a

jorik90 avatar Mar 01 '22 16:03 jorik90

It looks like lock argument works only when version_regex is set to "latest". If so we need to update the docs.

dimuon avatar Aug 16 '22 12:08 dimuon

@dimuon any progress on this one?

d-carmo avatar Jun 06 '23 12:06 d-carmo

@d-carmo , No, we didn't investigate this further.

dimuon avatar Jun 06 '23 12:06 dimuon