Skip to content

[Bug] Import of elasticstack_elasticsearch_index_lifecycle missing name attributes #87

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

Closed
ghost opened this issue Mar 14, 2022 · 2 comments · Fixed by #92
Closed

[Bug] Import of elasticstack_elasticsearch_index_lifecycle missing name attributes #87

ghost opened this issue Mar 14, 2022 · 2 comments · Fixed by #92
Assignees
Labels
bug Something isn't working Elasticsearch Elasticsearch related APIs

Comments

@ghost
Copy link

ghost commented Mar 14, 2022

Describe the bug
After importing elasticstack_elasticsearch_index_lifecycle, the resource name in terraform state is null resulting in resource destroy & create upon next apply.

To Reproduce
Steps to reproduce the behavior:

  1. Create a new index lifecycle policy independently of terraform
  2. Create a matching terraform resource template
  3. Initialize terraform state and import the index lifecycle policy
  4. Run terraform plan. The expected result is no change.

Expected behavior
The imported resource is not destroyed or altered if there is no difference in configuration.

Debug output

Create ILM Policy

$ NO_PROXY="*" curl -k -XPUT -u "$ELASTICSEARCH_USERNAME:$ELASTICSEARCH_PASSWORD" $ELASTICSEARCH_ENDPOINTS/_ilm/policy/import_test --header 'Content-Type: application/json' --data-binary @- <<EOF
> {
>     "policy" : {
>       "phases" : {
>         "hot" : {
>           "min_age" : "0ms",
>           "actions" : {
>             "set_priority" : {
>               "priority" : 100
>             },
>             "rollover" : {
>               "max_primary_shard_size" : "50gb",
>               "max_age" : "30d"
>             }
>           }
>         }
>       }
>     }
>   }
>
> EOF
export CLUSTER_UUID=$(NO_PROXY="*" curl -ks -XGET -u "$ELASTICSEARCH_USERNAME:$ELASTICSEARCH_PASSWORD" $ELASTICSEARCH_ENDPOINTS/_cluster/stats | jq -r '.cluster_uuid')

Content of import_test.tf

provider "elasticstack" {
  elasticsearch {
    insecure = true
  }
}

resource "elasticstack_elasticsearch_index_lifecycle" "import_test" {
    name = "import_test"

    hot {
        min_age = "0ms"
        
        set_priority {
          priority = 100
        }

        rollover {
          max_age = "30d"
          max_primary_shard_size = "50gb"
          max_docs = 0
        }
    }

}

Terraform import and plan output

$ terraform init

Initializing the backend...

Initializing provider plugins...
- Finding latest version of hashicorp/elasticstack...
- Installing hashicorp/elasticstack v0.3.2...
- Installed hashicorp/elasticstack v0.3.2 (unauthenticated)

Terraform has created a lock file .terraform.lock.hcl to record the provider
selections it made above. Include this file in your version control repository
so that Terraform can guarantee to make the same selections by default when
you run "terraform init" in the future.

Terraform has been successfully initialized!

You may now begin working with Terraform. Try running "terraform plan" to see
any changes that are required for your infrastructure. All Terraform commands
should now work.

If you ever set or change modules or backend configuration for Terraform,
rerun this command to reinitialize your working directory. If you forget, other
commands will detect it and remind you to do so if necessary.


$ terraform import elasticstack_elasticsearch_index_lifecycle.import_test ${CLUSTER_UUID}/import_test
elasticstack_elasticsearch_index_lifecycle.import_test: Importing from ID "oG8TX0pmTwKyMCC2_sRMqw/import_test"...
elasticstack_elasticsearch_index_lifecycle.import_test: Import prepared!
  Prepared elasticstack_elasticsearch_index_lifecycle for import
elasticstack_elasticsearch_index_lifecycle.import_test: Refreshing state... [id=oG8TX0pmTwKyMCC2_sRMqw/import_test]

Import successful!

The resources that were imported are shown above. These resources are now in
your Terraform state and will henceforth be managed by Terraform.

$ terraform plan
elasticstack_elasticsearch_index_lifecycle.import_test: Refreshing state... [id=oG8TX0pmTwKyMCC2_sRMqw/import_test]

Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols:
-/+ destroy and then create replacement

Terraform will perform the following actions:

  # elasticstack_elasticsearch_index_lifecycle.import_test must be replaced
-/+ resource "elasticstack_elasticsearch_index_lifecycle" "import_test" {
      ~ id            = "oG8TX0pmTwKyMCC2_sRMqw/import_test" -> (known after apply)
      ~ modified_date = "2022-03-14T13:47:03.254Z" -> (known after apply)
      + name          = "import_test" # forces replacement

      ~ hot {
            # (1 unchanged attribute hidden)

          ~ rollover {
                # (3 unchanged attributes hidden)
            }

            # (1 unchanged block hidden)
        }
    }

Plan: 1 to add, 0 to change, 1 to destroy.

Content of terraform.tfstate after import

{
  "version": 4,
  "terraform_version": "1.1.5",
  "serial": 1,
  "lineage": "e7f36a04-4abd-a71d-ba06-2cfbdd51eaff",
  "outputs": {},
  "resources": [
    {
      "mode": "managed",
      "type": "elasticstack_elasticsearch_index_lifecycle",
      "name": "import_test",
      "provider": "provider[\"registry.terraform.io/hashicorp/elasticstack\"]",
      "instances": [
        {
          "schema_version": 0,
          "attributes": {
            "cold": [],
            "delete": [],
            "elasticsearch_connection": [],
            "frozen": [],
            "hot": [
              {
                "forcemerge": [],
                "min_age": "0ms",
                "readonly": [],
                "rollover": [
                  {
                    "max_age": "30d",
                    "max_docs": 0,
                    "max_primary_shard_size": "50gb",
                    "max_size": ""
                  }
                ],
                "searchable_snapshot": [],
                "set_priority": [
                  {
                    "priority": 100
                  }
                ],
                "shrink": [],
                "unfollow": []
              }
            ],
            "id": "oG8TX0pmTwKyMCC2_sRMqw/import_test",
            "metadata": null,
            "modified_date": "2022-03-14T14:24:32.230Z",
            "name": null,
            "warm": []
          },
          "sensitive_attributes": [],
          "private": "eyJzY2hlbWFfdmVyc2lvbiI6IjAifQ=="
        }
      ]
    }
  ]
}

Note

Adding the resource name import_test to terraform.tfstate manually results in the expected behavior on next plan/apply.

Screenshots
If applicable, add screenshots to help explain your problem.

Versions (please complete the following information):

  • OS: Windows AMD64
  • Terraform Version v1.1.5
  • Provider version v0.3.2
  • Elasticsearch Version v7.16.3

Additional context
Add any other context about the problem here.

@ghost ghost added the bug Something isn't working label Mar 14, 2022
@olksdr olksdr self-assigned this Mar 14, 2022
@olksdr olksdr added the Elasticsearch Elasticsearch related APIs label Mar 14, 2022
@olksdr
Copy link
Contributor

olksdr commented Mar 14, 2022

hey @sf-sharris,
thanks for opening this issue! I will take a look into this.

olksdr added a commit to olksdr/terraform-provider-elasticstack that referenced this issue Mar 17, 2022
@olksdr
Copy link
Contributor

olksdr commented Mar 22, 2022

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working Elasticsearch Elasticsearch related APIs
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant