Skip to content

Commit

Permalink
fix: certificate_id should be optional for api_gateway resource (#678)
Browse files Browse the repository at this point in the history
  • Loading branch information
cristiGuranIonos authored Sep 27, 2024
1 parent 86cfd22 commit 3eab487
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 42 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 2 additions & 12 deletions docs/resources/apigateway.md
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
```

Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion docs/resources/ipblock.md
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
```
Expand Down
8 changes: 5 additions & 3 deletions ionoscloud/resource_apigateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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),
},
},
},
Expand Down
28 changes: 6 additions & 22 deletions ionoscloud/resource_apigateway_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
`

Expand All @@ -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"
}
}
`

Expand All @@ -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" {
Expand Down Expand Up @@ -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"),
),
},
{
Expand All @@ -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"),
),
},
{
Expand All @@ -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"),
),
},
{
Expand All @@ -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"),
),
},
{
Expand All @@ -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"),
),
},
{
Expand Down
8 changes: 4 additions & 4 deletions services/apigateway/apigateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down

0 comments on commit 3eab487

Please sign in to comment.