dikhan / terraform-provider-openapi

OpenAPI Terraform Provider that configures itself at runtime with the resources exposed by the service provider (defined in a swagger file)
Apache License 2.0
275 stars 48 forks source link

Importing a non existing resource results into the state being updated #236

Closed dikhan closed 4 years ago

dikhan commented 4 years ago

Describe the bug

A clear and concise description of what the bug is.

To Reproduce

A clear and concise description on how does it work now and what's the current behaviour.

Steps to reproduce the behaviour:

  1. Import a non existing reosurce. Example: terraform import openapi_group.my_group non_existing_resource
    
    openapi_group.my_group: Importing from ID "non_existing_resource"...

Error: [resource='group'] GET /api/group/non_existing_resource failed: HTTP Response Status Code 404 - Not Found. Could not find resource instance: {"id":"ZXOW8Xi4","code":"not_found","status":404,"detail":"group not found"}

2. Run terraform plan and get the diff

terraform plan openapi_group.my_group: Refreshing state... [id=non_existing_group]

An execution plan has been generated and is shown below. Resource actions are indicated with the following symbols:

Terraform will perform the following actions:

openapi_group.my_group will be destroyed

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

Do you want to perform these actions? Terraform will perform the actions described above. Only 'yes' will be accepted to approve.

Enter a value:

Apply cancelled.


## Expected behaviour

Example:
```gherkin
Scenario:
Given a non existing resource
When terraform import openapi_group.my_group non_existing_resource
Then an error should be thrown and also the state file should be clean and not contain any state for the non found resource

Additional context

Add any other context about the problem here.

Checklist (for admin only)

Don't forget to go through the checklist to make sure the issue is created properly: