Skip to content

Commit

Permalink
Add raw response (#145)
Browse files Browse the repository at this point in the history
* add raw_body to DSA resource

* set default for ACL instead of required

* bump to 1.19

* Automated docs update

---------

Co-authored-by: Dean Oren <deangili.oren@mail.schwarz>
Co-authored-by: do87 <do87@users.noreply.github.com>
  • Loading branch information
3 people authored May 26, 2023
1 parent e5f4c5c commit ee3cbf5
Show file tree
Hide file tree
Showing 16 changed files with 42 additions and 12 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ terraform {
required_providers {
stackit = {
source = "SchwarzIT/stackit"
version = "~> 1.18.0"
version = "~> 1.19.0"
}
}
}
Expand Down
1 change: 1 addition & 0 deletions docs/resources/elasticsearch_credential.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ resource "stackit_elasticsearch_credential" "example" {
- `id` (String) Specifies the resource ID
- `password` (String) Credential password
- `port` (Number) Credential port
- `raw_response` (String) The full API response (as JSON string)
- `route_service_url` (String) Credential route_service_url
- `syslog_drain_url` (String) Credential syslog_drain_url
- `uri` (String) The instance URI
Expand Down
1 change: 1 addition & 0 deletions docs/resources/logme_credential.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ resource "stackit_logme_credential" "example" {
- `id` (String) Specifies the resource ID
- `password` (String) Credential password
- `port` (Number) Credential port
- `raw_response` (String) The full API response (as JSON string)
- `route_service_url` (String) Credential route_service_url
- `syslog_drain_url` (String) Credential syslog_drain_url
- `uri` (String) The instance URI
Expand Down
1 change: 1 addition & 0 deletions docs/resources/mariadb_credential.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ resource "stackit_mariadb_credential" "example" {
- `id` (String) Specifies the resource ID
- `password` (String) Credential password
- `port` (Number) Credential port
- `raw_response` (String) The full API response (as JSON string)
- `route_service_url` (String) Credential route_service_url
- `syslog_drain_url` (String) Credential syslog_drain_url
- `uri` (String) The instance URI
Expand Down
2 changes: 1 addition & 1 deletion docs/resources/mongodb_flex_instance.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,13 @@ resource "stackit_mongodb_flex_instance" "example" {

### Required

- `acl` (List of String) Access Control rules to whitelist IP addresses
- `machine_type` (String) The Machine Type. Available options: `1.1` (1 CPU, 1 Memory), `1.2` (1 CPU, 2 Memory), `1.4` (1 CPU, 4 Memory), `1.8` (1 CPU, 8 Memory), `2.4` (2 CPU, 4 Memory), `2.8` (2 CPU, 8 Memory), `2.16` (2 CPU, 16 Memory), `4.8` (4 CPU, 8 Memory), `4.16` (4 CPU, 16 Memory), `4.32` (4 CPU, 32 Memory), `8.16` (8 CPU, 16 Memory), `8.32` (8 CPU, 32 Memory), `8.64` (8 CPU, 64 Memory), `16.32` (16 CPU, 32 Memory), `16.64` (16 CPU, 64 Memory)
- `name` (String) Specifies the instance name.
- `project_id` (String) The project ID the instance runs in. Changing this value requires the resource to be recreated.

### Optional

- `acl` (List of String) Whitelist IP address ranges. Default is [193.148.160.0/19 45.129.40.0/21 45.135.244.0/22]
- `backup_schedule` (String) Specifies the backup schedule (cron style).
- `labels` (Map of String) Instance Labels
- `replicas` (Number) Number of replicas (Default is `1`).
Expand Down
1 change: 1 addition & 0 deletions docs/resources/postgres_credential.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ resource "stackit_postgres_credential" "example" {
- `id` (String) Specifies the resource ID
- `password` (String) Credential password
- `port` (Number) Credential port
- `raw_response` (String) The full API response (as JSON string)
- `route_service_url` (String) Credential route_service_url
- `syslog_drain_url` (String) Credential syslog_drain_url
- `uri` (String) The instance URI
Expand Down
2 changes: 1 addition & 1 deletion docs/resources/postgres_flex_instance.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ resource "stackit_postgres_flex_instance" "example" {

### Optional

- `acl` (List of String) Access Control rules to whitelist IP addresses. Default is 193.148.160.0/19, 45.129.40.1/21
- `acl` (List of String) Whitelist IP address ranges. Default is [193.148.160.0/19 45.129.40.0/21 45.135.244.0/22]
- `backup_schedule` (String) Specifies the backup schedule (cron style)
- `labels` (Map of String) Instance Labels
- `options` (Map of String) Specifies postgres instance options
Expand Down
1 change: 1 addition & 0 deletions docs/resources/rabbitmq_credential.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ resource "stackit_rabbitmq_credential" "example" {
- `id` (String) Specifies the resource ID
- `password` (String) Credential password
- `port` (Number) Credential port
- `raw_response` (String) The full API response (as JSON string)
- `route_service_url` (String) Credential route_service_url
- `syslog_drain_url` (String) Credential syslog_drain_url
- `uri` (String) The instance URI
Expand Down
1 change: 1 addition & 0 deletions docs/resources/redis_credential.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ resource "stackit_redis_credential" "example" {
- `id` (String) Specifies the resource ID
- `password` (String) Credential password
- `port` (Number) Credential port
- `raw_response` (String) The full API response (as JSON string)
- `route_service_url` (String) Credential route_service_url
- `syslog_drain_url` (String) Credential syslog_drain_url
- `uri` (String) The instance URI
Expand Down
7 changes: 7 additions & 0 deletions stackit/internal/common/consts.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,10 @@ const (
// errors
ERR_UNEXPECTED_EOF = "unexpected EOF"
)

// KnownRanges are the known ranges of IP addresses used by STACKIT
var KnownRanges = []string{
"193.148.160.0/19",
"45.129.40.0/21",
"45.135.244.0/22",
}
10 changes: 10 additions & 0 deletions stackit/internal/common/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import (
"github.com/hashicorp/terraform-plugin-framework/attr"
"github.com/hashicorp/terraform-plugin-framework/diag"
"github.com/hashicorp/terraform-plugin-framework/resource/schema"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/defaults"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/listdefault"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/objectdefault"
"github.com/hashicorp/terraform-plugin-framework/types"
)
Expand Down Expand Up @@ -91,3 +93,11 @@ func Timeouts(ctx context.Context, opts timeouts.Opts) schema.SingleNestedAttrib
)
return timeout
}

func GetDefaultACL() defaults.List {
av := []attr.Value{}
for _, r := range KnownRanges {
av = append(av, types.StringValue(r))
}
return listdefault.StaticValue(types.ListValueMust(types.StringType, av))
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
clientValidate "github.com/SchwarzIT/community-stackit-go-client/pkg/validate"
"github.com/hashicorp/terraform-plugin-framework/path"
"github.com/hashicorp/terraform-plugin-framework/resource"
"github.com/hashicorp/terraform-plugin-framework/types"
)

// Create - lifecycle function
Expand Down Expand Up @@ -40,6 +41,7 @@ func (r Resource) Create(ctx context.Context, req resource.CreateRequest, resp *
resp.Diagnostics.AddError("failed to process client response", err.Error())
return
}
cred.RawResponse = types.StringValue(string(res.Body))

// update state
diags = resp.State.Set(ctx, &cred)
Expand Down Expand Up @@ -72,6 +74,7 @@ func (r Resource) Read(ctx context.Context, req resource.ReadRequest, resp *reso
resp.Diagnostics.AddError("failed to process client response", err.Error())
return
}
cred.RawResponse = types.StringValue(string(res.Body))

// update state
diags = resp.State.Set(ctx, &cred)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ func TestAcc_ResourceRabbitMQCredentialJob(t *testing.T) {
resource.TestCheckResourceAttrSet("stackit_rabbitmq_credential.example", "password"),
resource.TestCheckResourceAttrSet("stackit_rabbitmq_credential.example", "port"),
resource.TestCheckResourceAttrSet("stackit_rabbitmq_credential.example", "uri"),
resource.TestCheckResourceAttrSet("stackit_rabbitmq_credential.example", "raw_response"),
),
},
// test import
Expand Down
6 changes: 6 additions & 0 deletions stackit/internal/resources/data-services/credential/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ type Credential struct {
SyslogDrainURL types.String `tfsdk:"syslog_drain_url"`
RouteServiceURL types.String `tfsdk:"route_service_url"`
URI types.String `tfsdk:"uri"`
RawResponse types.String `tfsdk:"raw_response"`
}

// Schema returns the terraform schema structure
Expand Down Expand Up @@ -111,6 +112,11 @@ func (r *Resource) Schema(ctx context.Context, req resource.SchemaRequest, resp
Description: "The instance URI",
Computed: true,
},

"raw_response": schema.StringAttribute{
Description: "The full API response (as JSON string)",
Computed: true,
},
},
}
}
6 changes: 4 additions & 2 deletions stackit/internal/resources/mongodb-flex/instance/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,11 @@ func (r *Resource) Schema(ctx context.Context, req resource.SchemaRequest, resp
Optional: true,
},
"acl": schema.ListAttribute{
Description: "Access Control rules to whitelist IP addresses",
Description: fmt.Sprintf("Whitelist IP address ranges. Default is %v", common.KnownRanges),
ElementType: types.StringType,
Required: true,
Optional: true,
Computed: true,
Default: common.GetDefaultACL(),
},
"timeouts": common.Timeouts(ctx, timeouts.Opts{
Create: true,
Expand Down
9 changes: 2 additions & 7 deletions stackit/internal/resources/postgres-flex/instance/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,10 @@ import (
"github.com/SchwarzIT/terraform-provider-stackit/stackit/internal/common"
"github.com/SchwarzIT/terraform-provider-stackit/stackit/pkg/validate"
"github.com/hashicorp/terraform-plugin-framework-timeouts/resource/timeouts"
"github.com/hashicorp/terraform-plugin-framework/attr"
"github.com/hashicorp/terraform-plugin-framework/resource"
"github.com/hashicorp/terraform-plugin-framework/resource/schema"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/int64default"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/int64planmodifier"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/listdefault"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/stringdefault"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier"
Expand Down Expand Up @@ -129,14 +127,11 @@ func (r *Resource) Schema(ctx context.Context, req resource.SchemaRequest, resp
Optional: true,
},
"acl": schema.ListAttribute{
Description: "Access Control rules to whitelist IP addresses. Default is 193.148.160.0/19, 45.129.40.1/21",
Description: fmt.Sprintf("Whitelist IP address ranges. Default is %v", common.KnownRanges),
ElementType: types.StringType,
Optional: true,
Computed: true,
Default: listdefault.StaticValue(types.ListValueMust(types.StringType, []attr.Value{
types.StringValue("193.148.160.0/19"),
types.StringValue("45.129.40.1/21"),
})),
Default: common.GetDefaultACL(),
},
"timeouts": common.Timeouts(ctx, timeouts.Opts{
Create: true,
Expand Down

0 comments on commit ee3cbf5

Please sign in to comment.