From 702e79d30b680e702f5c980e2aeee8c4ce3bc1a1 Mon Sep 17 00:00:00 2001 From: cguran-ionos Date: Mon, 30 Sep 2024 09:44:48 +0300 Subject: [PATCH] Fix/cdn add metadata (#679) --- CHANGELOG.md | 1 + docs/data-sources/cdn_distribution.md | 3 +++ docs/resources/cdn_distribution.md | 5 +++++ ionoscloud/data_source_cdn_distribution.go | 15 +++++++++++++++ ionoscloud/resource_cdn_distribution.go | 15 +++++++++++++++ ionoscloud/resource_cdn_distribution_test.go | 9 +++++++++ services/cdn/distributions.go | 15 +++++++++++++++ 7 files changed, 63 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2fcd165c4..35d3dc3b1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ - Fix `ionoscloud_certificate` data source - Fix `DBaaS` tests, change location for clusters creation, mark `connection_pooler` as computed - `certificate_id` should not be required for API Gateway resource, `custom_domains` field. +- `cdn distribution` add metadata ipv4, ipv6 and resource_urn to resource and data source ## 6.5.5 ### Fixes diff --git a/docs/data-sources/cdn_distribution.md b/docs/data-sources/cdn_distribution.md index 8745b44f5..86dbfd892 100644 --- a/docs/data-sources/cdn_distribution.md +++ b/docs/data-sources/cdn_distribution.md @@ -63,3 +63,6 @@ The following attributes are returned by the datasource: * `geo_restrictions` - A map of geo_restrictions * `allow_list` - List of allowed countries * `block_list` - List of blocked countries +- `public_endpoint_v4` - IP of the distribution, it has to be included on the domain DNS Zone as A record. +- `public_endpoint_v6` - IP of the distribution, it has to be included on the domain DNS Zone as AAAA record. +- `resource_urn` - Unique resource identifier. \ No newline at end of file diff --git a/docs/resources/cdn_distribution.md b/docs/resources/cdn_distribution.md index 96554bc80..741e0d859 100644 --- a/docs/resources/cdn_distribution.md +++ b/docs/resources/cdn_distribution.md @@ -72,6 +72,11 @@ The following arguments are supported: * `geo_restrictions` - (Optional)[map] - A map of geo_restrictions * `allow_list` - (Optional)[string] List of allowed countries * `block_list` - (Optional)[string] List of blocked countries +## Attributes Reference + +- `public_endpoint_v4` - IP of the distribution, it has to be included on the domain DNS Zone as A record. +- `public_endpoint_v6` - IP of the distribution, it has to be included on the domain DNS Zone as AAAA record. +- `resource_urn` - Unique resource indentifier. ## Import diff --git a/ionoscloud/data_source_cdn_distribution.go b/ionoscloud/data_source_cdn_distribution.go index 54cdaf2dc..e01650bb4 100644 --- a/ionoscloud/data_source_cdn_distribution.go +++ b/ionoscloud/data_source_cdn_distribution.go @@ -23,6 +23,21 @@ func dataSourceCDNDistribution() *schema.Resource { Type: schema.TypeString, Optional: true, }, + "resource_urn": { + Type: schema.TypeString, + Description: "Unique name of the resource.", + Computed: true, + }, + "public_endpoint_v4": { + Type: schema.TypeString, + Description: "IP of the distribution, it has to be included on the domain DNS Zone as A record.", + Computed: true, + }, + "public_endpoint_v6": { + Type: schema.TypeString, + Description: "IP of the distribution, it has to be included on the domain DNS Zone as AAAA record.", + Computed: true, + }, "partial_match": { Type: schema.TypeBool, Description: "Whether partial matching is allowed or not when using domain argument.", diff --git a/ionoscloud/resource_cdn_distribution.go b/ionoscloud/resource_cdn_distribution.go index c9e7c0184..3fb8a6355 100644 --- a/ionoscloud/resource_cdn_distribution.go +++ b/ionoscloud/resource_cdn_distribution.go @@ -32,6 +32,21 @@ func resourceCDNDistribution() *schema.Resource { Required: true, ValidateDiagFunc: validation.ToDiagFunc(validation.StringIsNotWhiteSpace), }, + "resource_urn": { + Type: schema.TypeString, + Description: "Unique name of the resource.", + Computed: true, + }, + "public_endpoint_v4": { + Type: schema.TypeString, + Description: "IP of the distribution, it has to be included on the domain DNS Zone as A record.", + Computed: true, + }, + "public_endpoint_v6": { + Type: schema.TypeString, + Description: "IP of the distribution, it has to be included on the domain DNS Zone as AAAA record.", + Computed: true, + }, "certificate_id": { Type: schema.TypeString, Description: "The ID of the certificate to use for the distribution.", diff --git a/ionoscloud/resource_cdn_distribution_test.go b/ionoscloud/resource_cdn_distribution_test.go index 5f2cb7fea..2722d0142 100644 --- a/ionoscloud/resource_cdn_distribution_test.go +++ b/ionoscloud/resource_cdn_distribution_test.go @@ -60,6 +60,11 @@ func TestAccDistributionBasic(t *testing.T) { Config: testAccDataSourceCDNDistributionMatchId, Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr(constant.CDNDistributionResource+"."+constant.CDNDistributionTestResource, "domain", "unique.test.example.com"), + + resource.TestCheckResourceAttrPair(constant.DataSource+"."+constant.CDNDistributionResource+"."+constant.CDNDistributionDataSourceByID, "public_endpoint_v4", constant.CDNDistributionResource+"."+constant.CDNDistributionTestResource, "public_endpoint_v4"), + resource.TestCheckResourceAttrPair(constant.DataSource+"."+constant.CDNDistributionResource+"."+constant.CDNDistributionDataSourceByID, "public_endpoint_v6", constant.CDNDistributionResource+"."+constant.CDNDistributionTestResource, "public_endpoint_v6"), + resource.TestCheckResourceAttrPair(constant.DataSource+"."+constant.CDNDistributionResource+"."+constant.CDNDistributionDataSourceByID, "resource_urn", constant.CDNDistributionResource+"."+constant.CDNDistributionTestResource, "resource_urn"), + resource.TestCheckResourceAttr(constant.CDNDistributionResource+"."+constant.CDNDistributionTestResource, "routing_rules.0.scheme", "http"), resource.TestCheckResourceAttr(constant.CDNDistributionResource+"."+constant.CDNDistributionTestResource, "routing_rules.0.prefix", "/api"), resource.TestCheckResourceAttr(constant.CDNDistributionResource+"."+constant.CDNDistributionTestResource, "routing_rules.0.upstream.0.host", "server.example.com"), @@ -72,6 +77,10 @@ func TestAccDistributionBasic(t *testing.T) { { Config: testAccDataSourceCDNDistributionMatchDomain, Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttrPair(constant.DataSource+"."+constant.CDNDistributionResource+"."+constant.CDNDistributionDataSourceByDomain, "public_endpoint_v4", constant.CDNDistributionResource+"."+constant.CDNDistributionTestResource, "public_endpoint_v4"), + resource.TestCheckResourceAttrPair(constant.DataSource+"."+constant.CDNDistributionResource+"."+constant.CDNDistributionDataSourceByDomain, "public_endpoint_v6", constant.CDNDistributionResource+"."+constant.CDNDistributionTestResource, "public_endpoint_v6"), + resource.TestCheckResourceAttrPair(constant.DataSource+"."+constant.CDNDistributionResource+"."+constant.CDNDistributionDataSourceByDomain, "resource_urn", constant.CDNDistributionResource+"."+constant.CDNDistributionTestResource, "resource_urn"), + resource.TestCheckResourceAttr(constant.CDNDistributionResource+"."+constant.CDNDistributionTestResource, "domain", "unique.test.example.com"), resource.TestCheckResourceAttr(constant.CDNDistributionResource+"."+constant.CDNDistributionTestResource, "routing_rules.0.scheme", "http"), resource.TestCheckResourceAttr(constant.CDNDistributionResource+"."+constant.CDNDistributionTestResource, "routing_rules.0.prefix", "/api"), diff --git a/services/cdn/distributions.go b/services/cdn/distributions.go index 28d0c5200..a41273d4d 100644 --- a/services/cdn/distributions.go +++ b/services/cdn/distributions.go @@ -20,6 +20,21 @@ func SetDistributionData(d *schema.ResourceData, distribution cdn.Distribution) resourceName := "distribution" d.SetId(distribution.Id) + if distribution.Metadata.ResourceURN != nil { + if err := d.Set("resource_urn", *distribution.Metadata.ResourceURN); err != nil { + return utils.GenerateSetError(resourceName, "resource_urn", err) + } + } + if distribution.Metadata.PublicEndpointIpv4 != nil { + if err := d.Set("public_endpoint_v4", *distribution.Metadata.PublicEndpointIpv4); err != nil { + return utils.GenerateSetError(resourceName, "public_endpoint_v4", err) + } + } + if distribution.Metadata.PublicEndpointIpv6 != nil { + if err := d.Set("public_endpoint_v6", *distribution.Metadata.PublicEndpointIpv6); err != nil { + return utils.GenerateSetError(resourceName, "public_endpoint_v6", err) + } + } if err := d.Set("domain", distribution.Properties.Domain); err != nil { return utils.GenerateSetError(resourceName, "domain", err)