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

Is import compatible with force_new? #279

Open
drdkmkkr opened this issue Dec 12, 2024 · 0 comments
Open

Is import compatible with force_new? #279

drdkmkkr opened this issue Dec 12, 2024 · 0 comments

Comments

@drdkmkkr
Copy link

Hi,

Can import be used with force_new in any way, without instantly destroying ? 🤔

Example:

provider "restapi" {
  uri = "https://api.restful-api.dev"
}

import {
  id = "/objects/7"
  to = restapi_object.test
}

locals {
  name = "test"
}

resource "restapi_object" "test" {
  data = jsonencode({
    name = local.name
  })
  path = "/objects"
  force_new = [
    local.name
  ]
}

Results in:

Terraform will perform the following actions:

  # restapi_object.test must be replaced
  # (imported from "/objects/7")
  # Warning: this will destroy the imported resource
-/+ resource "restapi_object" "test" {
      ~ api_data        = {
          - "data" = "map[CPU model:Intel Core i9 Hard disk size:1 TB price:1849.99 year:2019]"
          - "id"   = "7"
          - "name" = "Apple MacBook Pro 16"
        } -> (known after apply)
      ~ api_response    = jsonencode(
            {
              - data = {
                  - "CPU model"      = "Intel Core i9"
                  - "Hard disk size" = "1 TB"
                  - price            = 1849.99
                  - year             = 2019
                }
              - id   = "7"
              - name = "Apple MacBook Pro 16"
            }
        ) -> (known after apply)
      + create_response = (known after apply)
      ~ data            = jsonencode(
          ~ {
              - id   = "7"
              + name = "test"
            }
        )
      - debug           = true -> null
      + force_new       = [ # forces replacement
          + "test",
        ]
      ~ id              = "7" -> (known after apply)
        path            = "/objects"
    }

Plan: 1 to import, 1 to add, 0 to change, 1 to destroy.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant