orange-cloudfoundry / terraform-provider-cloudfoundry

A terraform provider to manage a Cloud Foundry instance.
Apache License 2.0
31 stars 8 forks source link

Isolation segment fails to refresh resource when missing from cloud #36

Open gberche-orange opened 6 years ago

gberche-orange commented 6 years ago

When the tfstate and tf specs contain an isolation segment which is not present in the cloud,

resource "cloudfoundry_isolation_segment" "internet_isolation_segment" {
  name = "internet_isolation_segment"
  orgs_id = ["${cloudfoundry_organization.org-orange-internet.id}"]
}

the terraform plan fails with the following output:

+ terraform plan -input=false ../spec-applied/
Refreshing Terraform state in-memory prior to plan...
The refreshed state will be used to calculate this plan, but will not be
persisted to local or remote state storage.

[...]   
cloudfoundry_isolation_segment.internet_isolation_segment: Refreshing state... (ID: 1de9160c-c572-4eb2-b9f6-7e08d98a9564)
[...]

Error: Error refreshing state: 1 error(s) occurred:
* cloudfoundry_isolation_segment.internet_isolation_segment: 1 error(s) occurred:

* cloudfoundry_isolation_segment.internet_isolation_segment: cloudfoundry_isolation_segment.internet_isolation_segment: Isolation segment not found

The attempt to refresh the tfstate also fails with the same message:

terraform refresh -input=false -target=cloudfoundry_isolation_segment.internet_isolation_segment ../spec-applied/ 
cloudfoundry_organization.org-orange-internet: Refreshing state... (ID: 6344f674-7e9e-4159-a9e9-abc5f14501ee)
cloudfoundry_isolation_segment.internet_isolation_segment: Refreshing state... (ID: 1de9160c-c572-4eb2-b9f6-7e08d98a9564)

Error: Error refreshing state: 1 error(s) occurred:

* cloudfoundry_isolation_segment.internet_isolation_segment: 1 error(s) occurred:

* cloudfoundry_isolation_segment.internet_isolation_segment: cloudfoundry_isolation_segment.internet_isolation_segment: Isolation segment not found

Workaround: manually remove the missing isolation-segment from the tfstate:

$ terraform state list | grep isolation | xargs -n 1 terraform state rm