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

terraform import not working properly when importing a non existing resource #231

Closed dikhan closed 4 years ago

dikhan commented 4 years ago

Describe the bug

Importing a non existing resource (eg: the API return a 404) results into the import command succeeding instead of throwing an error.

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. Execute terraform import with a non existing ID terraform import openapi_group_v1.my_iam_group_v1 non_existing_group
    openapi_group_v1.my_iam_group_v1: Importing from ID "non_existing_group"...
    openapi_group_v1.my_iam_group_v1: Import prepared!
    Prepared openapi_group_v1 for import
    openapi_group_v1.my_iam_group_v1: Refreshing state... [id=non_existing_group]
     
    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.

Expected behaviour

As a OpenAPI Terraform user I want the terraform import command to fail and return an error when the imported resource does not exists (eg: the API returns 404) So that I can figure out what the issue is and fix it if needed (eg: typo in the resourceID imported) An error should be thrown stating the error and terraform import should fail

Example:

Scenario: Importing a non existing resource errors out
Given a non existing resource
When executing the import command: terraform import openapi_group_v1.my_iam_group_v1 non_existing_group
Then the plugin should return a user friendly error containing the details of the problem and terraform should error out

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: