Skip to content

Commit

Permalink
fix: location set as optional with de/txl default (#662)
Browse files Browse the repository at this point in the history
  • Loading branch information
cristiGuranIonos authored Sep 2, 2024
1 parent c2f3b35 commit 991e8b0
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 16 deletions.
5 changes: 1 addition & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
## 6.5.3
### Fixes
- `ionoslcoud_logging_pipeline` - `location` should be optional with `de/txl` default. Upgrading should not break existing pipelines.
- Fix DBaaS tests

## 6.5.2
### Features
- support for all s3 resources configurations


## 6.5.1
### Features
- Add `location` to `logging_pipeline` resource and data source
### Fixes
- Fix nil deref due to `GeoRestrictions` not being checked against nil
Expand Down
3 changes: 2 additions & 1 deletion docs/data-sources/logging_pipeline.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ If a single match is found, it will be returned. If your search results in multi
### By ID
```hcl
data "ionoscloud_logging_pipeline" "example" {
location = "de/txl"
id = <pipeline_id>
}
```
Expand All @@ -32,7 +33,7 @@ data "ionoscloud_logging_pipeline" "example" {
```

## Argument reference
* `location` - (Required)[string] The location of the Logging pipeline. One of `de/fra`, `de/txl`, `gb/lhr`, `es/vit`, `fr/par`.
* `location` - (Optional)[string] The location of the Logging pipeline. Default: `de/txl`. One of `de/fra`, `de/txl`, `gb/lhr`, `es/vit`, `fr/par`.
* `id` - (Optional)[string] The ID of the Logging pipeline you want to search for.
* `name` - (Optional)[string] The name of the Logging pipeline you want to search for.

Expand Down
3 changes: 1 addition & 2 deletions docs/resources/logging_pipeline.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ terraform apply -var-file="vars.tfvars"

## Argument reference

* `location` - (Required)[string] The location of the Logging pipeline. One of `de/fra`, `de/txl`, `gb/lhr`, `es/vit`, `fr/par`.
* `location` - (Optional)[string] The location of the Logging pipeline. Default: `de/txl` One of `de/fra`, `de/txl`, `gb/lhr`, `es/vit`, `fr/par`.
* `name` - (Required)[string] The name of the Logging pipeline.
* `grafana_address` - (Computed)[string] The address of the client's grafana instance.
* `log` - (Required)[list] Pipeline logs, a list that contains elements with the following structure:
Expand All @@ -124,7 +124,6 @@ In order to import a Logging pipeline, you can define an empty Logging pipeline

```hcl
resource "ionoscloud_logging_pipeline" "example" {
}
```

Expand Down
14 changes: 11 additions & 3 deletions ionoscloud/data_source_logging_pipeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,17 @@ func dataSourceLoggingPipeline() *schema.Resource {
ReadContext: dataSourcePipelineRead,
Schema: map[string]*schema.Schema{
"location": {
Type: schema.TypeString,
Description: fmt.Sprintf("The location of your logging pipeline. Supported locations: %s", strings.Join(loggingService.AvailableLocations, ", ")),
Required: true,
Type: schema.TypeString,
Description: fmt.Sprintf("The location of your logging pipeline. Default: de/txl. Supported locations: %s", strings.Join(loggingService.AvailableLocations, ", ")),
Optional: true,
Default: "de/txl",
// no diff in case it moves from "" to de/txl since it's an upgrade from when we had no location
DiffSuppressFunc: func(_, old, new string, _ *schema.ResourceData) bool {
if old == "" && new == "de/txl" {
return true
}
return false
},
ValidateDiagFunc: validation.ToDiagFunc(validation.StringInSlice(loggingService.AvailableLocations, false)),
},
"id": {
Expand Down
22 changes: 16 additions & 6 deletions ionoscloud/resource_logging_pipeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,18 @@ func resourceLoggingPipeline() *schema.Resource {
},
Schema: map[string]*schema.Schema{
"location": {
Type: schema.TypeString,
Description: fmt.Sprintf("The location of your logging pipeline. Default: de/txl. Supported locations: %s", strings.Join(logging.AvailableLocations, ", ")),
Required: true,
ForceNew: true,
Type: schema.TypeString,
Description: fmt.Sprintf("The location of your logging pipeline. Default: de/txl. Supported locations: %s", strings.Join(logging.AvailableLocations, ", ")),
Optional: true,
Default: logging.DefaultLocation,
ForceNew: true,
// no diff in case it moves from "" to de/txl since it's an upgrade from when we had no location
DiffSuppressFunc: func(_, old, new string, _ *schema.ResourceData) bool {
if old == "" && new == logging.DefaultLocation {
return true
}
return false
},
ValidateDiagFunc: validation.ToDiagFunc(validation.StringInSlice(logging.AvailableLocations, false)),
},
"name": {
Expand Down Expand Up @@ -116,8 +124,10 @@ func pipelineCreate(ctx context.Context, d *schema.ResourceData, meta interface{
func pipelineRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
client := meta.(services.SdkBundle).LoggingClient
pipelineID := d.Id()
location := d.Get("location").(string)

location := logging.DefaultLocation
if newLocation, ok := d.GetOk("location"); ok {
location = newLocation.(string)
}
pipeline, apiResponse, err := client.GetPipelineByID(ctx, location, pipelineID)
if err != nil {
if apiResponse.HttpNotFound() {
Expand Down
5 changes: 5 additions & 0 deletions services/logging/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ func NewClient(username, password, token, url, terraformVersion string) *Client
}

func (c *Client) changeConfigURL(location string) {
if location == "" {
location = DefaultLocation
}
config := c.sdkClient.GetConfig()
config.Servers = shared.ServerConfigurations{
{
Expand All @@ -44,6 +47,8 @@ func (c *Client) changeConfigURL(location string) {
var (
// AvailableLocations is a list of available locations
AvailableLocations = []string{"de/fra", "de/txl", "es/vit", "gb/lhr", "fr/par"}
// DefaultLocation is the default logging pipeline location
DefaultLocation = "de/txl"

locationToURL = map[string]string{
"de/fra": "https://logging.de-fra.ionos.com",
Expand Down

0 comments on commit 991e8b0

Please sign in to comment.