diff --git a/CHANGELOG.md b/CHANGELOG.md index e63d64902..2fcd165c4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ - Fix update behavior for container registry property: `apiSubnetAllowList` - 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. ## 6.5.5 ### Fixes diff --git a/docs/resources/apigateway.md b/docs/resources/apigateway.md index 14b583f59..37dda456c 100644 --- a/docs/resources/apigateway.md +++ b/docs/resources/apigateway.md @@ -17,16 +17,6 @@ An API gateway consists of the generic rules and configurations. resource "ionoscloud_apigateway" "example" { name = "example-gateway" metrics = true - - custom_domains { - name = "example.com" - certificate_id = "00000000-0000-0000-0000-000000000000" - } - - custom_domains { - name = "example.org" - certificate_id = "00000000-0000-0000-0000-000000000000" - } } ``` @@ -37,8 +27,8 @@ resource "ionoscloud_apigateway" "example" { * `logs` - (Optional)[bool] Enable or disable logging. Defaults to `false`. **NOTE**: Central Logging must be enabled through the Logging API to enable this feature. * `metrics` - (Optional)[bool] Enable or disable metrics. Defaults to `false`. * `custom_domains` - (Optional)[list] Custom domains for the API Gateway, a list that contains elements with the following structure: - * `name` - (Required)[string] The domain name. - * `certificate_id` - (Required)[string] The certificate ID for the domain. + * `name` - (Required)[string] The domain name. Externally reachable. + * `certificate_id` - (Optional)[string] The certificate ID for the domain. Must be a valid certificate in UUID form. * `public_endpoint` - (Computed)[string] The public endpoint of the API Gateway. ## Import diff --git a/docs/resources/ipblock.md b/docs/resources/ipblock.md index 656d26b6d..56be2edcc 100644 --- a/docs/resources/ipblock.md +++ b/docs/resources/ipblock.md @@ -16,7 +16,7 @@ Manages **IP Blocks** on IonosCloud. IP Blocks contain reserved public IP addres ```hcl resource "ionoscloud_ipblock" "example" { location = "us/las" - size = 3 + size = 1 name = "IP Block Example" } ``` diff --git a/ionoscloud/resource_apigateway.go b/ionoscloud/resource_apigateway.go index 49ca6e93a..615e2b2a6 100644 --- a/ionoscloud/resource_apigateway.go +++ b/ionoscloud/resource_apigateway.go @@ -7,6 +7,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" "github.com/ionos-cloud/terraform-provider-ionoscloud/v6/services" "github.com/ionos-cloud/terraform-provider-ionoscloud/v6/utils" @@ -57,9 +58,10 @@ func resourceAPIGateway() *schema.Resource { Required: true, }, "certificate_id": { - Type: schema.TypeString, - Description: "The certificate ID for the domain.", - Required: true, + Type: schema.TypeString, + Description: "The certificate ID for the domain.", + Optional: true, + ValidateDiagFunc: validation.ToDiagFunc(validation.IsUUID), }, }, }, diff --git a/ionoscloud/resource_apigateway_test.go b/ionoscloud/resource_apigateway_test.go index b560c2fae..965994ab6 100644 --- a/ionoscloud/resource_apigateway_test.go +++ b/ionoscloud/resource_apigateway_test.go @@ -19,10 +19,6 @@ resource "ionoscloud_apigateway" "example" { name = "example" logs = false metrics = true - custom_domains { - name = "example.com" - certificate_id = "00000000-0000-0000-0000-000000000000" - } } ` @@ -31,10 +27,6 @@ resource "ionoscloud_apigateway" "example" { name = "example_updated" logs = false metrics = false - custom_domains { - name = "example-updated.com" - certificate_id = "00000000-0000-0000-0000-000000000000" - } } ` @@ -61,10 +53,6 @@ resource "ionoscloud_apigateway" "example_multiple" { name = "example" logs = false metrics = true - custom_domains { - name = "example.com" - certificate_id = "00000000-0000-0000-0000-000000000000" - } } data "ionoscloud_apigateway" "example_matching" { @@ -95,8 +83,8 @@ func TestAccAPIGateway_basic(t *testing.T) { resource.TestCheckResourceAttr("ionoscloud_apigateway.example", "name", "example"), resource.TestCheckResourceAttr("ionoscloud_apigateway.example", "logs", "false"), resource.TestCheckResourceAttr("ionoscloud_apigateway.example", "metrics", "true"), - resource.TestCheckResourceAttr("ionoscloud_apigateway.example", "custom_domains.0.name", "example.com"), - resource.TestCheckResourceAttr("ionoscloud_apigateway.example", "custom_domains.0.certificate_id", "00000000-0000-0000-0000-000000000000"), + // can't be used in tests, as it requires a reachable domain name + // resource.TestCheckResourceAttr("ionoscloud_apigateway.example", "custom_domains.0.name", "example.com"), ), }, { @@ -106,8 +94,7 @@ func TestAccAPIGateway_basic(t *testing.T) { resource.TestCheckResourceAttr("ionoscloud_apigateway.example", "name", "example_updated"), resource.TestCheckResourceAttr("ionoscloud_apigateway.example", "logs", "false"), resource.TestCheckResourceAttr("ionoscloud_apigateway.example", "metrics", "false"), - resource.TestCheckResourceAttr("ionoscloud_apigateway.example", "custom_domains.0.name", "example-updated.com"), - resource.TestCheckResourceAttr("ionoscloud_apigateway.example", "custom_domains.0.certificate_id", "00000000-0000-0000-0000-000000000000"), + //resource.TestCheckResourceAttr("ionoscloud_apigateway.example", "custom_domains.0.name", "example-updated.com"), ), }, { @@ -116,8 +103,7 @@ func TestAccAPIGateway_basic(t *testing.T) { resource.TestCheckResourceAttrPair("data.ionoscloud_apigateway.example_by_id", "name", "ionoscloud_apigateway.example", "name"), resource.TestCheckResourceAttrPair("data.ionoscloud_apigateway.example_by_id", "logs", "ionoscloud_apigateway.example", "logs"), resource.TestCheckResourceAttrPair("data.ionoscloud_apigateway.example_by_id", "metrics", "ionoscloud_apigateway.example", "metrics"), - resource.TestCheckResourceAttrPair("data.ionoscloud_apigateway.example_by_id", "custom_domains.0.name", "ionoscloud_apigateway.example", "custom_domains.0.name"), - resource.TestCheckResourceAttrPair("data.ionoscloud_apigateway.example_by_id", "custom_domains.0.certificate_id", "ionoscloud_apigateway.example", "custom_domains.0.certificate_id"), + //resource.TestCheckResourceAttrPair("data.ionoscloud_apigateway.example_by_id", "custom_domains.0.name", "ionoscloud_apigateway.example", "custom_domains.0.name"), ), }, { @@ -126,8 +112,7 @@ func TestAccAPIGateway_basic(t *testing.T) { resource.TestCheckResourceAttrPair("data.ionoscloud_apigateway.example_by_name", "name", "ionoscloud_apigateway.example", "name"), resource.TestCheckResourceAttrPair("data.ionoscloud_apigateway.example_by_name", "logs", "ionoscloud_apigateway.example", "logs"), resource.TestCheckResourceAttrPair("data.ionoscloud_apigateway.example_by_name", "metrics", "ionoscloud_apigateway.example", "metrics"), - resource.TestCheckResourceAttrPair("data.ionoscloud_apigateway.example_by_name", "custom_domains.0.name", "ionoscloud_apigateway.example", "custom_domains.0.name"), - resource.TestCheckResourceAttrPair("data.ionoscloud_apigateway.example_by_name", "custom_domains.0.certificate_id", "ionoscloud_apigateway.example", "custom_domains.0.certificate_id"), + //resource.TestCheckResourceAttrPair("data.ionoscloud_apigateway.example_by_name", "custom_domains.0.name", "ionoscloud_apigateway.example", "custom_domains.0.name"), ), }, { @@ -136,8 +121,7 @@ func TestAccAPIGateway_basic(t *testing.T) { resource.TestCheckResourceAttrPair("data.ionoscloud_apigateway.example_matching", "name", "ionoscloud_apigateway.example", "name"), resource.TestCheckResourceAttrPair("data.ionoscloud_apigateway.example_matching", "logs", "ionoscloud_apigateway.example", "logs"), resource.TestCheckResourceAttrPair("data.ionoscloud_apigateway.example_matching", "metrics", "ionoscloud_apigateway.example", "metrics"), - resource.TestCheckResourceAttrPair("data.ionoscloud_apigateway.example_matching", "custom_domains.0.name", "ionoscloud_apigateway.example", "custom_domains.0.name"), - resource.TestCheckResourceAttrPair("data.ionoscloud_apigateway.example_matching", "custom_domains.0.certificate_id", "ionoscloud_apigateway.example", "custom_domains.0.certificate_id"), + //resource.TestCheckResourceAttrPair("data.ionoscloud_apigateway.example_matching", "custom_domains.0.name", "ionoscloud_apigateway.example", "custom_domains.0.name"), ), }, { diff --git a/services/apigateway/apigateway.go b/services/apigateway/apigateway.go index 98170fb6b..3a0e3002f 100644 --- a/services/apigateway/apigateway.go +++ b/services/apigateway/apigateway.go @@ -155,13 +155,13 @@ func setGatewayConfig(d *schema.ResourceData) apigateway.Gateway { for i, domain := range customDomainsRaw { domainData := domain.(map[string]interface{}) name := domainData["name"].(string) - certificateID := domainData["certificate_id"].(string) customDomainObj := apigateway.GatewayCustomDomains{ - Name: &name, - CertificateId: &certificateID, + Name: &name, + } + if cert, ok := domainData["certificate_id"]; ok && cert != "" { + customDomainObj.CertificateId = apigateway.ToPtr(cert.(string)) } - customDomains[i] = customDomainObj }