Skip to content

Commit

Permalink
Fix/cdn add metadata (#679)
Browse files Browse the repository at this point in the history
  • Loading branch information
cristiGuranIonos authored Sep 30, 2024
1 parent 3eab487 commit 702e79d
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions docs/data-sources/cdn_distribution.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
5 changes: 5 additions & 0 deletions docs/resources/cdn_distribution.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
15 changes: 15 additions & 0 deletions ionoscloud/data_source_cdn_distribution.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
Expand Down
15 changes: 15 additions & 0 deletions ionoscloud/resource_cdn_distribution.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
Expand Down
9 changes: 9 additions & 0 deletions ionoscloud/resource_cdn_distribution_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand All @@ -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"),
Expand Down
15 changes: 15 additions & 0 deletions services/cdn/distributions.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 702e79d

Please sign in to comment.