diff --git a/.changes/unreleased/FEATURES-20240423-133542.yaml b/.changes/unreleased/FEATURES-20240423-133542.yaml new file mode 100644 index 00000000..267c8ae1 --- /dev/null +++ b/.changes/unreleased/FEATURES-20240423-133542.yaml @@ -0,0 +1,3 @@ +kind: FEATURES +body: add provider_cname in cdn resource schema and set it for read and update operations. +time: 2024-04-23T13:35:42.460920502+03:00 diff --git a/yandex/resource_yandex_cdn_resource.go b/yandex/resource_yandex_cdn_resource.go index d0d96a1d..36370b66 100644 --- a/yandex/resource_yandex_cdn_resource.go +++ b/yandex/resource_yandex_cdn_resource.go @@ -110,6 +110,11 @@ func defineYandexCDNResourceBaseSchema() *schema.Resource { }, }, }, + "provider_cname": { + Type: schema.TypeString, + + Computed: true, + }, "options": { Type: schema.TypeList, @@ -1134,6 +1139,17 @@ func resourceYandexCDNResourceRead(d *schema.ResourceData, meta interface{}) err return err } + cname, err := config.sdk.CDN().Resource().GetProviderCName(ctx, &cdn.GetProviderCNameRequest{ + FolderId: resource.FolderId, + }) + if err != nil { + return handleNotFoundError(err, d, fmt.Sprintf("get provider cname: cdn resource %q, folder id %q", d.Id(), resource.FolderId)) + } + + if err = d.Set("provider_cname", cname.Cname); err != nil { + return err + } + return nil } @@ -1239,6 +1255,24 @@ func resourceYandexCDNResourceUpdate(d *schema.ResourceData, meta interface{}) e log.Printf("[DEBUG] Completed updating CDN Resource %q", d.Id()) + resource, err := config.sdk.CDN().Resource().Get(ctx, &cdn.GetResourceRequest{ + ResourceId: d.Id(), + }) + if err != nil { + return handleNotFoundError(err, d, fmt.Sprintf("cdn resource %q", d.Id())) + } + + cname, err := config.sdk.CDN().Resource().GetProviderCName(ctx, &cdn.GetProviderCNameRequest{ + FolderId: resource.FolderId, + }) + if err != nil { + return handleNotFoundError(err, d, fmt.Sprintf("get provider cname: cdn resource %q, folder id %q", d.Id(), resource.FolderId)) + } + + if err = d.Set("provider_cname", cname.Cname); err != nil { + return err + } + return resourceYandexCDNResourceRead(d, meta) }