yandex-cloud / terraform-provider-yandex

Terraform Yandex provider
https://www.terraform.io/docs/providers/yandex/
Mozilla Public License 2.0
208 stars 113 forks source link

yandex_cdn_origin_group misbehavior when domain not resolved #374

Open baznikin opened 1 year ago

baznikin commented 1 year ago

When domain name can't be resolved (no DNS record for host or nonexistent domain), origin was not created wth error

│ Error: error while requesting API to create origin group: operation (id=bc8c74ci6sq55jege34w) failed: rpc error: code = InvalidArgument desc = error: general api error: {"origins":{"inn.wrong-domain.ru":{"source":["The domain name cannot be resolved. Please specify a valid domain name."]}}}
│ 
│   with yandex_cdn_origin_group.assets_inn,
│   on cdn.tf line 225, in resource "yandex_cdn_origin_group" "assets_inn":
│  225: resource "yandex_cdn_origin_group" "assets_inn" {

and all subsequent operations with this object fails. Resource was created in TF state but in the cloud:

$ terraform apply -target yandex_cdn_origin_group.assets_inn
yandex_cdn_origin_group.assets_inn: Refreshing state... [id=0]
╷
│ Warning: Resource targeting is in effect
│ 
│ You are creating a plan with the -target option, which means that the result of this plan may not represent all of the changes requested by the current configuration.
│ 
│ The -target option is not for routine use, and is provided only for exceptional situations such as recovering from errors or mistakes, or when Terraform specifically suggests to use it as part of an error
│ message.
╵
╷
│ Error: error reading origin group "0": server-request-id = cefd394d-ccee-45ae-979e-a891ef86f4e1 server-trace-id = ad2944cbb232c388:2b0613ab54a9502d:ad2944cbb232c388:1 client-request-id = 3d350ef6-ed9b-40a8-8158-6d91b579e810 client-trace-id = ba119ebe-8281-4d5d-8d4b-46f65f9b96e6 rpc error: code = InvalidArgument desc = origin group id is empty
│ 
│   with yandex_cdn_origin_group.assets_inn,
│   on cdn.tf line 225, in resource "yandex_cdn_origin_group" "assets_inn":
│  225: resource "yandex_cdn_origin_group" "assets_inn" {
│ 
╵

$ terraform destroy -target yandex_cdn_origin_group.assets_inn
yandex_cdn_origin_group.assets_inn: Refreshing state... [id=0]
╷
│ Warning: Resource targeting is in effect
│ 
│ You are creating a plan with the -target option, which means that the result of this plan may not represent all of the changes requested by the current configuration.
│ 
│ The -target option is not for routine use, and is provided only for exceptional situations such as recovering from errors or mistakes, or when Terraform specifically suggests to use it as part of an error
│ message.
╵
╷
│ Error: error reading origin group "0": server-request-id = 7c63185e-9d89-4bcc-a6df-ff9546fe9248 server-trace-id = 50dd0a8b39c77e66:a4bee1b51ff57f81:50dd0a8b39c77e66:1 client-request-id = 6d86f585-def5-4364-b483-db5a8ff5c36e client-trace-id = 4e438e5f-62ce-4220-b169-4d4d5d140d36 rpc error: code = InvalidArgument desc = origin group id is empty
│ 
│   with yandex_cdn_origin_group.assets_inn,
│   on cdn.tf line 225, in resource "yandex_cdn_origin_group" "assets_inn":
│  225: resource "yandex_cdn_origin_group" "assets_inn" {

Only way to deal with it is to remove resource from state: terraform state rm yandex_cdn_origin_group.assets_inn

mipo256 commented 1 year ago

We have the same problem, any plans to fix this?

sharovmerk commented 6 months ago

Have the same problem. Fixed by terraform state rm, but it's really bad.

opportunity356 commented 2 weeks ago

It is impossible to create an origin with nonexistent domain, but in such case provider should not add resource to state. Bug confirmed