From ee3cbf53e807520af4365f09b2f84326c531f310 Mon Sep 17 00:00:00 2001 From: Dean Date: Fri, 26 May 2023 15:04:41 +0200 Subject: [PATCH] Add raw response (#145) * 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 Co-authored-by: do87 --- README.md | 2 +- docs/resources/elasticsearch_credential.md | 1 + docs/resources/logme_credential.md | 1 + docs/resources/mariadb_credential.md | 1 + docs/resources/mongodb_flex_instance.md | 2 +- docs/resources/postgres_credential.md | 1 + docs/resources/postgres_flex_instance.md | 2 +- docs/resources/rabbitmq_credential.md | 1 + docs/resources/redis_credential.md | 1 + stackit/internal/common/consts.go | 7 +++++++ stackit/internal/common/helpers.go | 10 ++++++++++ .../resources/data-services/credential/actions.go | 3 +++ .../data-services/credential/resource_rabbitmq_test.go | 1 + .../resources/data-services/credential/schema.go | 6 ++++++ .../internal/resources/mongodb-flex/instance/schema.go | 6 ++++-- .../resources/postgres-flex/instance/schema.go | 9 ++------- 16 files changed, 42 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index ed11e821..cad2816f 100644 --- a/README.md +++ b/README.md @@ -29,7 +29,7 @@ terraform { required_providers { stackit = { source = "SchwarzIT/stackit" - version = "~> 1.18.0" + version = "~> 1.19.0" } } } diff --git a/docs/resources/elasticsearch_credential.md b/docs/resources/elasticsearch_credential.md index 8c36de76..faa45dd9 100644 --- a/docs/resources/elasticsearch_credential.md +++ b/docs/resources/elasticsearch_credential.md @@ -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 diff --git a/docs/resources/logme_credential.md b/docs/resources/logme_credential.md index a240ab9f..ec07ff0d 100644 --- a/docs/resources/logme_credential.md +++ b/docs/resources/logme_credential.md @@ -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 diff --git a/docs/resources/mariadb_credential.md b/docs/resources/mariadb_credential.md index 973c2148..87653318 100644 --- a/docs/resources/mariadb_credential.md +++ b/docs/resources/mariadb_credential.md @@ -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 diff --git a/docs/resources/mongodb_flex_instance.md b/docs/resources/mongodb_flex_instance.md index 0d9a21f1..18bdffc8 100644 --- a/docs/resources/mongodb_flex_instance.md +++ b/docs/resources/mongodb_flex_instance.md @@ -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`). diff --git a/docs/resources/postgres_credential.md b/docs/resources/postgres_credential.md index 57921028..664c0f9c 100644 --- a/docs/resources/postgres_credential.md +++ b/docs/resources/postgres_credential.md @@ -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 diff --git a/docs/resources/postgres_flex_instance.md b/docs/resources/postgres_flex_instance.md index 94a63964..b2b9df1f 100644 --- a/docs/resources/postgres_flex_instance.md +++ b/docs/resources/postgres_flex_instance.md @@ -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 diff --git a/docs/resources/rabbitmq_credential.md b/docs/resources/rabbitmq_credential.md index fdb72a99..016f3d27 100644 --- a/docs/resources/rabbitmq_credential.md +++ b/docs/resources/rabbitmq_credential.md @@ -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 diff --git a/docs/resources/redis_credential.md b/docs/resources/redis_credential.md index 8a62ec53..524c2d82 100644 --- a/docs/resources/redis_credential.md +++ b/docs/resources/redis_credential.md @@ -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 diff --git a/stackit/internal/common/consts.go b/stackit/internal/common/consts.go index 7ada5d6a..0655ae83 100644 --- a/stackit/internal/common/consts.go +++ b/stackit/internal/common/consts.go @@ -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", +} diff --git a/stackit/internal/common/helpers.go b/stackit/internal/common/helpers.go index 38eafe4e..cf0ef74c 100644 --- a/stackit/internal/common/helpers.go +++ b/stackit/internal/common/helpers.go @@ -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" ) @@ -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)) +} diff --git a/stackit/internal/resources/data-services/credential/actions.go b/stackit/internal/resources/data-services/credential/actions.go index 9ebc186f..296e6045 100644 --- a/stackit/internal/resources/data-services/credential/actions.go +++ b/stackit/internal/resources/data-services/credential/actions.go @@ -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 @@ -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) @@ -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) diff --git a/stackit/internal/resources/data-services/credential/resource_rabbitmq_test.go b/stackit/internal/resources/data-services/credential/resource_rabbitmq_test.go index 12a3cf57..c43efa36 100644 --- a/stackit/internal/resources/data-services/credential/resource_rabbitmq_test.go +++ b/stackit/internal/resources/data-services/credential/resource_rabbitmq_test.go @@ -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 diff --git a/stackit/internal/resources/data-services/credential/schema.go b/stackit/internal/resources/data-services/credential/schema.go index d0f2b4d8..73d8578e 100644 --- a/stackit/internal/resources/data-services/credential/schema.go +++ b/stackit/internal/resources/data-services/credential/schema.go @@ -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 @@ -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, + }, }, } } diff --git a/stackit/internal/resources/mongodb-flex/instance/schema.go b/stackit/internal/resources/mongodb-flex/instance/schema.go index 3ec28337..644ec9e0 100644 --- a/stackit/internal/resources/mongodb-flex/instance/schema.go +++ b/stackit/internal/resources/mongodb-flex/instance/schema.go @@ -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, diff --git a/stackit/internal/resources/postgres-flex/instance/schema.go b/stackit/internal/resources/postgres-flex/instance/schema.go index 9706706e..c9f4687b 100644 --- a/stackit/internal/resources/postgres-flex/instance/schema.go +++ b/stackit/internal/resources/postgres-flex/instance/schema.go @@ -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" @@ -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,