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

Import fleet package policy #25

Open
breml opened this issue Oct 27, 2023 · 2 comments
Open

Import fleet package policy #25

breml opened this issue Oct 27, 2023 · 2 comments
Labels
question Further information is requested

Comments

@breml
Copy link

breml commented Oct 27, 2023

Hi @andrewkroh

Sorry for approaching you directly this way.

I found this repository by your mention in elastic/terraform-provider-elasticstack#89 (comment) . I was able to use the https://github.com/Mastercard/restapi provider to create fleet package policies. In this case also the further life cycle does work pretty well. But now I have an existing Elasticstack deployment (in Elastic Cloud) where I need to import the current state into terraform. Importing resources with the https://github.com/Mastercard/restapi provider is somewhat supported, but basically it just creates the necessary "link" between the terraform configuration and the resource (by linking the configuration to the ID) and if I run terraform plan right after the import, the complete resource is reported as changed without presenting a proper diff. Therefore it is always unclear, if the configuration I have in terraform actually does match the configuration in the cluster, which leaves me with unease.

Given this situation, I have the following questions:

  1. Do you know how to import resources (in particular fleet package policy) with the https://github.com/Mastercard/restapi such that after the import terraform plan does show no differences?
  2. Do you have a time plan, when progress on #elastic/terraform-provider-elasticstack/89 can be expected?
  3. Would a contribution to #elastic/terraform-provider-elasticstack/89 make sense at this point and would it be reviewed / accepted in due time?
@andrewkroh
Copy link
Owner

and if I run terraform plan right after the import, the complete resource is reported as changed without presenting a proper diff.

I wonder why you are not getting a diff. Is that because some variables are marked as sensitive = true? If you use terraform plan with the -json and -out=file are you able to see a diff?

Do you know how to import resources (in particular fleet package policy) with the https://github.com/Mastercard/restapi such that after the import terraform plan does show no differences?

No, I haven't tried. This assumes you are creating package policies (setting up the module variables) to match what you had in Fleet. As you probably know, terraform import imports the state for you, but it does not generate the ".tf" config for what you imported so this could be error prone (hence I understand your uneasiness). I think if you could get a diff from terraform plan that would help clue us in on where the problem lies (maybe terraform-provider-restapi doesn't behave like expected or maybe the resource doesn't match what's in fleet).

Do you have a time plan, when progress on #elastic/terraform-provider-elasticstack/89 can be expected?

I see that there is a PR open for those resources at https://github.com/elastic/terraform-provider-elasticstack/pull/454. So it's probably a matter of getting that reviewed and tested.

@breml
Copy link
Author

breml commented Oct 30, 2023

Hi @andrewkroh

Thanks for you response and especially thanks for pointing me to https://github.com/elastic/terraform-provider-elasticstack/pull/454, I was not yet aware of this PR.

I am well aware, that terraform import does not create the .tf files and I have created them my self. The issue is more related to how the restapi provider does work (and to some extend what terraform allows during import from a providers point of view). The restapi provider does store the data generated by terrafrom apply as well as the response from the api as two separate entities into the terraform state. This allows to detect if either side (terraform config or the response from the API) do change, but the two sources are not linked further. Therefore during import, the response from the API is stored to the terraform state, but the data calculated by terraform apply is missing (only the ID of the resource gets stored to the terrafrom state). If one then runs terraform apply after terraform import a diff is shown where it looks like all the attributes in the JSON object are added since in the terraform state the only thing that is stored is the id.

@andrewkroh andrewkroh added the question Further information is requested label Mar 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants