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

Read Datastream upon resource_already_exists_exception #341

Open
applike-ss opened this issue Mar 2, 2023 · 2 comments
Open

Read Datastream upon resource_already_exists_exception #341

applike-ss opened this issue Mar 2, 2023 · 2 comments

Comments

@applike-ss
Copy link

Hello,

i would like to suggest an improvement in the handling of the elasticsearch_data_stream resource.
Currently when you try to do a terraform apply and the data_stream already exists, there's an error thrown:

Error: elastic: Error 400 (Bad Request): data_stream [my-data-stream-name] already exists [type=resource_already_exists_exception]

I think it would be desirable to try to read it into the state in this case and only error out (with the original error) if that fails too.
If i got it right, then the only thing that needs to be adjusted is to move some code around in resourceElasticsearchDataStreamCreate (

func resourceElasticsearchDataStreamCreate(d *schema.ResourceData, meta interface{}) error {
)

Our point here is that we want to create the data_stream as part of our monitoring module which runs after we deployed a AWS ECS application. This ECS application does already emit logs to our log router and it gets into a steady state after the first logs get flushed by the log router. So the creation can basically never succeed for us right now. However we want the data_stream to be removed when the application is being removed, which is why we want to manage it in the terraform state.

best,
Sebastian Struß

@phillbaker
Copy link
Owner

Hi @applike-ss, thanks for opening an issue. Unfortunately, I think this would generally break expectations of how terraform is supposed to work, for example, this could result in unintentionally overriding an existing data stream if the name collides.

Have you considered importing the resource into terraform?

@applike-ss
Copy link
Author

Hi @phillbaker, yes i considered it. However it is not desirable in an automatically created environment to manually import things into a state. Right now it seems we can only create the datastream before making use of our module that creates all other monitoring related resources or we have to split our module in 2 parts. One part would run before and another one would run after the application was spawned.

Anyhow, i have seen somewhere in the terraform-provider-aws that upon resource creation it was imported when it did already exist. Not sure which one, but might be due to API limitations on aws side (like SNS topics, which can not be fetched by name).

I see that you don't want to break how terraform has worked for you until now and it makes sense to be able to detect when a resource i want to create did exist before (just not in the state). So feel free to close this one if you agree.

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

2 participants