From 5a5ac6640c667de4b847d0a47ecd4f1ec7640f8e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Palet?= Date: Thu, 12 Oct 2023 15:57:05 +0200 Subject: [PATCH] Rename credentials_id field to credential_id (#80) * Rename credentials_id field to credential_id * Address review comments --- MIGRATION.md | 4 +- docs/data-sources/logme_credential.md | 10 +-- docs/data-sources/mariadb_credential.md | 10 +-- docs/data-sources/opensearch_credential.md | 10 +-- docs/data-sources/postgresql_credential.md | 10 +-- docs/data-sources/rabbitmq_credential.md | 10 +-- docs/data-sources/redis_credential.md | 10 +-- docs/resources/logme_credential.md | 4 +- docs/resources/mariadb_credential.md | 4 +- docs/resources/opensearch_credential.md | 4 +- docs/resources/postgresql_credential.md | 4 +- docs/resources/rabbitmq_credential.md | 4 +- docs/resources/redis_credential.md | 4 +- .../stackit_logme_credential/data-source.tf | 6 +- .../stackit_mariadb_credential/data-source.tf | 6 +- .../data-source.tf | 6 +- .../data-source.tf | 6 +- .../data-source.tf | 6 +- .../stackit_redis_credential/data-source.tf | 6 +- .../services/logme/credential/datasource.go | 24 ++--- .../services/logme/credential/resource.go | 88 +++++++++---------- .../logme/credential/resource_test.go | 58 ++++++------ .../internal/services/logme/logme_acc_test.go | 48 +++++----- .../services/mariadb/credential/datasource.go | 24 ++--- .../services/mariadb/credential/resource.go | 88 +++++++++---------- .../mariadb/credential/resource_test.go | 58 ++++++------ .../services/mariadb/mariadb_acc_test.go | 48 +++++----- .../opensearch/credential/datasource.go | 24 ++--- .../opensearch/credential/resource.go | 88 +++++++++---------- .../opensearch/credential/resource_test.go | 58 ++++++------ .../opensearch/opensearch_acc_test.go | 50 +++++------ .../postgresql/credential/datasource.go | 24 ++--- .../postgresql/credential/resource.go | 88 +++++++++---------- .../postgresql/credential/resource_test.go | 58 ++++++------ .../postgresql/postgresql_acc_test.go | 48 +++++----- .../rabbitmq/credential/datasource.go | 24 ++--- .../services/rabbitmq/credential/resource.go | 88 +++++++++---------- .../rabbitmq/credential/resource_test.go | 58 ++++++------ .../services/rabbitmq/rabbitmq_acc_test.go | 54 ++++++------ .../services/redis/credential/datasource.go | 24 ++--- .../services/redis/credential/resource.go | 88 +++++++++---------- .../redis/credential/resource_test.go | 58 ++++++------ .../internal/services/redis/redis_acc_test.go | 52 +++++------ 43 files changed, 722 insertions(+), 722 deletions(-) diff --git a/MIGRATION.md b/MIGRATION.md index 66e3c239..6ee528d4 100644 --- a/MIGRATION.md +++ b/MIGRATION.md @@ -97,7 +97,7 @@ import { } import { - id = "project_id,instance_id,credentials_id" + id = "project_id,instance_id,credential_id" to = stackit_logme_credential.example-credential } ``` @@ -119,7 +119,7 @@ resource "stackit_logme_instance" "example-instance" { version = null } -# __generated__ by Terraform from "project_id,instance_id,credentials_id" +# __generated__ by Terraform from "project_id,instance_id,credential_id" resource "stackit_logme_credential" "example-credential" { instance_id = "instance_id" project_id = "project_id" diff --git a/docs/data-sources/logme_credential.md b/docs/data-sources/logme_credential.md index 8c781108..4a45b478 100644 --- a/docs/data-sources/logme_credential.md +++ b/docs/data-sources/logme_credential.md @@ -14,9 +14,9 @@ LogMe credential data source schema. ```terraform data "stackit_logme_credential" "example" { - project_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" - instance_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" - credentials_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" + project_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" + instance_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" + credential_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" } ``` @@ -25,7 +25,7 @@ data "stackit_logme_credential" "example" { ### Required -- `credentials_id` (String) The credentials ID. +- `credential_id` (String) The credential's ID. - `instance_id` (String) ID of the LogMe instance. - `project_id` (String) STACKIT project ID to which the instance is associated. @@ -34,7 +34,7 @@ data "stackit_logme_credential" "example" { - `host` (String) - `hosts` (List of String) - `http_api_uri` (String) -- `id` (String) Terraform's internal data source. identifier. It is structured as "`project_id`,`instance_id`,`credentials_id`". +- `id` (String) Terraform's internal data source. identifier. It is structured as "`project_id`,`instance_id`,`credential_id`". - `name` (String) - `password` (String, Sensitive) - `port` (Number) diff --git a/docs/data-sources/mariadb_credential.md b/docs/data-sources/mariadb_credential.md index a72ab8ac..790874ce 100644 --- a/docs/data-sources/mariadb_credential.md +++ b/docs/data-sources/mariadb_credential.md @@ -14,9 +14,9 @@ MariaDB credential data source schema. ```terraform data "stackit_mariadb_credential" "example" { - project_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" - instance_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" - credentials_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" + project_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" + instance_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" + credential_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" } ``` @@ -25,7 +25,7 @@ data "stackit_mariadb_credential" "example" { ### Required -- `credentials_id` (String) The credentials ID. +- `credential_id` (String) The credential's ID. - `instance_id` (String) ID of the MariaDB instance. - `project_id` (String) STACKIT project ID to which the instance is associated. @@ -34,7 +34,7 @@ data "stackit_mariadb_credential" "example" { - `host` (String) - `hosts` (List of String) - `http_api_uri` (String) -- `id` (String) Terraform's internal data source. identifier. It is structured as "`project_id`,`instance_id`,`credentials_id`". +- `id` (String) Terraform's internal data source. identifier. It is structured as "`project_id`,`instance_id`,`credential_id`". - `name` (String) - `password` (String, Sensitive) - `port` (Number) diff --git a/docs/data-sources/opensearch_credential.md b/docs/data-sources/opensearch_credential.md index a2ae3f89..da009669 100644 --- a/docs/data-sources/opensearch_credential.md +++ b/docs/data-sources/opensearch_credential.md @@ -14,9 +14,9 @@ OpenSearch credential data source schema. ```terraform data "stackit_opensearch_credential" "example" { - project_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" - instance_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" - credentials_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" + project_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" + instance_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" + credential_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" } ``` @@ -25,7 +25,7 @@ data "stackit_opensearch_credential" "example" { ### Required -- `credentials_id` (String) The credentials ID. +- `credential_id` (String) The credential's ID. - `instance_id` (String) ID of the OpenSearch instance. - `project_id` (String) STACKIT project ID to which the instance is associated. @@ -34,7 +34,7 @@ data "stackit_opensearch_credential" "example" { - `host` (String) - `hosts` (List of String) - `http_api_uri` (String) -- `id` (String) Terraform's internal data source. identifier. It is structured as "`project_id`,`instance_id`,`credentials_id`". +- `id` (String) Terraform's internal data source. identifier. It is structured as "`project_id`,`instance_id`,`credential_id`". - `name` (String) - `password` (String, Sensitive) - `port` (Number) diff --git a/docs/data-sources/postgresql_credential.md b/docs/data-sources/postgresql_credential.md index e65f5ce0..b75f6247 100644 --- a/docs/data-sources/postgresql_credential.md +++ b/docs/data-sources/postgresql_credential.md @@ -14,9 +14,9 @@ PostgreSQL credential data source schema. ```terraform data "stackit_postgresql_credential" "example" { - project_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" - instance_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" - credentials_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" + project_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" + instance_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" + credential_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" } ``` @@ -25,7 +25,7 @@ data "stackit_postgresql_credential" "example" { ### Required -- `credentials_id` (String) The credentials ID. +- `credential_id` (String) The credential's ID. - `instance_id` (String) ID of the PostgreSQL instance. - `project_id` (String) STACKIT project ID to which the instance is associated. @@ -34,7 +34,7 @@ data "stackit_postgresql_credential" "example" { - `host` (String) - `hosts` (List of String) - `http_api_uri` (String) -- `id` (String) Terraform's internal data source. identifier. It is structured as "`project_id`,`instance_id`,`credentials_id`". +- `id` (String) Terraform's internal data source. identifier. It is structured as "`project_id`,`instance_id`,`credential_id`". - `name` (String) - `password` (String, Sensitive) - `port` (Number) diff --git a/docs/data-sources/rabbitmq_credential.md b/docs/data-sources/rabbitmq_credential.md index 2e5eef28..f5a315f9 100644 --- a/docs/data-sources/rabbitmq_credential.md +++ b/docs/data-sources/rabbitmq_credential.md @@ -14,9 +14,9 @@ RabbitMQ credential data source schema. ```terraform data "stackit_rabbitmq_credential" "example" { - project_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" - instance_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" - credentials_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" + project_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" + instance_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" + credential_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" } ``` @@ -25,7 +25,7 @@ data "stackit_rabbitmq_credential" "example" { ### Required -- `credentials_id` (String) The credentials ID. +- `credential_id` (String) The credential's ID. - `instance_id` (String) ID of the RabbitMQ instance. - `project_id` (String) STACKIT project ID to which the instance is associated. @@ -34,7 +34,7 @@ data "stackit_rabbitmq_credential" "example" { - `host` (String) - `hosts` (List of String) - `http_api_uri` (String) -- `id` (String) Terraform's internal data source. identifier. It is structured as "`project_id`,`instance_id`,`credentials_id`". +- `id` (String) Terraform's internal data source. identifier. It is structured as "`project_id`,`instance_id`,`credential_id`". - `name` (String) - `password` (String, Sensitive) - `port` (Number) diff --git a/docs/data-sources/redis_credential.md b/docs/data-sources/redis_credential.md index 66ce4e27..d100f29f 100644 --- a/docs/data-sources/redis_credential.md +++ b/docs/data-sources/redis_credential.md @@ -14,9 +14,9 @@ Redis credential data source schema. ```terraform data "stackit_redis_credential" "example" { - project_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" - instance_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" - credentials_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" + project_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" + instance_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" + credential_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" } ``` @@ -25,7 +25,7 @@ data "stackit_redis_credential" "example" { ### Required -- `credentials_id` (String) The credentials ID. +- `credential_id` (String) The credential's ID. - `instance_id` (String) ID of the Redis instance. - `project_id` (String) STACKIT project ID to which the instance is associated. @@ -34,7 +34,7 @@ data "stackit_redis_credential" "example" { - `host` (String) - `hosts` (List of String) - `http_api_uri` (String) -- `id` (String) Terraform's internal data source. identifier. It is structured as "`project_id`,`instance_id`,`credentials_id`". +- `id` (String) Terraform's internal data source. identifier. It is structured as "`project_id`,`instance_id`,`credential_id`". - `name` (String) - `password` (String, Sensitive) - `port` (Number) diff --git a/docs/resources/logme_credential.md b/docs/resources/logme_credential.md index cfc8d30c..4956f612 100644 --- a/docs/resources/logme_credential.md +++ b/docs/resources/logme_credential.md @@ -29,11 +29,11 @@ resource "stackit_logme_credential" "example" { ### Read-Only -- `credentials_id` (String) The credentials ID. +- `credential_id` (String) The credential's ID. - `host` (String) - `hosts` (List of String) - `http_api_uri` (String) -- `id` (String) Terraform's internal resource identifier. It is structured as "`project_id`,`instance_id`,`credentials_id`". +- `id` (String) Terraform's internal resource identifier. It is structured as "`project_id`,`instance_id`,`credential_id`". - `name` (String) - `password` (String, Sensitive) - `port` (Number) diff --git a/docs/resources/mariadb_credential.md b/docs/resources/mariadb_credential.md index 8e0b24e8..ae417eb5 100644 --- a/docs/resources/mariadb_credential.md +++ b/docs/resources/mariadb_credential.md @@ -29,11 +29,11 @@ resource "stackit_mariadb_credential" "example" { ### Read-Only -- `credentials_id` (String) The credentials ID. +- `credential_id` (String) The credential's ID. - `host` (String) - `hosts` (List of String) - `http_api_uri` (String) -- `id` (String) Terraform's internal resource identifier. It is structured as "`project_id`,`instance_id`,`credentials_id`". +- `id` (String) Terraform's internal resource identifier. It is structured as "`project_id`,`instance_id`,`credential_id`". - `name` (String) - `password` (String, Sensitive) - `port` (Number) diff --git a/docs/resources/opensearch_credential.md b/docs/resources/opensearch_credential.md index 6c6ff442..235236a8 100644 --- a/docs/resources/opensearch_credential.md +++ b/docs/resources/opensearch_credential.md @@ -29,11 +29,11 @@ resource "stackit_opensearch_credential" "example" { ### Read-Only -- `credentials_id` (String) The credentials ID. +- `credential_id` (String) The credential's ID. - `host` (String) - `hosts` (List of String) - `http_api_uri` (String) -- `id` (String) Terraform's internal resource identifier. It is structured as "`project_id`,`instance_id`,`credentials_id`". +- `id` (String) Terraform's internal resource identifier. It is structured as "`project_id`,`instance_id`,`credential_id`". - `name` (String) - `password` (String, Sensitive) - `port` (Number) diff --git a/docs/resources/postgresql_credential.md b/docs/resources/postgresql_credential.md index 8d587f75..42cd0800 100644 --- a/docs/resources/postgresql_credential.md +++ b/docs/resources/postgresql_credential.md @@ -29,11 +29,11 @@ resource "stackit_postgresql_credential" "example" { ### Read-Only -- `credentials_id` (String) The credentials ID. +- `credential_id` (String) The credential's ID. - `host` (String) - `hosts` (List of String) - `http_api_uri` (String) -- `id` (String) Terraform's internal resource identifier. It is structured as "`project_id`,`instance_id`,`credentials_id`". +- `id` (String) Terraform's internal resource identifier. It is structured as "`project_id`,`instance_id`,`credential_id`". - `name` (String) - `password` (String, Sensitive) - `port` (Number) diff --git a/docs/resources/rabbitmq_credential.md b/docs/resources/rabbitmq_credential.md index e37efe47..12862a99 100644 --- a/docs/resources/rabbitmq_credential.md +++ b/docs/resources/rabbitmq_credential.md @@ -29,11 +29,11 @@ resource "stackit_rabbitmq_credential" "example" { ### Read-Only -- `credentials_id` (String) The credentials ID. +- `credential_id` (String) The credential's ID. - `host` (String) - `hosts` (List of String) - `http_api_uri` (String) -- `id` (String) Terraform's internal resource identifier. It is structured as "`project_id`,`instance_id`,`credentials_id`". +- `id` (String) Terraform's internal resource identifier. It is structured as "`project_id`,`instance_id`,`credential_id`". - `name` (String) - `password` (String, Sensitive) - `port` (Number) diff --git a/docs/resources/redis_credential.md b/docs/resources/redis_credential.md index 87e4911f..cb711c42 100644 --- a/docs/resources/redis_credential.md +++ b/docs/resources/redis_credential.md @@ -29,11 +29,11 @@ resource "stackit_redis_credential" "example" { ### Read-Only -- `credentials_id` (String) The credentials ID. +- `credential_id` (String) The credential's ID. - `host` (String) - `hosts` (List of String) - `http_api_uri` (String) -- `id` (String) Terraform's internal resource identifier. It is structured as "`project_id`,`instance_id`,`credentials_id`". +- `id` (String) Terraform's internal resource identifier. It is structured as "`project_id`,`instance_id`,`credential_id`". - `name` (String) - `password` (String, Sensitive) - `port` (Number) diff --git a/examples/data-sources/stackit_logme_credential/data-source.tf b/examples/data-sources/stackit_logme_credential/data-source.tf index 513579b8..d6ea7216 100644 --- a/examples/data-sources/stackit_logme_credential/data-source.tf +++ b/examples/data-sources/stackit_logme_credential/data-source.tf @@ -1,5 +1,5 @@ data "stackit_logme_credential" "example" { - project_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" - instance_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" - credentials_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" + project_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" + instance_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" + credential_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" } diff --git a/examples/data-sources/stackit_mariadb_credential/data-source.tf b/examples/data-sources/stackit_mariadb_credential/data-source.tf index 7e8fbe10..7adeb138 100644 --- a/examples/data-sources/stackit_mariadb_credential/data-source.tf +++ b/examples/data-sources/stackit_mariadb_credential/data-source.tf @@ -1,5 +1,5 @@ data "stackit_mariadb_credential" "example" { - project_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" - instance_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" - credentials_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" + project_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" + instance_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" + credential_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" } diff --git a/examples/data-sources/stackit_opensearch_credential/data-source.tf b/examples/data-sources/stackit_opensearch_credential/data-source.tf index c380fd50..0cc9149b 100644 --- a/examples/data-sources/stackit_opensearch_credential/data-source.tf +++ b/examples/data-sources/stackit_opensearch_credential/data-source.tf @@ -1,5 +1,5 @@ data "stackit_opensearch_credential" "example" { - project_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" - instance_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" - credentials_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" + project_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" + instance_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" + credential_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" } diff --git a/examples/data-sources/stackit_postgresql_credential/data-source.tf b/examples/data-sources/stackit_postgresql_credential/data-source.tf index dd53a75d..36893859 100644 --- a/examples/data-sources/stackit_postgresql_credential/data-source.tf +++ b/examples/data-sources/stackit_postgresql_credential/data-source.tf @@ -1,5 +1,5 @@ data "stackit_postgresql_credential" "example" { - project_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" - instance_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" - credentials_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" + project_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" + instance_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" + credential_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" } diff --git a/examples/data-sources/stackit_rabbitmq_credential/data-source.tf b/examples/data-sources/stackit_rabbitmq_credential/data-source.tf index 37827ec6..d0d37058 100644 --- a/examples/data-sources/stackit_rabbitmq_credential/data-source.tf +++ b/examples/data-sources/stackit_rabbitmq_credential/data-source.tf @@ -1,5 +1,5 @@ data "stackit_rabbitmq_credential" "example" { - project_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" - instance_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" - credentials_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" + project_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" + instance_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" + credential_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" } diff --git a/examples/data-sources/stackit_redis_credential/data-source.tf b/examples/data-sources/stackit_redis_credential/data-source.tf index 08bba4c3..9f96c089 100644 --- a/examples/data-sources/stackit_redis_credential/data-source.tf +++ b/examples/data-sources/stackit_redis_credential/data-source.tf @@ -1,5 +1,5 @@ data "stackit_redis_credential" "example" { - project_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" - instance_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" - credentials_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" + project_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" + instance_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" + credential_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" } diff --git a/stackit/internal/services/logme/credential/datasource.go b/stackit/internal/services/logme/credential/datasource.go index 7d633f51..8bfe5e0b 100644 --- a/stackit/internal/services/logme/credential/datasource.go +++ b/stackit/internal/services/logme/credential/datasource.go @@ -69,17 +69,17 @@ func (r *credentialDataSource) Configure(ctx context.Context, req datasource.Con } r.client = apiClient - tflog.Info(ctx, "LogMe credentials client configured") + tflog.Info(ctx, "LogMe credential client configured") } // Schema defines the schema for the data source. func (r *credentialDataSource) Schema(_ context.Context, _ datasource.SchemaRequest, resp *datasource.SchemaResponse) { descriptions := map[string]string{ - "main": "LogMe credential data source schema.", - "id": "Terraform's internal data source. identifier. It is structured as \"`project_id`,`instance_id`,`credentials_id`\".", - "credentials_id": "The credentials ID.", - "instance_id": "ID of the LogMe instance.", - "project_id": "STACKIT project ID to which the instance is associated.", + "main": "LogMe credential data source schema.", + "id": "Terraform's internal data source. identifier. It is structured as \"`project_id`,`instance_id`,`credential_id`\".", + "credential_id": "The credential's ID.", + "instance_id": "ID of the LogMe instance.", + "project_id": "STACKIT project ID to which the instance is associated.", } resp.Schema = schema.Schema{ @@ -89,8 +89,8 @@ func (r *credentialDataSource) Schema(_ context.Context, _ datasource.SchemaRequ Description: descriptions["id"], Computed: true, }, - "credentials_id": schema.StringAttribute{ - Description: descriptions["credentials_id"], + "credential_id": schema.StringAttribute{ + Description: descriptions["credential_id"], Required: true, Validators: []validator.String{ validate.UUID(), @@ -153,12 +153,12 @@ func (r *credentialDataSource) Read(ctx context.Context, req datasource.ReadRequ } projectId := model.ProjectId.ValueString() instanceId := model.InstanceId.ValueString() - credentialsId := model.CredentialsId.ValueString() + credentialId := model.CredentialId.ValueString() ctx = tflog.SetField(ctx, "project_id", projectId) ctx = tflog.SetField(ctx, "instance_id", instanceId) - ctx = tflog.SetField(ctx, "credentials_id", credentialsId) + ctx = tflog.SetField(ctx, "credential_id", credentialId) - recordSetResp, err := r.client.GetCredentials(ctx, projectId, instanceId, credentialsId).Execute() + recordSetResp, err := r.client.GetCredentials(ctx, projectId, instanceId, credentialId).Execute() if err != nil { core.LogAndAddError(ctx, &resp.Diagnostics, "Error reading credential", fmt.Sprintf("Calling API: %v", err)) return @@ -177,5 +177,5 @@ func (r *credentialDataSource) Read(ctx context.Context, req datasource.ReadRequ if resp.Diagnostics.HasError() { return } - tflog.Info(ctx, "LogMe credentials read") + tflog.Info(ctx, "LogMe credential read") } diff --git a/stackit/internal/services/logme/credential/resource.go b/stackit/internal/services/logme/credential/resource.go index 369661b1..f02b4d53 100644 --- a/stackit/internal/services/logme/credential/resource.go +++ b/stackit/internal/services/logme/credential/resource.go @@ -32,18 +32,18 @@ var ( ) type Model struct { - Id types.String `tfsdk:"id"` // needed by TF - CredentialsId types.String `tfsdk:"credentials_id"` - InstanceId types.String `tfsdk:"instance_id"` - ProjectId types.String `tfsdk:"project_id"` - Host types.String `tfsdk:"host"` - Hosts types.List `tfsdk:"hosts"` - HttpAPIURI types.String `tfsdk:"http_api_uri"` - Name types.String `tfsdk:"name"` - Password types.String `tfsdk:"password"` - Port types.Int64 `tfsdk:"port"` - Uri types.String `tfsdk:"uri"` - Username types.String `tfsdk:"username"` + Id types.String `tfsdk:"id"` // needed by TF + CredentialId types.String `tfsdk:"credential_id"` + InstanceId types.String `tfsdk:"instance_id"` + ProjectId types.String `tfsdk:"project_id"` + Host types.String `tfsdk:"host"` + Hosts types.List `tfsdk:"hosts"` + HttpAPIURI types.String `tfsdk:"http_api_uri"` + Name types.String `tfsdk:"name"` + Password types.String `tfsdk:"password"` + Port types.Int64 `tfsdk:"port"` + Uri types.String `tfsdk:"uri"` + Username types.String `tfsdk:"username"` } // NewCredentialResource is a helper function to simplify the provider implementation. @@ -94,17 +94,17 @@ func (r *credentialResource) Configure(ctx context.Context, req resource.Configu } r.client = apiClient - tflog.Info(ctx, "LogMe credentials client configured") + tflog.Info(ctx, "LogMe credential client configured") } // Schema defines the schema for the resource. func (r *credentialResource) Schema(_ context.Context, _ resource.SchemaRequest, resp *resource.SchemaResponse) { descriptions := map[string]string{ - "main": "LogMe credential resource schema.", - "id": "Terraform's internal resource identifier. It is structured as \"`project_id`,`instance_id`,`credentials_id`\".", - "credentials_id": "The credentials ID.", - "instance_id": "ID of the LogMe instance.", - "project_id": "STACKIT Project ID to which the instance is associated.", + "main": "LogMe credential resource schema.", + "id": "Terraform's internal resource identifier. It is structured as \"`project_id`,`instance_id`,`credential_id`\".", + "credential_id": "The credential's ID.", + "instance_id": "ID of the LogMe instance.", + "project_id": "STACKIT Project ID to which the instance is associated.", } resp.Schema = schema.Schema{ @@ -117,8 +117,8 @@ func (r *credentialResource) Schema(_ context.Context, _ resource.SchemaRequest, stringplanmodifier.UseStateForUnknown(), }, }, - "credentials_id": schema.StringAttribute{ - Description: descriptions["credentials_id"], + "credential_id": schema.StringAttribute{ + Description: descriptions["credential_id"], Computed: true, PlanModifiers: []planmodifier.String{ stringplanmodifier.UseStateForUnknown(), @@ -202,13 +202,13 @@ func (r *credentialResource) Create(ctx context.Context, req resource.CreateRequ return } if credentialsResp.Id == nil { - core.LogAndAddError(ctx, &resp.Diagnostics, "Error creating credential", "Got empty credentials id") + core.LogAndAddError(ctx, &resp.Diagnostics, "Error creating credential", "Got empty credential id") return } - credentialsId := *credentialsResp.Id - ctx = tflog.SetField(ctx, "credentials_id", credentialsId) + credentialId := *credentialsResp.Id + ctx = tflog.SetField(ctx, "credential_id", credentialId) - wr, err := wait.CreateCredentialsWaitHandler(ctx, r.client, projectId, instanceId, credentialsId).SetTimeout(1 * time.Minute).WaitWithContext(ctx) + wr, err := wait.CreateCredentialsWaitHandler(ctx, r.client, projectId, instanceId, credentialId).SetTimeout(1 * time.Minute).WaitWithContext(ctx) if err != nil { core.LogAndAddError(ctx, &resp.Diagnostics, "Error creating credential", fmt.Sprintf("Instance creation waiting: %v", err)) return @@ -230,7 +230,7 @@ func (r *credentialResource) Create(ctx context.Context, req resource.CreateRequ if resp.Diagnostics.HasError() { return } - tflog.Info(ctx, "LogMe credentials created") + tflog.Info(ctx, "LogMe credential created") } // Read refreshes the Terraform state with the latest data. @@ -243,12 +243,12 @@ func (r *credentialResource) Read(ctx context.Context, req resource.ReadRequest, } projectId := model.ProjectId.ValueString() instanceId := model.InstanceId.ValueString() - credentialsId := model.CredentialsId.ValueString() + credentialId := model.CredentialId.ValueString() ctx = tflog.SetField(ctx, "project_id", projectId) ctx = tflog.SetField(ctx, "instance_id", instanceId) - ctx = tflog.SetField(ctx, "credentials_id", credentialsId) + ctx = tflog.SetField(ctx, "credential_id", credentialId) - recordSetResp, err := r.client.GetCredentials(ctx, projectId, instanceId, credentialsId).Execute() + recordSetResp, err := r.client.GetCredentials(ctx, projectId, instanceId, credentialId).Execute() if err != nil { core.LogAndAddError(ctx, &resp.Diagnostics, "Error reading credential", fmt.Sprintf("Calling API: %v", err)) return @@ -267,7 +267,7 @@ func (r *credentialResource) Read(ctx context.Context, req resource.ReadRequest, if resp.Diagnostics.HasError() { return } - tflog.Info(ctx, "LogMe credentials read") + tflog.Info(ctx, "LogMe credential read") } // Update updates the resource and sets the updated Terraform state on success. @@ -287,40 +287,40 @@ func (r *credentialResource) Delete(ctx context.Context, req resource.DeleteRequ projectId := model.ProjectId.ValueString() instanceId := model.InstanceId.ValueString() - credentialsId := model.CredentialsId.ValueString() + credentialId := model.CredentialId.ValueString() ctx = tflog.SetField(ctx, "project_id", projectId) ctx = tflog.SetField(ctx, "instance_id", instanceId) - ctx = tflog.SetField(ctx, "credentials_id", credentialsId) + ctx = tflog.SetField(ctx, "credential_id", credentialId) // Delete existing record set - err := r.client.DeleteCredentials(ctx, projectId, instanceId, credentialsId).Execute() + err := r.client.DeleteCredentials(ctx, projectId, instanceId, credentialId).Execute() if err != nil { core.LogAndAddError(ctx, &resp.Diagnostics, "Error deleting credential", fmt.Sprintf("Calling API: %v", err)) } - _, err = wait.DeleteCredentialsWaitHandler(ctx, r.client, projectId, instanceId, credentialsId).SetTimeout(1 * time.Minute).WaitWithContext(ctx) + _, err = wait.DeleteCredentialsWaitHandler(ctx, r.client, projectId, instanceId, credentialId).SetTimeout(1 * time.Minute).WaitWithContext(ctx) if err != nil { core.LogAndAddError(ctx, &resp.Diagnostics, "Error deleting credential", fmt.Sprintf("Instance deletion waiting: %v", err)) return } - tflog.Info(ctx, "LogMe credentials deleted") + tflog.Info(ctx, "LogMe credential deleted") } // ImportState imports a resource into the Terraform state on success. -// The expected format of the resource import identifier is: project_id,instance_id,credentials_id +// The expected format of the resource import identifier is: project_id,instance_id,credential_id func (r *credentialResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { idParts := strings.Split(req.ID, core.Separator) if len(idParts) != 3 || idParts[0] == "" || idParts[1] == "" || idParts[2] == "" { core.LogAndAddError(ctx, &resp.Diagnostics, "Error importing credential", - fmt.Sprintf("Expected import identifier with format [project_id],[instance_id],[credentials_id], got %q", req.ID), + fmt.Sprintf("Expected import identifier with format [project_id],[instance_id],[credential_id], got %q", req.ID), ) return } resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("project_id"), idParts[0])...) resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("instance_id"), idParts[1])...) - resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("credentials_id"), idParts[2])...) - tflog.Info(ctx, "LogMe credentials state imported") + resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("credential_id"), idParts[2])...) + tflog.Info(ctx, "LogMe credential state imported") } func mapFields(credentialsResp *logme.CredentialsResponse, model *Model) error { @@ -335,11 +335,11 @@ func mapFields(credentialsResp *logme.CredentialsResponse, model *Model) error { } credentials := credentialsResp.Raw.Credentials - var credentialsId string - if model.CredentialsId.ValueString() != "" { - credentialsId = model.CredentialsId.ValueString() + var credentialId string + if model.CredentialId.ValueString() != "" { + credentialId = model.CredentialId.ValueString() } else if credentialsResp.Id != nil { - credentialsId = *credentialsResp.Id + credentialId = *credentialsResp.Id } else { return fmt.Errorf("credentials id not present") } @@ -347,12 +347,12 @@ func mapFields(credentialsResp *logme.CredentialsResponse, model *Model) error { idParts := []string{ model.ProjectId.ValueString(), model.InstanceId.ValueString(), - credentialsId, + credentialId, } model.Id = types.StringValue( strings.Join(idParts, core.Separator), ) - model.CredentialsId = types.StringValue(credentialsId) + model.CredentialId = types.StringValue(credentialId) model.Hosts = types.ListNull(types.StringType) if credentials != nil { if credentials.Hosts != nil { diff --git a/stackit/internal/services/logme/credential/resource_test.go b/stackit/internal/services/logme/credential/resource_test.go index e690f781..2aab4a40 100644 --- a/stackit/internal/services/logme/credential/resource_test.go +++ b/stackit/internal/services/logme/credential/resource_test.go @@ -24,18 +24,18 @@ func TestMapFields(t *testing.T) { Raw: &logme.RawCredentials{}, }, Model{ - Id: types.StringValue("pid,iid,cid"), - CredentialsId: types.StringValue("cid"), - InstanceId: types.StringValue("iid"), - ProjectId: types.StringValue("pid"), - Host: types.StringNull(), - Hosts: types.ListNull(types.StringType), - HttpAPIURI: types.StringNull(), - Name: types.StringNull(), - Password: types.StringNull(), - Port: types.Int64Null(), - Uri: types.StringNull(), - Username: types.StringNull(), + Id: types.StringValue("pid,iid,cid"), + CredentialId: types.StringValue("cid"), + InstanceId: types.StringValue("iid"), + ProjectId: types.StringValue("pid"), + Host: types.StringNull(), + Hosts: types.ListNull(types.StringType), + HttpAPIURI: types.StringNull(), + Name: types.StringNull(), + Password: types.StringNull(), + Port: types.Int64Null(), + Uri: types.StringNull(), + Username: types.StringNull(), }, true, }, @@ -60,11 +60,11 @@ func TestMapFields(t *testing.T) { }, }, Model{ - Id: types.StringValue("pid,iid,cid"), - CredentialsId: types.StringValue("cid"), - InstanceId: types.StringValue("iid"), - ProjectId: types.StringValue("pid"), - Host: types.StringValue("host"), + Id: types.StringValue("pid,iid,cid"), + CredentialId: types.StringValue("cid"), + InstanceId: types.StringValue("iid"), + ProjectId: types.StringValue("pid"), + Host: types.StringValue("host"), Hosts: types.ListValueMust(types.StringType, []attr.Value{ types.StringValue("host_1"), types.StringValue(""), @@ -96,18 +96,18 @@ func TestMapFields(t *testing.T) { }, }, Model{ - Id: types.StringValue("pid,iid,cid"), - CredentialsId: types.StringValue("cid"), - InstanceId: types.StringValue("iid"), - ProjectId: types.StringValue("pid"), - Host: types.StringValue(""), - Hosts: types.ListValueMust(types.StringType, []attr.Value{}), - HttpAPIURI: types.StringNull(), - Name: types.StringNull(), - Password: types.StringValue(""), - Port: types.Int64Value(2123456789), - Uri: types.StringNull(), - Username: types.StringValue(""), + Id: types.StringValue("pid,iid,cid"), + CredentialId: types.StringValue("cid"), + InstanceId: types.StringValue("iid"), + ProjectId: types.StringValue("pid"), + Host: types.StringValue(""), + Hosts: types.ListValueMust(types.StringType, []attr.Value{}), + HttpAPIURI: types.StringNull(), + Name: types.StringNull(), + Password: types.StringValue(""), + Port: types.Int64Value(2123456789), + Uri: types.StringNull(), + Username: types.StringValue(""), }, true, }, diff --git a/stackit/internal/services/logme/logme_acc_test.go b/stackit/internal/services/logme/logme_acc_test.go index a59a1104..d4b74234 100644 --- a/stackit/internal/services/logme/logme_acc_test.go +++ b/stackit/internal/services/logme/logme_acc_test.go @@ -41,7 +41,7 @@ func resourceConfig(acls string) string { } } - resource "stackit_logme_credential" "credentials" { + resource "stackit_logme_credential" "credential" { project_id = stackit_logme_instance.instance.project_id instance_id = stackit_logme_instance.instance.instance_id } @@ -73,17 +73,17 @@ func TestAccLogMeResource(t *testing.T) { resource.TestCheckResourceAttr("stackit_logme_instance.instance", "name", instanceResource["name"]), resource.TestCheckResourceAttr("stackit_logme_instance.instance", "parameters.sgw_acl", instanceResource["sgw_acl-1"]), - // Credentials data + // Credential data resource.TestCheckResourceAttrPair( - "stackit_logme_credential.credentials", "project_id", + "stackit_logme_credential.credential", "project_id", "stackit_logme_instance.instance", "project_id", ), resource.TestCheckResourceAttrPair( - "stackit_logme_credential.credentials", "instance_id", + "stackit_logme_credential.credential", "instance_id", "stackit_logme_instance.instance", "instance_id", ), - resource.TestCheckResourceAttrSet("stackit_logme_credential.credentials", "credentials_id"), - resource.TestCheckResourceAttrSet("stackit_logme_credential.credentials", "host"), + resource.TestCheckResourceAttrSet("stackit_logme_credential.credential", "credential_id"), + resource.TestCheckResourceAttrSet("stackit_logme_credential.credential", "host"), ), }, // Data source @@ -96,10 +96,10 @@ func TestAccLogMeResource(t *testing.T) { instance_id = stackit_logme_instance.instance.instance_id } - data "stackit_logme_credential" "credentials" { - project_id = stackit_logme_credential.credentials.project_id - instance_id = stackit_logme_credential.credentials.instance_id - credentials_id = stackit_logme_credential.credentials.credentials_id + data "stackit_logme_credential" "credential" { + project_id = stackit_logme_credential.credential.project_id + instance_id = stackit_logme_credential.credential.instance_id + credential_id = stackit_logme_credential.credential.credential_id }`, resourceConfig(instanceResource["sgw_acl-1"]), ), @@ -109,18 +109,18 @@ func TestAccLogMeResource(t *testing.T) { resource.TestCheckResourceAttrPair("stackit_logme_instance.instance", "instance_id", "data.stackit_logme_instance.instance", "instance_id"), - resource.TestCheckResourceAttrPair("stackit_logme_credential.credentials", "credentials_id", - "data.stackit_logme_credential.credentials", "credentials_id"), + resource.TestCheckResourceAttrPair("stackit_logme_credential.credential", "credential_id", + "data.stackit_logme_credential.credential", "credential_id"), resource.TestCheckResourceAttr("data.stackit_logme_instance.instance", "plan_id", instanceResource["plan_id"]), resource.TestCheckResourceAttr("data.stackit_logme_instance.instance", "name", instanceResource["name"]), resource.TestCheckResourceAttr("data.stackit_logme_instance.instance", "parameters.sgw_acl", instanceResource["sgw_acl-1"]), - // Credentials data - resource.TestCheckResourceAttr("data.stackit_logme_credential.credentials", "project_id", instanceResource["project_id"]), - resource.TestCheckResourceAttrSet("data.stackit_logme_credential.credentials", "credentials_id"), - resource.TestCheckResourceAttrSet("data.stackit_logme_credential.credentials", "host"), - resource.TestCheckResourceAttrSet("data.stackit_logme_credential.credentials", "port"), - resource.TestCheckResourceAttrSet("data.stackit_logme_credential.credentials", "uri"), + // Credential data + resource.TestCheckResourceAttr("data.stackit_logme_credential.credential", "project_id", instanceResource["project_id"]), + resource.TestCheckResourceAttrSet("data.stackit_logme_credential.credential", "credential_id"), + resource.TestCheckResourceAttrSet("data.stackit_logme_credential.credential", "host"), + resource.TestCheckResourceAttrSet("data.stackit_logme_credential.credential", "port"), + resource.TestCheckResourceAttrSet("data.stackit_logme_credential.credential", "uri"), ), }, // Import @@ -141,21 +141,21 @@ func TestAccLogMeResource(t *testing.T) { ImportStateVerify: true, }, { - ResourceName: "stackit_logme_credential.credentials", + ResourceName: "stackit_logme_credential.credential", ImportStateIdFunc: func(s *terraform.State) (string, error) { - r, ok := s.RootModule().Resources["stackit_logme_credential.credentials"] + r, ok := s.RootModule().Resources["stackit_logme_credential.credential"] if !ok { - return "", fmt.Errorf("couldn't find resource stackit_logme_credential.credentials") + return "", fmt.Errorf("couldn't find resource stackit_logme_credential.credential") } instanceId, ok := r.Primary.Attributes["instance_id"] if !ok { return "", fmt.Errorf("couldn't find attribute instance_id") } - credentialsId, ok := r.Primary.Attributes["credentials_id"] + credentialId, ok := r.Primary.Attributes["credential_id"] if !ok { - return "", fmt.Errorf("couldn't find attribute credentials_id") + return "", fmt.Errorf("couldn't find attribute credential_id") } - return fmt.Sprintf("%s,%s,%s", testutil.ProjectId, instanceId, credentialsId), nil + return fmt.Sprintf("%s,%s,%s", testutil.ProjectId, instanceId, credentialId), nil }, ImportState: true, ImportStateVerify: true, diff --git a/stackit/internal/services/mariadb/credential/datasource.go b/stackit/internal/services/mariadb/credential/datasource.go index be81fc81..c2fbcf51 100644 --- a/stackit/internal/services/mariadb/credential/datasource.go +++ b/stackit/internal/services/mariadb/credential/datasource.go @@ -69,17 +69,17 @@ func (r *credentialDataSource) Configure(ctx context.Context, req datasource.Con } r.client = apiClient - tflog.Info(ctx, "mariadb credentials client configured") + tflog.Info(ctx, "mariadb credential client configured") } // Schema defines the schema for the data source. func (r *credentialDataSource) Schema(_ context.Context, _ datasource.SchemaRequest, resp *datasource.SchemaResponse) { descriptions := map[string]string{ - "main": "MariaDB credential data source schema.", - "id": "Terraform's internal data source. identifier. It is structured as \"`project_id`,`instance_id`,`credentials_id`\".", - "credentials_id": "The credentials ID.", - "instance_id": "ID of the MariaDB instance.", - "project_id": "STACKIT project ID to which the instance is associated.", + "main": "MariaDB credential data source schema.", + "id": "Terraform's internal data source. identifier. It is structured as \"`project_id`,`instance_id`,`credential_id`\".", + "credential_id": "The credential's ID.", + "instance_id": "ID of the MariaDB instance.", + "project_id": "STACKIT project ID to which the instance is associated.", } resp.Schema = schema.Schema{ @@ -89,8 +89,8 @@ func (r *credentialDataSource) Schema(_ context.Context, _ datasource.SchemaRequ Description: descriptions["id"], Computed: true, }, - "credentials_id": schema.StringAttribute{ - Description: descriptions["credentials_id"], + "credential_id": schema.StringAttribute{ + Description: descriptions["credential_id"], Required: true, Validators: []validator.String{ validate.UUID(), @@ -153,12 +153,12 @@ func (r *credentialDataSource) Read(ctx context.Context, req datasource.ReadRequ } projectId := model.ProjectId.ValueString() instanceId := model.InstanceId.ValueString() - credentialsId := model.CredentialsId.ValueString() + credentialId := model.CredentialId.ValueString() ctx = tflog.SetField(ctx, "project_id", projectId) ctx = tflog.SetField(ctx, "instance_id", instanceId) - ctx = tflog.SetField(ctx, "credentials_id", credentialsId) + ctx = tflog.SetField(ctx, "credential_id", credentialId) - recordSetResp, err := r.client.GetCredentials(ctx, projectId, instanceId, credentialsId).Execute() + recordSetResp, err := r.client.GetCredentials(ctx, projectId, instanceId, credentialId).Execute() if err != nil { core.LogAndAddError(ctx, &resp.Diagnostics, "Error reading credential", fmt.Sprintf("Calling API: %v", err)) return @@ -177,5 +177,5 @@ func (r *credentialDataSource) Read(ctx context.Context, req datasource.ReadRequ if resp.Diagnostics.HasError() { return } - tflog.Info(ctx, "mariadb credentials read") + tflog.Info(ctx, "mariadb credential read") } diff --git a/stackit/internal/services/mariadb/credential/resource.go b/stackit/internal/services/mariadb/credential/resource.go index 7ad7f02b..3d0b3f81 100644 --- a/stackit/internal/services/mariadb/credential/resource.go +++ b/stackit/internal/services/mariadb/credential/resource.go @@ -32,18 +32,18 @@ var ( ) type Model struct { - Id types.String `tfsdk:"id"` // needed by TF - CredentialsId types.String `tfsdk:"credentials_id"` - InstanceId types.String `tfsdk:"instance_id"` - ProjectId types.String `tfsdk:"project_id"` - Host types.String `tfsdk:"host"` - Hosts types.List `tfsdk:"hosts"` - HttpAPIURI types.String `tfsdk:"http_api_uri"` - Name types.String `tfsdk:"name"` - Password types.String `tfsdk:"password"` - Port types.Int64 `tfsdk:"port"` - Uri types.String `tfsdk:"uri"` - Username types.String `tfsdk:"username"` + Id types.String `tfsdk:"id"` // needed by TF + CredentialId types.String `tfsdk:"credential_id"` + InstanceId types.String `tfsdk:"instance_id"` + ProjectId types.String `tfsdk:"project_id"` + Host types.String `tfsdk:"host"` + Hosts types.List `tfsdk:"hosts"` + HttpAPIURI types.String `tfsdk:"http_api_uri"` + Name types.String `tfsdk:"name"` + Password types.String `tfsdk:"password"` + Port types.Int64 `tfsdk:"port"` + Uri types.String `tfsdk:"uri"` + Username types.String `tfsdk:"username"` } // NewCredentialResource is a helper function to simplify the provider implementation. @@ -94,17 +94,17 @@ func (r *credentialResource) Configure(ctx context.Context, req resource.Configu } r.client = apiClient - tflog.Info(ctx, "MariaDB credentials client configured") + tflog.Info(ctx, "MariaDB credential client configured") } // Schema defines the schema for the resource. func (r *credentialResource) Schema(_ context.Context, _ resource.SchemaRequest, resp *resource.SchemaResponse) { descriptions := map[string]string{ - "main": "MariaDB credential resource schema.", - "id": "Terraform's internal resource identifier. It is structured as \"`project_id`,`instance_id`,`credentials_id`\".", - "credentials_id": "The credentials ID.", - "instance_id": "ID of the MariaDB instance.", - "project_id": "STACKIT Project ID to which the instance is associated.", + "main": "MariaDB credential resource schema.", + "id": "Terraform's internal resource identifier. It is structured as \"`project_id`,`instance_id`,`credential_id`\".", + "credential_id": "The credential's ID.", + "instance_id": "ID of the MariaDB instance.", + "project_id": "STACKIT Project ID to which the instance is associated.", } resp.Schema = schema.Schema{ @@ -117,8 +117,8 @@ func (r *credentialResource) Schema(_ context.Context, _ resource.SchemaRequest, stringplanmodifier.UseStateForUnknown(), }, }, - "credentials_id": schema.StringAttribute{ - Description: descriptions["credentials_id"], + "credential_id": schema.StringAttribute{ + Description: descriptions["credential_id"], Computed: true, PlanModifiers: []planmodifier.String{ stringplanmodifier.UseStateForUnknown(), @@ -202,13 +202,13 @@ func (r *credentialResource) Create(ctx context.Context, req resource.CreateRequ return } if credentialsResp.Id == nil { - core.LogAndAddError(ctx, &resp.Diagnostics, "Error creating credential", "Got empty credentials id") + core.LogAndAddError(ctx, &resp.Diagnostics, "Error creating credential", "Got empty credential id") return } - credentialsId := *credentialsResp.Id - ctx = tflog.SetField(ctx, "credentials_id", credentialsId) + credentialId := *credentialsResp.Id + ctx = tflog.SetField(ctx, "credential_id", credentialId) - wr, err := wait.CreateCredentialsWaitHandler(ctx, r.client, projectId, instanceId, credentialsId).SetTimeout(1 * time.Minute).WaitWithContext(ctx) + wr, err := wait.CreateCredentialsWaitHandler(ctx, r.client, projectId, instanceId, credentialId).SetTimeout(1 * time.Minute).WaitWithContext(ctx) if err != nil { core.LogAndAddError(ctx, &resp.Diagnostics, "Error creating credential", fmt.Sprintf("Instance creation waiting: %v", err)) return @@ -230,7 +230,7 @@ func (r *credentialResource) Create(ctx context.Context, req resource.CreateRequ if resp.Diagnostics.HasError() { return } - tflog.Info(ctx, "MariaDB credentials created") + tflog.Info(ctx, "MariaDB credential created") } // Read refreshes the Terraform state with the latest data. @@ -243,12 +243,12 @@ func (r *credentialResource) Read(ctx context.Context, req resource.ReadRequest, } projectId := model.ProjectId.ValueString() instanceId := model.InstanceId.ValueString() - credentialsId := model.CredentialsId.ValueString() + credentialId := model.CredentialId.ValueString() ctx = tflog.SetField(ctx, "project_id", projectId) ctx = tflog.SetField(ctx, "instance_id", instanceId) - ctx = tflog.SetField(ctx, "credentials_id", credentialsId) + ctx = tflog.SetField(ctx, "credential_id", credentialId) - recordSetResp, err := r.client.GetCredentials(ctx, projectId, instanceId, credentialsId).Execute() + recordSetResp, err := r.client.GetCredentials(ctx, projectId, instanceId, credentialId).Execute() if err != nil { core.LogAndAddError(ctx, &resp.Diagnostics, "Error reading credential", fmt.Sprintf("Calling API: %v", err)) return @@ -267,7 +267,7 @@ func (r *credentialResource) Read(ctx context.Context, req resource.ReadRequest, if resp.Diagnostics.HasError() { return } - tflog.Info(ctx, "MariaDB credentials read") + tflog.Info(ctx, "MariaDB credential read") } // Update updates the resource and sets the updated Terraform state on success. @@ -287,40 +287,40 @@ func (r *credentialResource) Delete(ctx context.Context, req resource.DeleteRequ projectId := model.ProjectId.ValueString() instanceId := model.InstanceId.ValueString() - credentialsId := model.CredentialsId.ValueString() + credentialId := model.CredentialId.ValueString() ctx = tflog.SetField(ctx, "project_id", projectId) ctx = tflog.SetField(ctx, "instance_id", instanceId) - ctx = tflog.SetField(ctx, "credentials_id", credentialsId) + ctx = tflog.SetField(ctx, "credential_id", credentialId) // Delete existing record set - err := r.client.DeleteCredentials(ctx, projectId, instanceId, credentialsId).Execute() + err := r.client.DeleteCredentials(ctx, projectId, instanceId, credentialId).Execute() if err != nil { core.LogAndAddError(ctx, &resp.Diagnostics, "Error deleting credential", fmt.Sprintf("Calling API: %v", err)) } - _, err = wait.DeleteCredentialsWaitHandler(ctx, r.client, projectId, instanceId, credentialsId).SetTimeout(1 * time.Minute).WaitWithContext(ctx) + _, err = wait.DeleteCredentialsWaitHandler(ctx, r.client, projectId, instanceId, credentialId).SetTimeout(1 * time.Minute).WaitWithContext(ctx) if err != nil { core.LogAndAddError(ctx, &resp.Diagnostics, "Error deleting credential", fmt.Sprintf("Instance deletion waiting: %v", err)) return } - tflog.Info(ctx, "MariaDB credentials deleted") + tflog.Info(ctx, "MariaDB credential deleted") } // ImportState imports a resource into the Terraform state on success. -// The expected format of the resource import identifier is: project_id,instance_id,credentials_id +// The expected format of the resource import identifier is: project_id,instance_id,credential_id func (r *credentialResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { idParts := strings.Split(req.ID, core.Separator) if len(idParts) != 3 || idParts[0] == "" || idParts[1] == "" || idParts[2] == "" { core.LogAndAddError(ctx, &resp.Diagnostics, "Error importing credential", - fmt.Sprintf("Expected import identifier with format [project_id],[instance_id],[credentials_id], got %q", req.ID), + fmt.Sprintf("Expected import identifier with format [project_id],[instance_id],[credential_id], got %q", req.ID), ) return } resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("project_id"), idParts[0])...) resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("instance_id"), idParts[1])...) - resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("credentials_id"), idParts[2])...) - tflog.Info(ctx, "MariaDB credentials state imported") + resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("credential_id"), idParts[2])...) + tflog.Info(ctx, "MariaDB credential state imported") } func mapFields(credentialsResp *mariadb.CredentialsResponse, model *Model) error { @@ -335,11 +335,11 @@ func mapFields(credentialsResp *mariadb.CredentialsResponse, model *Model) error } credentials := credentialsResp.Raw.Credentials - var credentialsId string - if model.CredentialsId.ValueString() != "" { - credentialsId = model.CredentialsId.ValueString() + var credentialId string + if model.CredentialId.ValueString() != "" { + credentialId = model.CredentialId.ValueString() } else if credentialsResp.Id != nil { - credentialsId = *credentialsResp.Id + credentialId = *credentialsResp.Id } else { return fmt.Errorf("credentials id not present") } @@ -347,12 +347,12 @@ func mapFields(credentialsResp *mariadb.CredentialsResponse, model *Model) error idParts := []string{ model.ProjectId.ValueString(), model.InstanceId.ValueString(), - credentialsId, + credentialId, } model.Id = types.StringValue( strings.Join(idParts, core.Separator), ) - model.CredentialsId = types.StringValue(credentialsId) + model.CredentialId = types.StringValue(credentialId) model.Hosts = types.ListNull(types.StringType) if credentials != nil { if credentials.Hosts != nil { diff --git a/stackit/internal/services/mariadb/credential/resource_test.go b/stackit/internal/services/mariadb/credential/resource_test.go index ac05d210..0c789fc8 100644 --- a/stackit/internal/services/mariadb/credential/resource_test.go +++ b/stackit/internal/services/mariadb/credential/resource_test.go @@ -24,18 +24,18 @@ func TestMapFields(t *testing.T) { Raw: &mariadb.RawCredentials{}, }, Model{ - Id: types.StringValue("pid,iid,cid"), - CredentialsId: types.StringValue("cid"), - InstanceId: types.StringValue("iid"), - ProjectId: types.StringValue("pid"), - Host: types.StringNull(), - Hosts: types.ListNull(types.StringType), - HttpAPIURI: types.StringNull(), - Name: types.StringNull(), - Password: types.StringNull(), - Port: types.Int64Null(), - Uri: types.StringNull(), - Username: types.StringNull(), + Id: types.StringValue("pid,iid,cid"), + CredentialId: types.StringValue("cid"), + InstanceId: types.StringValue("iid"), + ProjectId: types.StringValue("pid"), + Host: types.StringNull(), + Hosts: types.ListNull(types.StringType), + HttpAPIURI: types.StringNull(), + Name: types.StringNull(), + Password: types.StringNull(), + Port: types.Int64Null(), + Uri: types.StringNull(), + Username: types.StringNull(), }, true, }, @@ -60,11 +60,11 @@ func TestMapFields(t *testing.T) { }, }, Model{ - Id: types.StringValue("pid,iid,cid"), - CredentialsId: types.StringValue("cid"), - InstanceId: types.StringValue("iid"), - ProjectId: types.StringValue("pid"), - Host: types.StringValue("host"), + Id: types.StringValue("pid,iid,cid"), + CredentialId: types.StringValue("cid"), + InstanceId: types.StringValue("iid"), + ProjectId: types.StringValue("pid"), + Host: types.StringValue("host"), Hosts: types.ListValueMust(types.StringType, []attr.Value{ types.StringValue("host_1"), types.StringValue(""), @@ -96,18 +96,18 @@ func TestMapFields(t *testing.T) { }, }, Model{ - Id: types.StringValue("pid,iid,cid"), - CredentialsId: types.StringValue("cid"), - InstanceId: types.StringValue("iid"), - ProjectId: types.StringValue("pid"), - Host: types.StringValue(""), - Hosts: types.ListValueMust(types.StringType, []attr.Value{}), - HttpAPIURI: types.StringNull(), - Name: types.StringNull(), - Password: types.StringValue(""), - Port: types.Int64Value(2123456789), - Uri: types.StringNull(), - Username: types.StringValue(""), + Id: types.StringValue("pid,iid,cid"), + CredentialId: types.StringValue("cid"), + InstanceId: types.StringValue("iid"), + ProjectId: types.StringValue("pid"), + Host: types.StringValue(""), + Hosts: types.ListValueMust(types.StringType, []attr.Value{}), + HttpAPIURI: types.StringNull(), + Name: types.StringNull(), + Password: types.StringValue(""), + Port: types.Int64Value(2123456789), + Uri: types.StringNull(), + Username: types.StringValue(""), }, true, }, diff --git a/stackit/internal/services/mariadb/mariadb_acc_test.go b/stackit/internal/services/mariadb/mariadb_acc_test.go index 9fff4ff7..d33b091a 100644 --- a/stackit/internal/services/mariadb/mariadb_acc_test.go +++ b/stackit/internal/services/mariadb/mariadb_acc_test.go @@ -41,7 +41,7 @@ func resourceConfig(acls string) string { } } - resource "stackit_mariadb_credential" "credentials" { + resource "stackit_mariadb_credential" "credential" { project_id = stackit_mariadb_instance.instance.project_id instance_id = stackit_mariadb_instance.instance.instance_id } @@ -73,17 +73,17 @@ func TestAccMariaDBResource(t *testing.T) { resource.TestCheckResourceAttr("stackit_mariadb_instance.instance", "name", instanceResource["name"]), resource.TestCheckResourceAttr("stackit_mariadb_instance.instance", "parameters.sgw_acl", instanceResource["sgw_acl-1"]), - // Credentials data + // Credential data resource.TestCheckResourceAttrPair( - "stackit_mariadb_credential.credentials", "project_id", + "stackit_mariadb_credential.credential", "project_id", "stackit_mariadb_instance.instance", "project_id", ), resource.TestCheckResourceAttrPair( - "stackit_mariadb_credential.credentials", "instance_id", + "stackit_mariadb_credential.credential", "instance_id", "stackit_mariadb_instance.instance", "instance_id", ), - resource.TestCheckResourceAttrSet("stackit_mariadb_credential.credentials", "credentials_id"), - resource.TestCheckResourceAttrSet("stackit_mariadb_credential.credentials", "host"), + resource.TestCheckResourceAttrSet("stackit_mariadb_credential.credential", "credential_id"), + resource.TestCheckResourceAttrSet("stackit_mariadb_credential.credential", "host"), ), }, // Data source @@ -96,10 +96,10 @@ func TestAccMariaDBResource(t *testing.T) { instance_id = stackit_mariadb_instance.instance.instance_id } - data "stackit_mariadb_credential" "credentials" { - project_id = stackit_mariadb_credential.credentials.project_id - instance_id = stackit_mariadb_credential.credentials.instance_id - credentials_id = stackit_mariadb_credential.credentials.credentials_id + data "stackit_mariadb_credential" "credential" { + project_id = stackit_mariadb_credential.credential.project_id + instance_id = stackit_mariadb_credential.credential.instance_id + credential_id = stackit_mariadb_credential.credential.credential_id }`, resourceConfig(instanceResource["sgw_acl-1"]), ), @@ -108,18 +108,18 @@ func TestAccMariaDBResource(t *testing.T) { resource.TestCheckResourceAttr("data.stackit_mariadb_instance.instance", "project_id", instanceResource["project_id"]), resource.TestCheckResourceAttrPair("stackit_mariadb_instance.instance", "instance_id", "data.stackit_mariadb_instance.instance", "instance_id"), - resource.TestCheckResourceAttrPair("stackit_mariadb_credential.credentials", "credentials_id", - "data.stackit_mariadb_credential.credentials", "credentials_id"), + resource.TestCheckResourceAttrPair("stackit_mariadb_credential.credential", "credential_id", + "data.stackit_mariadb_credential.credential", "credential_id"), resource.TestCheckResourceAttr("data.stackit_mariadb_instance.instance", "plan_id", instanceResource["plan_id"]), resource.TestCheckResourceAttr("data.stackit_mariadb_instance.instance", "name", instanceResource["name"]), resource.TestCheckResourceAttr("data.stackit_mariadb_instance.instance", "parameters.sgw_acl", instanceResource["sgw_acl-1"]), - // Credentials data - resource.TestCheckResourceAttr("data.stackit_mariadb_credential.credentials", "project_id", instanceResource["project_id"]), - resource.TestCheckResourceAttrSet("data.stackit_mariadb_credential.credentials", "credentials_id"), - resource.TestCheckResourceAttrSet("data.stackit_mariadb_credential.credentials", "host"), - resource.TestCheckResourceAttrSet("data.stackit_mariadb_credential.credentials", "port"), - resource.TestCheckResourceAttrSet("data.stackit_mariadb_credential.credentials", "uri"), + // Credential data + resource.TestCheckResourceAttr("data.stackit_mariadb_credential.credential", "project_id", instanceResource["project_id"]), + resource.TestCheckResourceAttrSet("data.stackit_mariadb_credential.credential", "credential_id"), + resource.TestCheckResourceAttrSet("data.stackit_mariadb_credential.credential", "host"), + resource.TestCheckResourceAttrSet("data.stackit_mariadb_credential.credential", "port"), + resource.TestCheckResourceAttrSet("data.stackit_mariadb_credential.credential", "uri"), ), }, // Import @@ -140,21 +140,21 @@ func TestAccMariaDBResource(t *testing.T) { ImportStateVerify: true, }, { - ResourceName: "stackit_mariadb_credential.credentials", + ResourceName: "stackit_mariadb_credential.credential", ImportStateIdFunc: func(s *terraform.State) (string, error) { - r, ok := s.RootModule().Resources["stackit_mariadb_credential.credentials"] + r, ok := s.RootModule().Resources["stackit_mariadb_credential.credential"] if !ok { - return "", fmt.Errorf("couldn't find resource stackit_mariadb_credential.credentials") + return "", fmt.Errorf("couldn't find resource stackit_mariadb_credential.credential") } instanceId, ok := r.Primary.Attributes["instance_id"] if !ok { return "", fmt.Errorf("couldn't find attribute instance_id") } - credentialsId, ok := r.Primary.Attributes["credentials_id"] + credentialId, ok := r.Primary.Attributes["credential_id"] if !ok { - return "", fmt.Errorf("couldn't find attribute credentials_id") + return "", fmt.Errorf("couldn't find attribute credential_id") } - return fmt.Sprintf("%s,%s,%s", testutil.ProjectId, instanceId, credentialsId), nil + return fmt.Sprintf("%s,%s,%s", testutil.ProjectId, instanceId, credentialId), nil }, ImportState: true, ImportStateVerify: true, diff --git a/stackit/internal/services/opensearch/credential/datasource.go b/stackit/internal/services/opensearch/credential/datasource.go index 89299828..cbdb1f3b 100644 --- a/stackit/internal/services/opensearch/credential/datasource.go +++ b/stackit/internal/services/opensearch/credential/datasource.go @@ -69,17 +69,17 @@ func (r *credentialDataSource) Configure(ctx context.Context, req datasource.Con } r.client = apiClient - tflog.Info(ctx, "OpenSearch credentials client configured") + tflog.Info(ctx, "OpenSearch credential client configured") } // Schema defines the schema for the data source. func (r *credentialDataSource) Schema(_ context.Context, _ datasource.SchemaRequest, resp *datasource.SchemaResponse) { descriptions := map[string]string{ - "main": "OpenSearch credential data source schema.", - "id": "Terraform's internal data source. identifier. It is structured as \"`project_id`,`instance_id`,`credentials_id`\".", - "credentials_id": "The credentials ID.", - "instance_id": "ID of the OpenSearch instance.", - "project_id": "STACKIT project ID to which the instance is associated.", + "main": "OpenSearch credential data source schema.", + "id": "Terraform's internal data source. identifier. It is structured as \"`project_id`,`instance_id`,`credential_id`\".", + "credential_id": "The credential's ID.", + "instance_id": "ID of the OpenSearch instance.", + "project_id": "STACKIT project ID to which the instance is associated.", } resp.Schema = schema.Schema{ @@ -89,8 +89,8 @@ func (r *credentialDataSource) Schema(_ context.Context, _ datasource.SchemaRequ Description: descriptions["id"], Computed: true, }, - "credentials_id": schema.StringAttribute{ - Description: descriptions["credentials_id"], + "credential_id": schema.StringAttribute{ + Description: descriptions["credential_id"], Required: true, Validators: []validator.String{ validate.UUID(), @@ -153,12 +153,12 @@ func (r *credentialDataSource) Read(ctx context.Context, req datasource.ReadRequ } projectId := model.ProjectId.ValueString() instanceId := model.InstanceId.ValueString() - credentialsId := model.CredentialsId.ValueString() + credentialId := model.CredentialId.ValueString() ctx = tflog.SetField(ctx, "project_id", projectId) ctx = tflog.SetField(ctx, "instance_id", instanceId) - ctx = tflog.SetField(ctx, "credentials_id", credentialsId) + ctx = tflog.SetField(ctx, "credential_id", credentialId) - recordSetResp, err := r.client.GetCredentials(ctx, projectId, instanceId, credentialsId).Execute() + recordSetResp, err := r.client.GetCredentials(ctx, projectId, instanceId, credentialId).Execute() if err != nil { core.LogAndAddError(ctx, &resp.Diagnostics, "Error reading credential", fmt.Sprintf("Calling API: %v", err)) return @@ -177,5 +177,5 @@ func (r *credentialDataSource) Read(ctx context.Context, req datasource.ReadRequ if resp.Diagnostics.HasError() { return } - tflog.Info(ctx, "OpenSearch credentials read") + tflog.Info(ctx, "OpenSearch credential read") } diff --git a/stackit/internal/services/opensearch/credential/resource.go b/stackit/internal/services/opensearch/credential/resource.go index d636111d..2b90537c 100644 --- a/stackit/internal/services/opensearch/credential/resource.go +++ b/stackit/internal/services/opensearch/credential/resource.go @@ -32,18 +32,18 @@ var ( ) type Model struct { - Id types.String `tfsdk:"id"` // needed by TF - CredentialsId types.String `tfsdk:"credentials_id"` - InstanceId types.String `tfsdk:"instance_id"` - ProjectId types.String `tfsdk:"project_id"` - Host types.String `tfsdk:"host"` - Hosts types.List `tfsdk:"hosts"` - HttpAPIURI types.String `tfsdk:"http_api_uri"` - Name types.String `tfsdk:"name"` - Password types.String `tfsdk:"password"` - Port types.Int64 `tfsdk:"port"` - Uri types.String `tfsdk:"uri"` - Username types.String `tfsdk:"username"` + Id types.String `tfsdk:"id"` // needed by TF + CredentialId types.String `tfsdk:"credential_id"` + InstanceId types.String `tfsdk:"instance_id"` + ProjectId types.String `tfsdk:"project_id"` + Host types.String `tfsdk:"host"` + Hosts types.List `tfsdk:"hosts"` + HttpAPIURI types.String `tfsdk:"http_api_uri"` + Name types.String `tfsdk:"name"` + Password types.String `tfsdk:"password"` + Port types.Int64 `tfsdk:"port"` + Uri types.String `tfsdk:"uri"` + Username types.String `tfsdk:"username"` } // NewCredentialResource is a helper function to simplify the provider implementation. @@ -94,17 +94,17 @@ func (r *credentialResource) Configure(ctx context.Context, req resource.Configu } r.client = apiClient - tflog.Info(ctx, "OpenSearch credentials client configured") + tflog.Info(ctx, "OpenSearch credential client configured") } // Schema defines the schema for the resource. func (r *credentialResource) Schema(_ context.Context, _ resource.SchemaRequest, resp *resource.SchemaResponse) { descriptions := map[string]string{ - "main": "OpenSearch credential resource schema.", - "id": "Terraform's internal resource identifier. It is structured as \"`project_id`,`instance_id`,`credentials_id`\".", - "credentials_id": "The credentials ID.", - "instance_id": "ID of the OpenSearch instance.", - "project_id": "STACKIT Project ID to which the instance is associated.", + "main": "OpenSearch credential resource schema.", + "id": "Terraform's internal resource identifier. It is structured as \"`project_id`,`instance_id`,`credential_id`\".", + "credential_id": "The credential's ID.", + "instance_id": "ID of the OpenSearch instance.", + "project_id": "STACKIT Project ID to which the instance is associated.", } resp.Schema = schema.Schema{ @@ -117,8 +117,8 @@ func (r *credentialResource) Schema(_ context.Context, _ resource.SchemaRequest, stringplanmodifier.UseStateForUnknown(), }, }, - "credentials_id": schema.StringAttribute{ - Description: descriptions["credentials_id"], + "credential_id": schema.StringAttribute{ + Description: descriptions["credential_id"], Computed: true, PlanModifiers: []planmodifier.String{ stringplanmodifier.UseStateForUnknown(), @@ -202,13 +202,13 @@ func (r *credentialResource) Create(ctx context.Context, req resource.CreateRequ return } if credentialsResp.Id == nil { - core.LogAndAddError(ctx, &resp.Diagnostics, "Error creating credential", "Got empty credentials id") + core.LogAndAddError(ctx, &resp.Diagnostics, "Error creating credential", "Got empty credential id") return } - credentialsId := *credentialsResp.Id - ctx = tflog.SetField(ctx, "credentials_id", credentialsId) + credentialId := *credentialsResp.Id + ctx = tflog.SetField(ctx, "credential_id", credentialId) - wr, err := wait.CreateCredentialsWaitHandler(ctx, r.client, projectId, instanceId, credentialsId).SetTimeout(1 * time.Minute).WaitWithContext(ctx) + wr, err := wait.CreateCredentialsWaitHandler(ctx, r.client, projectId, instanceId, credentialId).SetTimeout(1 * time.Minute).WaitWithContext(ctx) if err != nil { core.LogAndAddError(ctx, &resp.Diagnostics, "Error creating credential", fmt.Sprintf("Instance creation waiting: %v", err)) return @@ -230,7 +230,7 @@ func (r *credentialResource) Create(ctx context.Context, req resource.CreateRequ if resp.Diagnostics.HasError() { return } - tflog.Info(ctx, "OpenSearch credentials created") + tflog.Info(ctx, "OpenSearch credential created") } // Read refreshes the Terraform state with the latest data. @@ -243,12 +243,12 @@ func (r *credentialResource) Read(ctx context.Context, req resource.ReadRequest, } projectId := model.ProjectId.ValueString() instanceId := model.InstanceId.ValueString() - credentialsId := model.CredentialsId.ValueString() + credentialId := model.CredentialId.ValueString() ctx = tflog.SetField(ctx, "project_id", projectId) ctx = tflog.SetField(ctx, "instance_id", instanceId) - ctx = tflog.SetField(ctx, "credentials_id", credentialsId) + ctx = tflog.SetField(ctx, "credential_id", credentialId) - recordSetResp, err := r.client.GetCredentials(ctx, projectId, instanceId, credentialsId).Execute() + recordSetResp, err := r.client.GetCredentials(ctx, projectId, instanceId, credentialId).Execute() if err != nil { core.LogAndAddError(ctx, &resp.Diagnostics, "Error reading credential", fmt.Sprintf("Calling API: %v", err)) return @@ -267,7 +267,7 @@ func (r *credentialResource) Read(ctx context.Context, req resource.ReadRequest, if resp.Diagnostics.HasError() { return } - tflog.Info(ctx, "OpenSearch credentials read") + tflog.Info(ctx, "OpenSearch credential read") } // Update updates the resource and sets the updated Terraform state on success. @@ -287,40 +287,40 @@ func (r *credentialResource) Delete(ctx context.Context, req resource.DeleteRequ projectId := model.ProjectId.ValueString() instanceId := model.InstanceId.ValueString() - credentialsId := model.CredentialsId.ValueString() + credentialId := model.CredentialId.ValueString() ctx = tflog.SetField(ctx, "project_id", projectId) ctx = tflog.SetField(ctx, "instance_id", instanceId) - ctx = tflog.SetField(ctx, "credentials_id", credentialsId) + ctx = tflog.SetField(ctx, "credential_id", credentialId) // Delete existing record set - err := r.client.DeleteCredentials(ctx, projectId, instanceId, credentialsId).Execute() + err := r.client.DeleteCredentials(ctx, projectId, instanceId, credentialId).Execute() if err != nil { core.LogAndAddError(ctx, &resp.Diagnostics, "Error deleting credential", fmt.Sprintf("Calling API: %v", err)) } - _, err = wait.DeleteCredentialsWaitHandler(ctx, r.client, projectId, instanceId, credentialsId).SetTimeout(1 * time.Minute).WaitWithContext(ctx) + _, err = wait.DeleteCredentialsWaitHandler(ctx, r.client, projectId, instanceId, credentialId).SetTimeout(1 * time.Minute).WaitWithContext(ctx) if err != nil { core.LogAndAddError(ctx, &resp.Diagnostics, "Error deleting credential", fmt.Sprintf("Instance deletion waiting: %v", err)) return } - tflog.Info(ctx, "OpenSearch credentials deleted") + tflog.Info(ctx, "OpenSearch credential deleted") } // ImportState imports a resource into the Terraform state on success. -// The expected format of the resource import identifier is: project_id,instance_id,credentials_id +// The expected format of the resource import identifier is: project_id,instance_id,credential_id func (r *credentialResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { idParts := strings.Split(req.ID, core.Separator) if len(idParts) != 3 || idParts[0] == "" || idParts[1] == "" || idParts[2] == "" { core.LogAndAddError(ctx, &resp.Diagnostics, "Error importing credential", - fmt.Sprintf("Expected import identifier with format [project_id],[instance_id],[credentials_id], got %q", req.ID), + fmt.Sprintf("Expected import identifier with format [project_id],[instance_id],[credential_id], got %q", req.ID), ) return } resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("project_id"), idParts[0])...) resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("instance_id"), idParts[1])...) - resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("credentials_id"), idParts[2])...) - tflog.Info(ctx, "OpenSearch credentials state imported") + resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("credential_id"), idParts[2])...) + tflog.Info(ctx, "OpenSearch credential state imported") } func mapFields(credentialsResp *opensearch.CredentialsResponse, model *Model) error { @@ -335,11 +335,11 @@ func mapFields(credentialsResp *opensearch.CredentialsResponse, model *Model) er } credentials := credentialsResp.Raw.Credentials - var credentialsId string - if model.CredentialsId.ValueString() != "" { - credentialsId = model.CredentialsId.ValueString() + var credentialId string + if model.CredentialId.ValueString() != "" { + credentialId = model.CredentialId.ValueString() } else if credentialsResp.Id != nil { - credentialsId = *credentialsResp.Id + credentialId = *credentialsResp.Id } else { return fmt.Errorf("credentials id not present") } @@ -347,12 +347,12 @@ func mapFields(credentialsResp *opensearch.CredentialsResponse, model *Model) er idParts := []string{ model.ProjectId.ValueString(), model.InstanceId.ValueString(), - credentialsId, + credentialId, } model.Id = types.StringValue( strings.Join(idParts, core.Separator), ) - model.CredentialsId = types.StringValue(credentialsId) + model.CredentialId = types.StringValue(credentialId) model.Hosts = types.ListNull(types.StringType) if credentials != nil { if credentials.Hosts != nil { diff --git a/stackit/internal/services/opensearch/credential/resource_test.go b/stackit/internal/services/opensearch/credential/resource_test.go index 5b653d38..7e2641f5 100644 --- a/stackit/internal/services/opensearch/credential/resource_test.go +++ b/stackit/internal/services/opensearch/credential/resource_test.go @@ -24,18 +24,18 @@ func TestMapFields(t *testing.T) { Raw: &opensearch.RawCredentials{}, }, Model{ - Id: types.StringValue("pid,iid,cid"), - CredentialsId: types.StringValue("cid"), - InstanceId: types.StringValue("iid"), - ProjectId: types.StringValue("pid"), - Host: types.StringNull(), - Hosts: types.ListNull(types.StringType), - HttpAPIURI: types.StringNull(), - Name: types.StringNull(), - Password: types.StringNull(), - Port: types.Int64Null(), - Uri: types.StringNull(), - Username: types.StringNull(), + Id: types.StringValue("pid,iid,cid"), + CredentialId: types.StringValue("cid"), + InstanceId: types.StringValue("iid"), + ProjectId: types.StringValue("pid"), + Host: types.StringNull(), + Hosts: types.ListNull(types.StringType), + HttpAPIURI: types.StringNull(), + Name: types.StringNull(), + Password: types.StringNull(), + Port: types.Int64Null(), + Uri: types.StringNull(), + Username: types.StringNull(), }, true, }, @@ -60,11 +60,11 @@ func TestMapFields(t *testing.T) { }, }, Model{ - Id: types.StringValue("pid,iid,cid"), - CredentialsId: types.StringValue("cid"), - InstanceId: types.StringValue("iid"), - ProjectId: types.StringValue("pid"), - Host: types.StringValue("host"), + Id: types.StringValue("pid,iid,cid"), + CredentialId: types.StringValue("cid"), + InstanceId: types.StringValue("iid"), + ProjectId: types.StringValue("pid"), + Host: types.StringValue("host"), Hosts: types.ListValueMust(types.StringType, []attr.Value{ types.StringValue("host_1"), types.StringValue(""), @@ -96,18 +96,18 @@ func TestMapFields(t *testing.T) { }, }, Model{ - Id: types.StringValue("pid,iid,cid"), - CredentialsId: types.StringValue("cid"), - InstanceId: types.StringValue("iid"), - ProjectId: types.StringValue("pid"), - Host: types.StringValue(""), - Hosts: types.ListValueMust(types.StringType, []attr.Value{}), - HttpAPIURI: types.StringNull(), - Name: types.StringNull(), - Password: types.StringValue(""), - Port: types.Int64Value(2123456789), - Uri: types.StringNull(), - Username: types.StringValue(""), + Id: types.StringValue("pid,iid,cid"), + CredentialId: types.StringValue("cid"), + InstanceId: types.StringValue("iid"), + ProjectId: types.StringValue("pid"), + Host: types.StringValue(""), + Hosts: types.ListValueMust(types.StringType, []attr.Value{}), + HttpAPIURI: types.StringNull(), + Name: types.StringNull(), + Password: types.StringValue(""), + Port: types.Int64Value(2123456789), + Uri: types.StringNull(), + Username: types.StringValue(""), }, true, }, diff --git a/stackit/internal/services/opensearch/opensearch_acc_test.go b/stackit/internal/services/opensearch/opensearch_acc_test.go index e31751e5..13fdf909 100644 --- a/stackit/internal/services/opensearch/opensearch_acc_test.go +++ b/stackit/internal/services/opensearch/opensearch_acc_test.go @@ -37,7 +37,7 @@ func resourceConfig() string { version = "%s" } - resource "stackit_opensearch_credential" "credentials" { + resource "stackit_opensearch_credential" "credential" { project_id = stackit_opensearch_instance.instance.project_id instance_id = stackit_opensearch_instance.instance.instance_id } @@ -64,7 +64,7 @@ func resourceConfigUpdate() string { } } - resource "stackit_opensearch_credential" "credentials" { + resource "stackit_opensearch_credential" "credential" { project_id = stackit_opensearch_instance.instance.project_id instance_id = stackit_opensearch_instance.instance.instance_id } @@ -97,17 +97,17 @@ func TestAccOpenSearchResource(t *testing.T) { resource.TestCheckResourceAttr("stackit_opensearch_instance.instance", "name", instanceResource["name"]), resource.TestCheckResourceAttrSet("stackit_opensearch_instance.instance", "parameters.sgw_acl"), - // Credentials data + // Credential data resource.TestCheckResourceAttrPair( - "stackit_opensearch_credential.credentials", "project_id", + "stackit_opensearch_credential.credential", "project_id", "stackit_opensearch_instance.instance", "project_id", ), resource.TestCheckResourceAttrPair( - "stackit_opensearch_credential.credentials", "instance_id", + "stackit_opensearch_credential.credential", "instance_id", "stackit_opensearch_instance.instance", "instance_id", ), - resource.TestCheckResourceAttrSet("stackit_opensearch_credential.credentials", "credentials_id"), - resource.TestCheckResourceAttrSet("stackit_opensearch_credential.credentials", "host"), + resource.TestCheckResourceAttrSet("stackit_opensearch_credential.credential", "credential_id"), + resource.TestCheckResourceAttrSet("stackit_opensearch_credential.credential", "host"), ), }, // Data source @@ -120,10 +120,10 @@ func TestAccOpenSearchResource(t *testing.T) { instance_id = stackit_opensearch_instance.instance.instance_id } - data "stackit_opensearch_credential" "credentials" { - project_id = stackit_opensearch_credential.credentials.project_id - instance_id = stackit_opensearch_credential.credentials.instance_id - credentials_id = stackit_opensearch_credential.credentials.credentials_id + data "stackit_opensearch_credential" "credential" { + project_id = stackit_opensearch_credential.credential.project_id + instance_id = stackit_opensearch_credential.credential.instance_id + credential_id = stackit_opensearch_credential.credential.credential_id }`, resourceConfig(), ), @@ -132,18 +132,18 @@ func TestAccOpenSearchResource(t *testing.T) { resource.TestCheckResourceAttr("data.stackit_opensearch_instance.instance", "project_id", instanceResource["project_id"]), resource.TestCheckResourceAttrPair("stackit_opensearch_instance.instance", "instance_id", "data.stackit_opensearch_instance.instance", "instance_id"), - resource.TestCheckResourceAttrPair("stackit_opensearch_credential.credentials", "credentials_id", - "data.stackit_opensearch_credential.credentials", "credentials_id"), + resource.TestCheckResourceAttrPair("stackit_opensearch_credential.credential", "credential_id", + "data.stackit_opensearch_credential.credential", "credential_id"), resource.TestCheckResourceAttr("data.stackit_opensearch_instance.instance", "plan_id", instanceResource["plan_id"]), resource.TestCheckResourceAttr("data.stackit_opensearch_instance.instance", "name", instanceResource["name"]), resource.TestCheckResourceAttrSet("data.stackit_opensearch_instance.instance", "parameters.sgw_acl"), - // Credentials data - resource.TestCheckResourceAttr("data.stackit_opensearch_credential.credentials", "project_id", instanceResource["project_id"]), - resource.TestCheckResourceAttrSet("data.stackit_opensearch_credential.credentials", "credentials_id"), - resource.TestCheckResourceAttrSet("data.stackit_opensearch_credential.credentials", "host"), - resource.TestCheckResourceAttrSet("data.stackit_opensearch_credential.credentials", "port"), - resource.TestCheckResourceAttrSet("data.stackit_opensearch_credential.credentials", "uri"), + // Credential data + resource.TestCheckResourceAttr("data.stackit_opensearch_credential.credential", "project_id", instanceResource["project_id"]), + resource.TestCheckResourceAttrSet("data.stackit_opensearch_credential.credential", "credential_id"), + resource.TestCheckResourceAttrSet("data.stackit_opensearch_credential.credential", "host"), + resource.TestCheckResourceAttrSet("data.stackit_opensearch_credential.credential", "port"), + resource.TestCheckResourceAttrSet("data.stackit_opensearch_credential.credential", "uri"), ), }, // Import @@ -165,21 +165,21 @@ func TestAccOpenSearchResource(t *testing.T) { ImportStateVerify: true, }, { - ResourceName: "stackit_opensearch_credential.credentials", + ResourceName: "stackit_opensearch_credential.credential", ImportStateIdFunc: func(s *terraform.State) (string, error) { - r, ok := s.RootModule().Resources["stackit_opensearch_credential.credentials"] + r, ok := s.RootModule().Resources["stackit_opensearch_credential.credential"] if !ok { - return "", fmt.Errorf("couldn't find resource stackit_opensearch_credential.credentials") + return "", fmt.Errorf("couldn't find resource stackit_opensearch_credential.credential") } instanceId, ok := r.Primary.Attributes["instance_id"] if !ok { return "", fmt.Errorf("couldn't find attribute instance_id") } - credentialsId, ok := r.Primary.Attributes["credentials_id"] + credentialId, ok := r.Primary.Attributes["credential_id"] if !ok { - return "", fmt.Errorf("couldn't find attribute credentials_id") + return "", fmt.Errorf("couldn't find attribute credential_id") } - return fmt.Sprintf("%s,%s,%s", testutil.ProjectId, instanceId, credentialsId), nil + return fmt.Sprintf("%s,%s,%s", testutil.ProjectId, instanceId, credentialId), nil }, ImportState: true, ImportStateVerify: true, diff --git a/stackit/internal/services/postgresql/credential/datasource.go b/stackit/internal/services/postgresql/credential/datasource.go index 2bc0f3ee..dd67bd6a 100644 --- a/stackit/internal/services/postgresql/credential/datasource.go +++ b/stackit/internal/services/postgresql/credential/datasource.go @@ -69,17 +69,17 @@ func (r *credentialDataSource) Configure(ctx context.Context, req datasource.Con } r.client = apiClient - tflog.Info(ctx, "PostgreSQL credentials client configured") + tflog.Info(ctx, "PostgreSQL credential client configured") } // Schema defines the schema for the data source. func (r *credentialDataSource) Schema(_ context.Context, _ datasource.SchemaRequest, resp *datasource.SchemaResponse) { descriptions := map[string]string{ - "main": "PostgreSQL credential data source schema.", - "id": "Terraform's internal data source. identifier. It is structured as \"`project_id`,`instance_id`,`credentials_id`\".", - "credentials_id": "The credentials ID.", - "instance_id": "ID of the PostgreSQL instance.", - "project_id": "STACKIT project ID to which the instance is associated.", + "main": "PostgreSQL credential data source schema.", + "id": "Terraform's internal data source. identifier. It is structured as \"`project_id`,`instance_id`,`credential_id`\".", + "credential_id": "The credential's ID.", + "instance_id": "ID of the PostgreSQL instance.", + "project_id": "STACKIT project ID to which the instance is associated.", } resp.Schema = schema.Schema{ @@ -89,8 +89,8 @@ func (r *credentialDataSource) Schema(_ context.Context, _ datasource.SchemaRequ Description: descriptions["id"], Computed: true, }, - "credentials_id": schema.StringAttribute{ - Description: descriptions["credentials_id"], + "credential_id": schema.StringAttribute{ + Description: descriptions["credential_id"], Required: true, Validators: []validator.String{ validate.UUID(), @@ -153,12 +153,12 @@ func (r *credentialDataSource) Read(ctx context.Context, req datasource.ReadRequ } projectId := model.ProjectId.ValueString() instanceId := model.InstanceId.ValueString() - credentialsId := model.CredentialsId.ValueString() + credentialId := model.CredentialId.ValueString() ctx = tflog.SetField(ctx, "project_id", projectId) ctx = tflog.SetField(ctx, "instance_id", instanceId) - ctx = tflog.SetField(ctx, "credentials_id", credentialsId) + ctx = tflog.SetField(ctx, "credential_id", credentialId) - recordSetResp, err := r.client.GetCredentials(ctx, projectId, instanceId, credentialsId).Execute() + recordSetResp, err := r.client.GetCredentials(ctx, projectId, instanceId, credentialId).Execute() if err != nil { core.LogAndAddError(ctx, &resp.Diagnostics, "Error reading credential", fmt.Sprintf("Calling API: %v", err)) return @@ -177,5 +177,5 @@ func (r *credentialDataSource) Read(ctx context.Context, req datasource.ReadRequ if resp.Diagnostics.HasError() { return } - tflog.Info(ctx, "PostgreSQL credentials read") + tflog.Info(ctx, "PostgreSQL credential read") } diff --git a/stackit/internal/services/postgresql/credential/resource.go b/stackit/internal/services/postgresql/credential/resource.go index bceb7e97..0ee8f707 100644 --- a/stackit/internal/services/postgresql/credential/resource.go +++ b/stackit/internal/services/postgresql/credential/resource.go @@ -32,18 +32,18 @@ var ( ) type Model struct { - Id types.String `tfsdk:"id"` // needed by TF - CredentialsId types.String `tfsdk:"credentials_id"` - InstanceId types.String `tfsdk:"instance_id"` - ProjectId types.String `tfsdk:"project_id"` - Host types.String `tfsdk:"host"` - Hosts types.List `tfsdk:"hosts"` - HttpAPIURI types.String `tfsdk:"http_api_uri"` - Name types.String `tfsdk:"name"` - Password types.String `tfsdk:"password"` - Port types.Int64 `tfsdk:"port"` - Uri types.String `tfsdk:"uri"` - Username types.String `tfsdk:"username"` + Id types.String `tfsdk:"id"` // needed by TF + CredentialId types.String `tfsdk:"credential_id"` + InstanceId types.String `tfsdk:"instance_id"` + ProjectId types.String `tfsdk:"project_id"` + Host types.String `tfsdk:"host"` + Hosts types.List `tfsdk:"hosts"` + HttpAPIURI types.String `tfsdk:"http_api_uri"` + Name types.String `tfsdk:"name"` + Password types.String `tfsdk:"password"` + Port types.Int64 `tfsdk:"port"` + Uri types.String `tfsdk:"uri"` + Username types.String `tfsdk:"username"` } // NewCredentialResource is a helper function to simplify the provider implementation. @@ -94,17 +94,17 @@ func (r *credentialResource) Configure(ctx context.Context, req resource.Configu } r.client = apiClient - tflog.Info(ctx, "PostgreSQL credentials client configured") + tflog.Info(ctx, "PostgreSQL credential client configured") } // Schema defines the schema for the resource. func (r *credentialResource) Schema(_ context.Context, _ resource.SchemaRequest, resp *resource.SchemaResponse) { descriptions := map[string]string{ - "main": "PostgreSQL credential resource schema.", - "id": "Terraform's internal resource identifier. It is structured as \"`project_id`,`instance_id`,`credentials_id`\".", - "credentials_id": "The credentials ID.", - "instance_id": "ID of the PostgreSQL instance.", - "project_id": "STACKIT Project ID to which the instance is associated.", + "main": "PostgreSQL credential resource schema.", + "id": "Terraform's internal resource identifier. It is structured as \"`project_id`,`instance_id`,`credential_id`\".", + "credential_id": "The credential's ID.", + "instance_id": "ID of the PostgreSQL instance.", + "project_id": "STACKIT Project ID to which the instance is associated.", } resp.Schema = schema.Schema{ @@ -117,8 +117,8 @@ func (r *credentialResource) Schema(_ context.Context, _ resource.SchemaRequest, stringplanmodifier.UseStateForUnknown(), }, }, - "credentials_id": schema.StringAttribute{ - Description: descriptions["credentials_id"], + "credential_id": schema.StringAttribute{ + Description: descriptions["credential_id"], Computed: true, PlanModifiers: []planmodifier.String{ stringplanmodifier.UseStateForUnknown(), @@ -202,13 +202,13 @@ func (r *credentialResource) Create(ctx context.Context, req resource.CreateRequ return } if credentialsResp.Id == nil { - core.LogAndAddError(ctx, &resp.Diagnostics, "Error creating credential", "Got empty credentials id") + core.LogAndAddError(ctx, &resp.Diagnostics, "Error creating credential", "Got empty credential id") return } - credentialsId := *credentialsResp.Id - ctx = tflog.SetField(ctx, "credentials_id", credentialsId) + credentialId := *credentialsResp.Id + ctx = tflog.SetField(ctx, "credential_id", credentialId) - wr, err := wait.CreateCredentialsWaitHandler(ctx, r.client, projectId, instanceId, credentialsId).SetTimeout(1 * time.Minute).WaitWithContext(ctx) + wr, err := wait.CreateCredentialsWaitHandler(ctx, r.client, projectId, instanceId, credentialId).SetTimeout(1 * time.Minute).WaitWithContext(ctx) if err != nil { core.LogAndAddError(ctx, &resp.Diagnostics, "Error creating credential", fmt.Sprintf("Instance creation waiting: %v", err)) return @@ -230,7 +230,7 @@ func (r *credentialResource) Create(ctx context.Context, req resource.CreateRequ if resp.Diagnostics.HasError() { return } - tflog.Info(ctx, "PostgreSQL credentials created") + tflog.Info(ctx, "PostgreSQL credential created") } // Read refreshes the Terraform state with the latest data. @@ -243,12 +243,12 @@ func (r *credentialResource) Read(ctx context.Context, req resource.ReadRequest, } projectId := model.ProjectId.ValueString() instanceId := model.InstanceId.ValueString() - credentialsId := model.CredentialsId.ValueString() + credentialId := model.CredentialId.ValueString() ctx = tflog.SetField(ctx, "project_id", projectId) ctx = tflog.SetField(ctx, "instance_id", instanceId) - ctx = tflog.SetField(ctx, "credentials_id", credentialsId) + ctx = tflog.SetField(ctx, "credential_id", credentialId) - recordSetResp, err := r.client.GetCredentials(ctx, projectId, instanceId, credentialsId).Execute() + recordSetResp, err := r.client.GetCredentials(ctx, projectId, instanceId, credentialId).Execute() if err != nil { core.LogAndAddError(ctx, &resp.Diagnostics, "Error reading credential", fmt.Sprintf("Calling API: %v", err)) return @@ -267,7 +267,7 @@ func (r *credentialResource) Read(ctx context.Context, req resource.ReadRequest, if resp.Diagnostics.HasError() { return } - tflog.Info(ctx, "PostgreSQL credentials read") + tflog.Info(ctx, "PostgreSQL credential read") } // Update updates the resource and sets the updated Terraform state on success. @@ -287,40 +287,40 @@ func (r *credentialResource) Delete(ctx context.Context, req resource.DeleteRequ projectId := model.ProjectId.ValueString() instanceId := model.InstanceId.ValueString() - credentialsId := model.CredentialsId.ValueString() + credentialId := model.CredentialId.ValueString() ctx = tflog.SetField(ctx, "project_id", projectId) ctx = tflog.SetField(ctx, "instance_id", instanceId) - ctx = tflog.SetField(ctx, "credentials_id", credentialsId) + ctx = tflog.SetField(ctx, "credential_id", credentialId) // Delete existing record set - err := r.client.DeleteCredentials(ctx, projectId, instanceId, credentialsId).Execute() + err := r.client.DeleteCredentials(ctx, projectId, instanceId, credentialId).Execute() if err != nil { core.LogAndAddError(ctx, &resp.Diagnostics, "Error deleting credential", fmt.Sprintf("Calling API: %v", err)) } - _, err = wait.DeleteCredentialsWaitHandler(ctx, r.client, projectId, instanceId, credentialsId).SetTimeout(1 * time.Minute).WaitWithContext(ctx) + _, err = wait.DeleteCredentialsWaitHandler(ctx, r.client, projectId, instanceId, credentialId).SetTimeout(1 * time.Minute).WaitWithContext(ctx) if err != nil { core.LogAndAddError(ctx, &resp.Diagnostics, "Error deleting credential", fmt.Sprintf("Instance deletion waiting: %v", err)) return } - tflog.Info(ctx, "PostgreSQL credentials deleted") + tflog.Info(ctx, "PostgreSQL credential deleted") } // ImportState imports a resource into the Terraform state on success. -// The expected format of the resource import identifier is: project_id,instance_id,credentials_id +// The expected format of the resource import identifier is: project_id,instance_id,credential_id func (r *credentialResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { idParts := strings.Split(req.ID, core.Separator) if len(idParts) != 3 || idParts[0] == "" || idParts[1] == "" || idParts[2] == "" { core.LogAndAddError(ctx, &resp.Diagnostics, "Error importing credential", - fmt.Sprintf("Expected import identifier with format [project_id],[instance_id],[credentials_id], got %q", req.ID), + fmt.Sprintf("Expected import identifier with format [project_id],[instance_id],[credential_id], got %q", req.ID), ) return } resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("project_id"), idParts[0])...) resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("instance_id"), idParts[1])...) - resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("credentials_id"), idParts[2])...) - tflog.Info(ctx, "PostgreSQL credentials state imported") + resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("credential_id"), idParts[2])...) + tflog.Info(ctx, "PostgreSQL credential state imported") } func mapFields(credentialsResp *postgresql.CredentialsResponse, model *Model) error { @@ -335,11 +335,11 @@ func mapFields(credentialsResp *postgresql.CredentialsResponse, model *Model) er } credentials := credentialsResp.Raw.Credentials - var credentialsId string - if model.CredentialsId.ValueString() != "" { - credentialsId = model.CredentialsId.ValueString() + var credentialId string + if model.CredentialId.ValueString() != "" { + credentialId = model.CredentialId.ValueString() } else if credentialsResp.Id != nil { - credentialsId = *credentialsResp.Id + credentialId = *credentialsResp.Id } else { return fmt.Errorf("credentials id not present") } @@ -347,12 +347,12 @@ func mapFields(credentialsResp *postgresql.CredentialsResponse, model *Model) er idParts := []string{ model.ProjectId.ValueString(), model.InstanceId.ValueString(), - credentialsId, + credentialId, } model.Id = types.StringValue( strings.Join(idParts, core.Separator), ) - model.CredentialsId = types.StringValue(credentialsId) + model.CredentialId = types.StringValue(credentialId) model.Hosts = types.ListNull(types.StringType) if credentials != nil { if credentials.Hosts != nil { diff --git a/stackit/internal/services/postgresql/credential/resource_test.go b/stackit/internal/services/postgresql/credential/resource_test.go index 075f426f..dc80bea2 100644 --- a/stackit/internal/services/postgresql/credential/resource_test.go +++ b/stackit/internal/services/postgresql/credential/resource_test.go @@ -24,18 +24,18 @@ func TestMapFields(t *testing.T) { Raw: &postgresql.RawCredentials{}, }, Model{ - Id: types.StringValue("pid,iid,cid"), - CredentialsId: types.StringValue("cid"), - InstanceId: types.StringValue("iid"), - ProjectId: types.StringValue("pid"), - Host: types.StringNull(), - Hosts: types.ListNull(types.StringType), - HttpAPIURI: types.StringNull(), - Name: types.StringNull(), - Password: types.StringNull(), - Port: types.Int64Null(), - Uri: types.StringNull(), - Username: types.StringNull(), + Id: types.StringValue("pid,iid,cid"), + CredentialId: types.StringValue("cid"), + InstanceId: types.StringValue("iid"), + ProjectId: types.StringValue("pid"), + Host: types.StringNull(), + Hosts: types.ListNull(types.StringType), + HttpAPIURI: types.StringNull(), + Name: types.StringNull(), + Password: types.StringNull(), + Port: types.Int64Null(), + Uri: types.StringNull(), + Username: types.StringNull(), }, true, }, @@ -60,11 +60,11 @@ func TestMapFields(t *testing.T) { }, }, Model{ - Id: types.StringValue("pid,iid,cid"), - CredentialsId: types.StringValue("cid"), - InstanceId: types.StringValue("iid"), - ProjectId: types.StringValue("pid"), - Host: types.StringValue("host"), + Id: types.StringValue("pid,iid,cid"), + CredentialId: types.StringValue("cid"), + InstanceId: types.StringValue("iid"), + ProjectId: types.StringValue("pid"), + Host: types.StringValue("host"), Hosts: types.ListValueMust(types.StringType, []attr.Value{ types.StringValue("host_1"), types.StringValue(""), @@ -96,18 +96,18 @@ func TestMapFields(t *testing.T) { }, }, Model{ - Id: types.StringValue("pid,iid,cid"), - CredentialsId: types.StringValue("cid"), - InstanceId: types.StringValue("iid"), - ProjectId: types.StringValue("pid"), - Host: types.StringValue(""), - Hosts: types.ListValueMust(types.StringType, []attr.Value{}), - HttpAPIURI: types.StringNull(), - Name: types.StringNull(), - Password: types.StringNull(), - Port: types.Int64Value(2123456789), - Uri: types.StringNull(), - Username: types.StringNull(), + Id: types.StringValue("pid,iid,cid"), + CredentialId: types.StringValue("cid"), + InstanceId: types.StringValue("iid"), + ProjectId: types.StringValue("pid"), + Host: types.StringValue(""), + Hosts: types.ListValueMust(types.StringType, []attr.Value{}), + HttpAPIURI: types.StringNull(), + Name: types.StringNull(), + Password: types.StringNull(), + Port: types.Int64Value(2123456789), + Uri: types.StringNull(), + Username: types.StringNull(), }, true, }, diff --git a/stackit/internal/services/postgresql/postgresql_acc_test.go b/stackit/internal/services/postgresql/postgresql_acc_test.go index f250a8cb..10aa2623 100644 --- a/stackit/internal/services/postgresql/postgresql_acc_test.go +++ b/stackit/internal/services/postgresql/postgresql_acc_test.go @@ -47,7 +47,7 @@ func resourceConfig(acls, frequency, plugins string) string { } } - resource "stackit_postgresql_credential" "credentials" { + resource "stackit_postgresql_credential" "credential" { project_id = stackit_postgresql_instance.instance.project_id instance_id = stackit_postgresql_instance.instance.instance_id } @@ -81,17 +81,17 @@ func TestAccPostgreSQLResource(t *testing.T) { resource.TestCheckResourceAttr("stackit_postgresql_instance.instance", "name", instanceResource["name"]), resource.TestCheckResourceAttr("stackit_postgresql_instance.instance", "parameters.sgw_acl", instanceResource["sgw_acl"]), - // Credentials data + // Credential data resource.TestCheckResourceAttrPair( - "stackit_postgresql_credential.credentials", "project_id", + "stackit_postgresql_credential.credential", "project_id", "stackit_postgresql_instance.instance", "project_id", ), resource.TestCheckResourceAttrPair( - "stackit_postgresql_credential.credentials", "instance_id", + "stackit_postgresql_credential.credential", "instance_id", "stackit_postgresql_instance.instance", "instance_id", ), - resource.TestCheckResourceAttrSet("stackit_postgresql_credential.credentials", "credentials_id"), - resource.TestCheckResourceAttrSet("stackit_postgresql_credential.credentials", "host"), + resource.TestCheckResourceAttrSet("stackit_postgresql_credential.credential", "credential_id"), + resource.TestCheckResourceAttrSet("stackit_postgresql_credential.credential", "host"), ), }, { // Data source @@ -103,10 +103,10 @@ func TestAccPostgreSQLResource(t *testing.T) { instance_id = stackit_postgresql_instance.instance.instance_id } - data "stackit_postgresql_credential" "credentials" { - project_id = stackit_postgresql_credential.credentials.project_id - instance_id = stackit_postgresql_credential.credentials.instance_id - credentials_id = stackit_postgresql_credential.credentials.credentials_id + data "stackit_postgresql_credential" "credential" { + project_id = stackit_postgresql_credential.credential.project_id + instance_id = stackit_postgresql_credential.credential.instance_id + credential_id = stackit_postgresql_credential.credential.credential_id }`, resourceConfig(instanceResource["sgw_acl"], instanceResource["metrics_frequency"], instanceResource["plugins"]), ), @@ -115,20 +115,20 @@ func TestAccPostgreSQLResource(t *testing.T) { resource.TestCheckResourceAttr("data.stackit_postgresql_instance.instance", "project_id", instanceResource["project_id"]), resource.TestCheckResourceAttrPair("stackit_postgresql_instance.instance", "instance_id", "data.stackit_postgresql_instance.instance", "instance_id"), - resource.TestCheckResourceAttrPair("stackit_postgresql_credential.credentials", "credentials_id", - "data.stackit_postgresql_credential.credentials", "credentials_id"), + resource.TestCheckResourceAttrPair("stackit_postgresql_credential.credential", "credential_id", + "data.stackit_postgresql_credential.credential", "credential_id"), resource.TestCheckResourceAttr("data.stackit_postgresql_instance.instance", "plan_id", instanceResource["plan_id"]), resource.TestCheckResourceAttr("data.stackit_postgresql_instance.instance", "name", instanceResource["name"]), resource.TestCheckResourceAttr("data.stackit_postgresql_instance.instance", "parameters.sgw_acl", instanceResource["sgw_acl"]), resource.TestCheckResourceAttr("data.stackit_postgresql_instance.instance", "parameters.plugins.#", "1"), resource.TestCheckResourceAttr("data.stackit_postgresql_instance.instance", "parameters.plugins.0", instanceResource["plugins"]), - // Credentials data - resource.TestCheckResourceAttr("data.stackit_postgresql_credential.credentials", "project_id", instanceResource["project_id"]), - resource.TestCheckResourceAttrSet("data.stackit_postgresql_credential.credentials", "credentials_id"), - resource.TestCheckResourceAttrSet("data.stackit_postgresql_credential.credentials", "host"), - resource.TestCheckResourceAttrSet("data.stackit_postgresql_credential.credentials", "port"), - resource.TestCheckResourceAttrSet("data.stackit_postgresql_credential.credentials", "uri"), + // Credential data + resource.TestCheckResourceAttr("data.stackit_postgresql_credential.credential", "project_id", instanceResource["project_id"]), + resource.TestCheckResourceAttrSet("data.stackit_postgresql_credential.credential", "credential_id"), + resource.TestCheckResourceAttrSet("data.stackit_postgresql_credential.credential", "host"), + resource.TestCheckResourceAttrSet("data.stackit_postgresql_credential.credential", "port"), + resource.TestCheckResourceAttrSet("data.stackit_postgresql_credential.credential", "uri"), ), }, // Import @@ -149,21 +149,21 @@ func TestAccPostgreSQLResource(t *testing.T) { ImportStateVerify: true, }, { - ResourceName: "stackit_postgresql_credential.credentials", + ResourceName: "stackit_postgresql_credential.credential", ImportStateIdFunc: func(s *terraform.State) (string, error) { - r, ok := s.RootModule().Resources["stackit_postgresql_credential.credentials"] + r, ok := s.RootModule().Resources["stackit_postgresql_credential.credential"] if !ok { - return "", fmt.Errorf("couldn't find resource stackit_postgresql_credential.credentials") + return "", fmt.Errorf("couldn't find resource stackit_postgresql_credential.credential") } instanceId, ok := r.Primary.Attributes["instance_id"] if !ok { return "", fmt.Errorf("couldn't find attribute instance_id") } - credentialsId, ok := r.Primary.Attributes["credentials_id"] + credentialId, ok := r.Primary.Attributes["credential_id"] if !ok { - return "", fmt.Errorf("couldn't find attribute credentials_id") + return "", fmt.Errorf("couldn't find attribute credential_id") } - return fmt.Sprintf("%s,%s,%s", testutil.ProjectId, instanceId, credentialsId), nil + return fmt.Sprintf("%s,%s,%s", testutil.ProjectId, instanceId, credentialId), nil }, ImportState: true, ImportStateVerify: true, diff --git a/stackit/internal/services/rabbitmq/credential/datasource.go b/stackit/internal/services/rabbitmq/credential/datasource.go index 2d0c458e..1c6588b6 100644 --- a/stackit/internal/services/rabbitmq/credential/datasource.go +++ b/stackit/internal/services/rabbitmq/credential/datasource.go @@ -69,17 +69,17 @@ func (r *credentialDataSource) Configure(ctx context.Context, req datasource.Con } r.client = apiClient - tflog.Info(ctx, "RabbitMQ credentials client configured") + tflog.Info(ctx, "RabbitMQ credential client configured") } // Schema defines the schema for the data source. func (r *credentialDataSource) Schema(_ context.Context, _ datasource.SchemaRequest, resp *datasource.SchemaResponse) { descriptions := map[string]string{ - "main": "RabbitMQ credential data source schema.", - "id": "Terraform's internal data source. identifier. It is structured as \"`project_id`,`instance_id`,`credentials_id`\".", - "credentials_id": "The credentials ID.", - "instance_id": "ID of the RabbitMQ instance.", - "project_id": "STACKIT project ID to which the instance is associated.", + "main": "RabbitMQ credential data source schema.", + "id": "Terraform's internal data source. identifier. It is structured as \"`project_id`,`instance_id`,`credential_id`\".", + "credential_id": "The credential's ID.", + "instance_id": "ID of the RabbitMQ instance.", + "project_id": "STACKIT project ID to which the instance is associated.", } resp.Schema = schema.Schema{ @@ -89,8 +89,8 @@ func (r *credentialDataSource) Schema(_ context.Context, _ datasource.SchemaRequ Description: descriptions["id"], Computed: true, }, - "credentials_id": schema.StringAttribute{ - Description: descriptions["credentials_id"], + "credential_id": schema.StringAttribute{ + Description: descriptions["credential_id"], Required: true, Validators: []validator.String{ validate.UUID(), @@ -153,12 +153,12 @@ func (r *credentialDataSource) Read(ctx context.Context, req datasource.ReadRequ } projectId := model.ProjectId.ValueString() instanceId := model.InstanceId.ValueString() - credentialsId := model.CredentialsId.ValueString() + credentialId := model.CredentialId.ValueString() ctx = tflog.SetField(ctx, "project_id", projectId) ctx = tflog.SetField(ctx, "instance_id", instanceId) - ctx = tflog.SetField(ctx, "credentials_id", credentialsId) + ctx = tflog.SetField(ctx, "credential_id", credentialId) - recordSetResp, err := r.client.GetCredentials(ctx, projectId, instanceId, credentialsId).Execute() + recordSetResp, err := r.client.GetCredentials(ctx, projectId, instanceId, credentialId).Execute() if err != nil { core.LogAndAddError(ctx, &resp.Diagnostics, "Error reading credential", fmt.Sprintf("Calling API: %v", err)) return @@ -177,5 +177,5 @@ func (r *credentialDataSource) Read(ctx context.Context, req datasource.ReadRequ if resp.Diagnostics.HasError() { return } - tflog.Info(ctx, "RabbitMQ credentials read") + tflog.Info(ctx, "RabbitMQ credential read") } diff --git a/stackit/internal/services/rabbitmq/credential/resource.go b/stackit/internal/services/rabbitmq/credential/resource.go index 372fc893..766cf5d7 100644 --- a/stackit/internal/services/rabbitmq/credential/resource.go +++ b/stackit/internal/services/rabbitmq/credential/resource.go @@ -32,18 +32,18 @@ var ( ) type Model struct { - Id types.String `tfsdk:"id"` // needed by TF - CredentialsId types.String `tfsdk:"credentials_id"` - InstanceId types.String `tfsdk:"instance_id"` - ProjectId types.String `tfsdk:"project_id"` - Host types.String `tfsdk:"host"` - Hosts types.List `tfsdk:"hosts"` - HttpAPIURI types.String `tfsdk:"http_api_uri"` - Name types.String `tfsdk:"name"` - Password types.String `tfsdk:"password"` - Port types.Int64 `tfsdk:"port"` - Uri types.String `tfsdk:"uri"` - Username types.String `tfsdk:"username"` + Id types.String `tfsdk:"id"` // needed by TF + CredentialId types.String `tfsdk:"credential_id"` + InstanceId types.String `tfsdk:"instance_id"` + ProjectId types.String `tfsdk:"project_id"` + Host types.String `tfsdk:"host"` + Hosts types.List `tfsdk:"hosts"` + HttpAPIURI types.String `tfsdk:"http_api_uri"` + Name types.String `tfsdk:"name"` + Password types.String `tfsdk:"password"` + Port types.Int64 `tfsdk:"port"` + Uri types.String `tfsdk:"uri"` + Username types.String `tfsdk:"username"` } // NewCredentialResource is a helper function to simplify the provider implementation. @@ -94,17 +94,17 @@ func (r *credentialResource) Configure(ctx context.Context, req resource.Configu } r.client = apiClient - tflog.Info(ctx, "RabbitMQ credentials client configured") + tflog.Info(ctx, "RabbitMQ credential client configured") } // Schema defines the schema for the resource. func (r *credentialResource) Schema(_ context.Context, _ resource.SchemaRequest, resp *resource.SchemaResponse) { descriptions := map[string]string{ - "main": "RabbitMQ credential resource schema.", - "id": "Terraform's internal resource identifier. It is structured as \"`project_id`,`instance_id`,`credentials_id`\".", - "credentials_id": "The credentials ID.", - "instance_id": "ID of the RabbitMQ instance.", - "project_id": "STACKIT Project ID to which the instance is associated.", + "main": "RabbitMQ credential resource schema.", + "id": "Terraform's internal resource identifier. It is structured as \"`project_id`,`instance_id`,`credential_id`\".", + "credential_id": "The credential's ID.", + "instance_id": "ID of the RabbitMQ instance.", + "project_id": "STACKIT Project ID to which the instance is associated.", } resp.Schema = schema.Schema{ @@ -117,8 +117,8 @@ func (r *credentialResource) Schema(_ context.Context, _ resource.SchemaRequest, stringplanmodifier.UseStateForUnknown(), }, }, - "credentials_id": schema.StringAttribute{ - Description: descriptions["credentials_id"], + "credential_id": schema.StringAttribute{ + Description: descriptions["credential_id"], Computed: true, PlanModifiers: []planmodifier.String{ stringplanmodifier.UseStateForUnknown(), @@ -202,13 +202,13 @@ func (r *credentialResource) Create(ctx context.Context, req resource.CreateRequ return } if credentialsResp.Id == nil { - core.LogAndAddError(ctx, &resp.Diagnostics, "Error creating credential", "Got empty credentials id") + core.LogAndAddError(ctx, &resp.Diagnostics, "Error creating credential", "Got empty credential id") return } - credentialsId := *credentialsResp.Id - ctx = tflog.SetField(ctx, "credentials_id", credentialsId) + credentialId := *credentialsResp.Id + ctx = tflog.SetField(ctx, "credential_id", credentialId) - wr, err := wait.CreateCredentialsWaitHandler(ctx, r.client, projectId, instanceId, credentialsId).SetTimeout(1 * time.Minute).WaitWithContext(ctx) + wr, err := wait.CreateCredentialsWaitHandler(ctx, r.client, projectId, instanceId, credentialId).SetTimeout(1 * time.Minute).WaitWithContext(ctx) if err != nil { core.LogAndAddError(ctx, &resp.Diagnostics, "Error creating credential", fmt.Sprintf("Instance creation waiting: %v", err)) return @@ -230,7 +230,7 @@ func (r *credentialResource) Create(ctx context.Context, req resource.CreateRequ if resp.Diagnostics.HasError() { return } - tflog.Info(ctx, "RabbitMQ credentials created") + tflog.Info(ctx, "RabbitMQ credential created") } // Read refreshes the Terraform state with the latest data. @@ -243,12 +243,12 @@ func (r *credentialResource) Read(ctx context.Context, req resource.ReadRequest, } projectId := model.ProjectId.ValueString() instanceId := model.InstanceId.ValueString() - credentialsId := model.CredentialsId.ValueString() + credentialId := model.CredentialId.ValueString() ctx = tflog.SetField(ctx, "project_id", projectId) ctx = tflog.SetField(ctx, "instance_id", instanceId) - ctx = tflog.SetField(ctx, "credentials_id", credentialsId) + ctx = tflog.SetField(ctx, "credential_id", credentialId) - recordSetResp, err := r.client.GetCredentials(ctx, projectId, instanceId, credentialsId).Execute() + recordSetResp, err := r.client.GetCredentials(ctx, projectId, instanceId, credentialId).Execute() if err != nil { core.LogAndAddError(ctx, &resp.Diagnostics, "Error reading credential", fmt.Sprintf("Calling API: %v", err)) return @@ -267,7 +267,7 @@ func (r *credentialResource) Read(ctx context.Context, req resource.ReadRequest, if resp.Diagnostics.HasError() { return } - tflog.Info(ctx, "RabbitMQ credentials read") + tflog.Info(ctx, "RabbitMQ credential read") } // Update updates the resource and sets the updated Terraform state on success. @@ -287,40 +287,40 @@ func (r *credentialResource) Delete(ctx context.Context, req resource.DeleteRequ projectId := model.ProjectId.ValueString() instanceId := model.InstanceId.ValueString() - credentialsId := model.CredentialsId.ValueString() + credentialId := model.CredentialId.ValueString() ctx = tflog.SetField(ctx, "project_id", projectId) ctx = tflog.SetField(ctx, "instance_id", instanceId) - ctx = tflog.SetField(ctx, "credentials_id", credentialsId) + ctx = tflog.SetField(ctx, "credential_id", credentialId) // Delete existing record set - err := r.client.DeleteCredentials(ctx, projectId, instanceId, credentialsId).Execute() + err := r.client.DeleteCredentials(ctx, projectId, instanceId, credentialId).Execute() if err != nil { core.LogAndAddError(ctx, &resp.Diagnostics, "Error deleting credential", fmt.Sprintf("Calling API: %v", err)) } - _, err = wait.DeleteCredentialsWaitHandler(ctx, r.client, projectId, instanceId, credentialsId).SetTimeout(1 * time.Minute).WaitWithContext(ctx) + _, err = wait.DeleteCredentialsWaitHandler(ctx, r.client, projectId, instanceId, credentialId).SetTimeout(1 * time.Minute).WaitWithContext(ctx) if err != nil { core.LogAndAddError(ctx, &resp.Diagnostics, "Error deleting credential", fmt.Sprintf("Instance deletion waiting: %v", err)) return } - tflog.Info(ctx, "RabbitMQ credentials deleted") + tflog.Info(ctx, "RabbitMQ credential deleted") } // ImportState imports a resource into the Terraform state on success. -// The expected format of the resource import identifier is: project_id,instance_id,credentials_id +// The expected format of the resource import identifier is: project_id,instance_id,credential_id func (r *credentialResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { idParts := strings.Split(req.ID, core.Separator) if len(idParts) != 3 || idParts[0] == "" || idParts[1] == "" || idParts[2] == "" { core.LogAndAddError(ctx, &resp.Diagnostics, "Error importing credential", - fmt.Sprintf("Expected import identifier with format [project_id],[instance_id],[credentials_id], got %q", req.ID), + fmt.Sprintf("Expected import identifier with format [project_id],[instance_id],[credential_id], got %q", req.ID), ) return } resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("project_id"), idParts[0])...) resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("instance_id"), idParts[1])...) - resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("credentials_id"), idParts[2])...) - tflog.Info(ctx, "RabbitMQ credentials state imported") + resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("credential_id"), idParts[2])...) + tflog.Info(ctx, "RabbitMQ credential state imported") } func mapFields(credentialsResp *rabbitmq.CredentialsResponse, model *Model) error { @@ -335,11 +335,11 @@ func mapFields(credentialsResp *rabbitmq.CredentialsResponse, model *Model) erro } credentials := credentialsResp.Raw.Credentials - var credentialsId string - if model.CredentialsId.ValueString() != "" { - credentialsId = model.CredentialsId.ValueString() + var credentialId string + if model.CredentialId.ValueString() != "" { + credentialId = model.CredentialId.ValueString() } else if credentialsResp.Id != nil { - credentialsId = *credentialsResp.Id + credentialId = *credentialsResp.Id } else { return fmt.Errorf("credentials id not present") } @@ -347,12 +347,12 @@ func mapFields(credentialsResp *rabbitmq.CredentialsResponse, model *Model) erro idParts := []string{ model.ProjectId.ValueString(), model.InstanceId.ValueString(), - credentialsId, + credentialId, } model.Id = types.StringValue( strings.Join(idParts, core.Separator), ) - model.CredentialsId = types.StringValue(credentialsId) + model.CredentialId = types.StringValue(credentialId) model.Hosts = types.ListNull(types.StringType) if credentials != nil { if credentials.Hosts != nil { diff --git a/stackit/internal/services/rabbitmq/credential/resource_test.go b/stackit/internal/services/rabbitmq/credential/resource_test.go index 5e6e3c44..f358aedd 100644 --- a/stackit/internal/services/rabbitmq/credential/resource_test.go +++ b/stackit/internal/services/rabbitmq/credential/resource_test.go @@ -24,18 +24,18 @@ func TestMapFields(t *testing.T) { Raw: &rabbitmq.RawCredentials{}, }, Model{ - Id: types.StringValue("pid,iid,cid"), - CredentialsId: types.StringValue("cid"), - InstanceId: types.StringValue("iid"), - ProjectId: types.StringValue("pid"), - Host: types.StringNull(), - Hosts: types.ListNull(types.StringType), - HttpAPIURI: types.StringNull(), - Name: types.StringNull(), - Password: types.StringNull(), - Port: types.Int64Null(), - Uri: types.StringNull(), - Username: types.StringNull(), + Id: types.StringValue("pid,iid,cid"), + CredentialId: types.StringValue("cid"), + InstanceId: types.StringValue("iid"), + ProjectId: types.StringValue("pid"), + Host: types.StringNull(), + Hosts: types.ListNull(types.StringType), + HttpAPIURI: types.StringNull(), + Name: types.StringNull(), + Password: types.StringNull(), + Port: types.Int64Null(), + Uri: types.StringNull(), + Username: types.StringNull(), }, true, }, @@ -60,11 +60,11 @@ func TestMapFields(t *testing.T) { }, }, Model{ - Id: types.StringValue("pid,iid,cid"), - CredentialsId: types.StringValue("cid"), - InstanceId: types.StringValue("iid"), - ProjectId: types.StringValue("pid"), - Host: types.StringValue("host"), + Id: types.StringValue("pid,iid,cid"), + CredentialId: types.StringValue("cid"), + InstanceId: types.StringValue("iid"), + ProjectId: types.StringValue("pid"), + Host: types.StringValue("host"), Hosts: types.ListValueMust(types.StringType, []attr.Value{ types.StringValue("host_1"), types.StringValue(""), @@ -96,18 +96,18 @@ func TestMapFields(t *testing.T) { }, }, Model{ - Id: types.StringValue("pid,iid,cid"), - CredentialsId: types.StringValue("cid"), - InstanceId: types.StringValue("iid"), - ProjectId: types.StringValue("pid"), - Host: types.StringValue(""), - Hosts: types.ListValueMust(types.StringType, []attr.Value{}), - HttpAPIURI: types.StringNull(), - Name: types.StringNull(), - Password: types.StringValue(""), - Port: types.Int64Value(2123456789), - Uri: types.StringNull(), - Username: types.StringValue(""), + Id: types.StringValue("pid,iid,cid"), + CredentialId: types.StringValue("cid"), + InstanceId: types.StringValue("iid"), + ProjectId: types.StringValue("pid"), + Host: types.StringValue(""), + Hosts: types.ListValueMust(types.StringType, []attr.Value{}), + HttpAPIURI: types.StringNull(), + Name: types.StringNull(), + Password: types.StringValue(""), + Port: types.Int64Value(2123456789), + Uri: types.StringNull(), + Username: types.StringValue(""), }, true, }, diff --git a/stackit/internal/services/rabbitmq/rabbitmq_acc_test.go b/stackit/internal/services/rabbitmq/rabbitmq_acc_test.go index 21a178bc..be106e22 100644 --- a/stackit/internal/services/rabbitmq/rabbitmq_acc_test.go +++ b/stackit/internal/services/rabbitmq/rabbitmq_acc_test.go @@ -56,7 +56,7 @@ func resourceConfig(acls *string) string { instanceResource["version"], aclsLine, instanceResource["metrics_frequency"], - resourceConfigCredentials(), + resourceConfigCredential(), ) } @@ -82,13 +82,13 @@ func resourceConfigWithUpdate() string { instanceResource["plan_name"], instanceResource["version"], instanceResource["sgw_acl_valid"], - resourceConfigCredentials(), + resourceConfigCredential(), ) } -func resourceConfigCredentials() string { +func resourceConfigCredential() string { return ` - resource "stackit_rabbitmq_credential" "credentials" { + resource "stackit_rabbitmq_credential" "credential" { project_id = stackit_rabbitmq_instance.instance.project_id instance_id = stackit_rabbitmq_instance.instance.instance_id } @@ -119,17 +119,17 @@ func TestAccRabbitMQResource(t *testing.T) { resource.TestCheckResourceAttr("stackit_rabbitmq_instance.instance", "name", instanceResource["name"]), resource.TestCheckResourceAttrSet("stackit_rabbitmq_instance.instance", "parameters.sgw_acl"), - // Credentials data + // Credential data resource.TestCheckResourceAttrPair( - "stackit_rabbitmq_credential.credentials", "project_id", + "stackit_rabbitmq_credential.credential", "project_id", "stackit_rabbitmq_instance.instance", "project_id", ), resource.TestCheckResourceAttrPair( - "stackit_rabbitmq_credential.credentials", "instance_id", + "stackit_rabbitmq_credential.credential", "instance_id", "stackit_rabbitmq_instance.instance", "instance_id", ), - resource.TestCheckResourceAttrSet("stackit_rabbitmq_credential.credentials", "credentials_id"), - resource.TestCheckResourceAttrSet("stackit_rabbitmq_credential.credentials", "host"), + resource.TestCheckResourceAttrSet("stackit_rabbitmq_credential.credential", "credential_id"), + resource.TestCheckResourceAttrSet("stackit_rabbitmq_credential.credential", "host"), ), }, // data source @@ -142,10 +142,10 @@ func TestAccRabbitMQResource(t *testing.T) { instance_id = stackit_rabbitmq_instance.instance.instance_id } - data "stackit_rabbitmq_credential" "credentials" { - project_id = stackit_rabbitmq_credential.credentials.project_id - instance_id = stackit_rabbitmq_credential.credentials.instance_id - credentials_id = stackit_rabbitmq_credential.credentials.credentials_id + data "stackit_rabbitmq_credential" "credential" { + project_id = stackit_rabbitmq_credential.credential.project_id + instance_id = stackit_rabbitmq_credential.credential.instance_id + credential_id = stackit_rabbitmq_credential.credential.credential_id }`, resourceConfig(nil), ), @@ -153,19 +153,19 @@ func TestAccRabbitMQResource(t *testing.T) { // Instance data resource.TestCheckResourceAttr("data.stackit_rabbitmq_instance.instance", "project_id", instanceResource["project_id"]), resource.TestCheckResourceAttrPair("stackit_rabbitmq_instance.instance", "instance_id", - "data.stackit_rabbitmq_credential.credentials", "instance_id"), + "data.stackit_rabbitmq_credential.credential", "instance_id"), resource.TestCheckResourceAttrPair("data.stackit_rabbitmq_instance.instance", "instance_id", - "data.stackit_rabbitmq_credential.credentials", "instance_id"), + "data.stackit_rabbitmq_credential.credential", "instance_id"), resource.TestCheckResourceAttr("data.stackit_rabbitmq_instance.instance", "plan_id", instanceResource["plan_id"]), resource.TestCheckResourceAttr("data.stackit_rabbitmq_instance.instance", "name", instanceResource["name"]), resource.TestCheckResourceAttrSet("data.stackit_rabbitmq_instance.instance", "parameters.sgw_acl"), - // Credentials data - resource.TestCheckResourceAttr("data.stackit_rabbitmq_credential.credentials", "project_id", instanceResource["project_id"]), - resource.TestCheckResourceAttrSet("data.stackit_rabbitmq_credential.credentials", "credentials_id"), - resource.TestCheckResourceAttrSet("data.stackit_rabbitmq_credential.credentials", "host"), - resource.TestCheckResourceAttrSet("data.stackit_rabbitmq_credential.credentials", "port"), - resource.TestCheckResourceAttrSet("data.stackit_rabbitmq_credential.credentials", "uri"), + // Credential data + resource.TestCheckResourceAttr("data.stackit_rabbitmq_credential.credential", "project_id", instanceResource["project_id"]), + resource.TestCheckResourceAttrSet("data.stackit_rabbitmq_credential.credential", "credential_id"), + resource.TestCheckResourceAttrSet("data.stackit_rabbitmq_credential.credential", "host"), + resource.TestCheckResourceAttrSet("data.stackit_rabbitmq_credential.credential", "port"), + resource.TestCheckResourceAttrSet("data.stackit_rabbitmq_credential.credential", "uri"), ), }, // Import @@ -186,21 +186,21 @@ func TestAccRabbitMQResource(t *testing.T) { ImportStateVerify: true, }, { - ResourceName: "stackit_rabbitmq_credential.credentials", + ResourceName: "stackit_rabbitmq_credential.credential", ImportStateIdFunc: func(s *terraform.State) (string, error) { - r, ok := s.RootModule().Resources["stackit_rabbitmq_credential.credentials"] + r, ok := s.RootModule().Resources["stackit_rabbitmq_credential.credential"] if !ok { - return "", fmt.Errorf("couldn't find resource stackit_rabbitmq_credential.credentials") + return "", fmt.Errorf("couldn't find resource stackit_rabbitmq_credential.credential") } instanceId, ok := r.Primary.Attributes["instance_id"] if !ok { return "", fmt.Errorf("couldn't find attribute instance_id") } - credentialsId, ok := r.Primary.Attributes["credentials_id"] + credentialId, ok := r.Primary.Attributes["credential_id"] if !ok { - return "", fmt.Errorf("couldn't find attribute credentials_id") + return "", fmt.Errorf("couldn't find attribute credential_id") } - return fmt.Sprintf("%s,%s,%s", testutil.ProjectId, instanceId, credentialsId), nil + return fmt.Sprintf("%s,%s,%s", testutil.ProjectId, instanceId, credentialId), nil }, ImportState: true, ImportStateVerify: true, diff --git a/stackit/internal/services/redis/credential/datasource.go b/stackit/internal/services/redis/credential/datasource.go index 1a6f2166..f058ddc3 100644 --- a/stackit/internal/services/redis/credential/datasource.go +++ b/stackit/internal/services/redis/credential/datasource.go @@ -69,17 +69,17 @@ func (r *credentialDataSource) Configure(ctx context.Context, req datasource.Con } r.client = apiClient - tflog.Info(ctx, "Redis credentials client configured") + tflog.Info(ctx, "Redis credential client configured") } // Schema defines the schema for the data source. func (r *credentialDataSource) Schema(_ context.Context, _ datasource.SchemaRequest, resp *datasource.SchemaResponse) { descriptions := map[string]string{ - "main": "Redis credential data source schema.", - "id": "Terraform's internal data source. identifier. It is structured as \"`project_id`,`instance_id`,`credentials_id`\".", - "credentials_id": "The credentials ID.", - "instance_id": "ID of the Redis instance.", - "project_id": "STACKIT project ID to which the instance is associated.", + "main": "Redis credential data source schema.", + "id": "Terraform's internal data source. identifier. It is structured as \"`project_id`,`instance_id`,`credential_id`\".", + "credential_id": "The credential's ID.", + "instance_id": "ID of the Redis instance.", + "project_id": "STACKIT project ID to which the instance is associated.", } resp.Schema = schema.Schema{ @@ -89,8 +89,8 @@ func (r *credentialDataSource) Schema(_ context.Context, _ datasource.SchemaRequ Description: descriptions["id"], Computed: true, }, - "credentials_id": schema.StringAttribute{ - Description: descriptions["credentials_id"], + "credential_id": schema.StringAttribute{ + Description: descriptions["credential_id"], Required: true, Validators: []validator.String{ validate.UUID(), @@ -153,12 +153,12 @@ func (r *credentialDataSource) Read(ctx context.Context, req datasource.ReadRequ } projectId := model.ProjectId.ValueString() instanceId := model.InstanceId.ValueString() - credentialsId := model.CredentialsId.ValueString() + credentialId := model.CredentialId.ValueString() ctx = tflog.SetField(ctx, "project_id", projectId) ctx = tflog.SetField(ctx, "instance_id", instanceId) - ctx = tflog.SetField(ctx, "credentials_id", credentialsId) + ctx = tflog.SetField(ctx, "credential_id", credentialId) - recordSetResp, err := r.client.GetCredentials(ctx, projectId, instanceId, credentialsId).Execute() + recordSetResp, err := r.client.GetCredentials(ctx, projectId, instanceId, credentialId).Execute() if err != nil { core.LogAndAddError(ctx, &resp.Diagnostics, "Error reading credential", fmt.Sprintf("Calling API: %v", err)) return @@ -177,5 +177,5 @@ func (r *credentialDataSource) Read(ctx context.Context, req datasource.ReadRequ if resp.Diagnostics.HasError() { return } - tflog.Info(ctx, "Redis credentials read") + tflog.Info(ctx, "Redis credential read") } diff --git a/stackit/internal/services/redis/credential/resource.go b/stackit/internal/services/redis/credential/resource.go index d953d499..3de20208 100644 --- a/stackit/internal/services/redis/credential/resource.go +++ b/stackit/internal/services/redis/credential/resource.go @@ -32,18 +32,18 @@ var ( ) type Model struct { - Id types.String `tfsdk:"id"` // needed by TF - CredentialsId types.String `tfsdk:"credentials_id"` - InstanceId types.String `tfsdk:"instance_id"` - ProjectId types.String `tfsdk:"project_id"` - Host types.String `tfsdk:"host"` - Hosts types.List `tfsdk:"hosts"` - HttpAPIURI types.String `tfsdk:"http_api_uri"` - Name types.String `tfsdk:"name"` - Password types.String `tfsdk:"password"` - Port types.Int64 `tfsdk:"port"` - Uri types.String `tfsdk:"uri"` - Username types.String `tfsdk:"username"` + Id types.String `tfsdk:"id"` // needed by TF + CredentialId types.String `tfsdk:"credential_id"` + InstanceId types.String `tfsdk:"instance_id"` + ProjectId types.String `tfsdk:"project_id"` + Host types.String `tfsdk:"host"` + Hosts types.List `tfsdk:"hosts"` + HttpAPIURI types.String `tfsdk:"http_api_uri"` + Name types.String `tfsdk:"name"` + Password types.String `tfsdk:"password"` + Port types.Int64 `tfsdk:"port"` + Uri types.String `tfsdk:"uri"` + Username types.String `tfsdk:"username"` } // NewCredentialResource is a helper function to simplify the provider implementation. @@ -94,17 +94,17 @@ func (r *credentialResource) Configure(ctx context.Context, req resource.Configu } r.client = apiClient - tflog.Info(ctx, "Redis credentials client configured") + tflog.Info(ctx, "Redis credential client configured") } // Schema defines the schema for the resource. func (r *credentialResource) Schema(_ context.Context, _ resource.SchemaRequest, resp *resource.SchemaResponse) { descriptions := map[string]string{ - "main": "Redis credential resource schema.", - "id": "Terraform's internal resource identifier. It is structured as \"`project_id`,`instance_id`,`credentials_id`\".", - "credentials_id": "The credentials ID.", - "instance_id": "ID of the Redis instance.", - "project_id": "STACKIT Project ID to which the instance is associated.", + "main": "Redis credential resource schema.", + "id": "Terraform's internal resource identifier. It is structured as \"`project_id`,`instance_id`,`credential_id`\".", + "credential_id": "The credential's ID.", + "instance_id": "ID of the Redis instance.", + "project_id": "STACKIT Project ID to which the instance is associated.", } resp.Schema = schema.Schema{ @@ -117,8 +117,8 @@ func (r *credentialResource) Schema(_ context.Context, _ resource.SchemaRequest, stringplanmodifier.UseStateForUnknown(), }, }, - "credentials_id": schema.StringAttribute{ - Description: descriptions["credentials_id"], + "credential_id": schema.StringAttribute{ + Description: descriptions["credential_id"], Computed: true, PlanModifiers: []planmodifier.String{ stringplanmodifier.UseStateForUnknown(), @@ -202,13 +202,13 @@ func (r *credentialResource) Create(ctx context.Context, req resource.CreateRequ return } if credentialsResp.Id == nil { - core.LogAndAddError(ctx, &resp.Diagnostics, "Error creating credential", "Got empty credentials id") + core.LogAndAddError(ctx, &resp.Diagnostics, "Error creating credential", "Got empty credential id") return } - credentialsId := *credentialsResp.Id - ctx = tflog.SetField(ctx, "credentials_id", credentialsId) + credentialId := *credentialsResp.Id + ctx = tflog.SetField(ctx, "credential_id", credentialId) - wr, err := wait.CreateCredentialsWaitHandler(ctx, r.client, projectId, instanceId, credentialsId).SetTimeout(1 * time.Minute).WaitWithContext(ctx) + wr, err := wait.CreateCredentialsWaitHandler(ctx, r.client, projectId, instanceId, credentialId).SetTimeout(1 * time.Minute).WaitWithContext(ctx) if err != nil { core.LogAndAddError(ctx, &resp.Diagnostics, "Error creating credential", fmt.Sprintf("Instance creation waiting: %v", err)) return @@ -230,7 +230,7 @@ func (r *credentialResource) Create(ctx context.Context, req resource.CreateRequ if resp.Diagnostics.HasError() { return } - tflog.Info(ctx, "Redis credentials created") + tflog.Info(ctx, "Redis credential created") } // Read refreshes the Terraform state with the latest data. @@ -243,12 +243,12 @@ func (r *credentialResource) Read(ctx context.Context, req resource.ReadRequest, } projectId := model.ProjectId.ValueString() instanceId := model.InstanceId.ValueString() - credentialsId := model.CredentialsId.ValueString() + credentialId := model.CredentialId.ValueString() ctx = tflog.SetField(ctx, "project_id", projectId) ctx = tflog.SetField(ctx, "instance_id", instanceId) - ctx = tflog.SetField(ctx, "credentials_id", credentialsId) + ctx = tflog.SetField(ctx, "credential_id", credentialId) - recordSetResp, err := r.client.GetCredentials(ctx, projectId, instanceId, credentialsId).Execute() + recordSetResp, err := r.client.GetCredentials(ctx, projectId, instanceId, credentialId).Execute() if err != nil { core.LogAndAddError(ctx, &resp.Diagnostics, "Error reading credential", fmt.Sprintf("Calling API: %v", err)) return @@ -267,7 +267,7 @@ func (r *credentialResource) Read(ctx context.Context, req resource.ReadRequest, if resp.Diagnostics.HasError() { return } - tflog.Info(ctx, "Redis credentials read") + tflog.Info(ctx, "Redis credential read") } // Update updates the resource and sets the updated Terraform state on success. @@ -287,40 +287,40 @@ func (r *credentialResource) Delete(ctx context.Context, req resource.DeleteRequ projectId := model.ProjectId.ValueString() instanceId := model.InstanceId.ValueString() - credentialsId := model.CredentialsId.ValueString() + credentialId := model.CredentialId.ValueString() ctx = tflog.SetField(ctx, "project_id", projectId) ctx = tflog.SetField(ctx, "instance_id", instanceId) - ctx = tflog.SetField(ctx, "credentials_id", credentialsId) + ctx = tflog.SetField(ctx, "credential_id", credentialId) // Delete existing record set - err := r.client.DeleteCredentials(ctx, projectId, instanceId, credentialsId).Execute() + err := r.client.DeleteCredentials(ctx, projectId, instanceId, credentialId).Execute() if err != nil { core.LogAndAddError(ctx, &resp.Diagnostics, "Error deleting credential", fmt.Sprintf("Calling API: %v", err)) } - _, err = wait.DeleteCredentialsWaitHandler(ctx, r.client, projectId, instanceId, credentialsId).SetTimeout(1 * time.Minute).WaitWithContext(ctx) + _, err = wait.DeleteCredentialsWaitHandler(ctx, r.client, projectId, instanceId, credentialId).SetTimeout(1 * time.Minute).WaitWithContext(ctx) if err != nil { core.LogAndAddError(ctx, &resp.Diagnostics, "Error deleting credential", fmt.Sprintf("Instance deletion waiting: %v", err)) return } - tflog.Info(ctx, "Redis credentials deleted") + tflog.Info(ctx, "Redis credential deleted") } // ImportState imports a resource into the Terraform state on success. -// The expected format of the resource import identifier is: project_id,instance_id,credentials_id +// The expected format of the resource import identifier is: project_id,instance_id,credential_id func (r *credentialResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { idParts := strings.Split(req.ID, core.Separator) if len(idParts) != 3 || idParts[0] == "" || idParts[1] == "" || idParts[2] == "" { core.LogAndAddError(ctx, &resp.Diagnostics, "Error importing credential", - fmt.Sprintf("Expected import identifier with format [project_id],[instance_id],[credentials_id], got %q", req.ID), + fmt.Sprintf("Expected import identifier with format [project_id],[instance_id],[credential_id], got %q", req.ID), ) return } resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("project_id"), idParts[0])...) resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("instance_id"), idParts[1])...) - resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("credentials_id"), idParts[2])...) - tflog.Info(ctx, "Redis credentials state imported") + resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("credential_id"), idParts[2])...) + tflog.Info(ctx, "Redis credential state imported") } func mapFields(credentialsResp *redis.CredentialsResponse, model *Model) error { @@ -335,11 +335,11 @@ func mapFields(credentialsResp *redis.CredentialsResponse, model *Model) error { } credentials := credentialsResp.Raw.Credentials - var credentialsId string - if model.CredentialsId.ValueString() != "" { - credentialsId = model.CredentialsId.ValueString() + var credentialId string + if model.CredentialId.ValueString() != "" { + credentialId = model.CredentialId.ValueString() } else if credentialsResp.Id != nil { - credentialsId = *credentialsResp.Id + credentialId = *credentialsResp.Id } else { return fmt.Errorf("credentials id not present") } @@ -347,12 +347,12 @@ func mapFields(credentialsResp *redis.CredentialsResponse, model *Model) error { idParts := []string{ model.ProjectId.ValueString(), model.InstanceId.ValueString(), - credentialsId, + credentialId, } model.Id = types.StringValue( strings.Join(idParts, core.Separator), ) - model.CredentialsId = types.StringValue(credentialsId) + model.CredentialId = types.StringValue(credentialId) model.Hosts = types.ListNull(types.StringType) if credentials != nil { if credentials.Hosts != nil { diff --git a/stackit/internal/services/redis/credential/resource_test.go b/stackit/internal/services/redis/credential/resource_test.go index b601dbed..5ca3032b 100644 --- a/stackit/internal/services/redis/credential/resource_test.go +++ b/stackit/internal/services/redis/credential/resource_test.go @@ -24,18 +24,18 @@ func TestMapFields(t *testing.T) { Raw: &redis.RawCredentials{}, }, Model{ - Id: types.StringValue("pid,iid,cid"), - CredentialsId: types.StringValue("cid"), - InstanceId: types.StringValue("iid"), - ProjectId: types.StringValue("pid"), - Host: types.StringNull(), - Hosts: types.ListNull(types.StringType), - HttpAPIURI: types.StringNull(), - Name: types.StringNull(), - Password: types.StringNull(), - Port: types.Int64Null(), - Uri: types.StringNull(), - Username: types.StringNull(), + Id: types.StringValue("pid,iid,cid"), + CredentialId: types.StringValue("cid"), + InstanceId: types.StringValue("iid"), + ProjectId: types.StringValue("pid"), + Host: types.StringNull(), + Hosts: types.ListNull(types.StringType), + HttpAPIURI: types.StringNull(), + Name: types.StringNull(), + Password: types.StringNull(), + Port: types.Int64Null(), + Uri: types.StringNull(), + Username: types.StringNull(), }, true, }, @@ -60,11 +60,11 @@ func TestMapFields(t *testing.T) { }, }, Model{ - Id: types.StringValue("pid,iid,cid"), - CredentialsId: types.StringValue("cid"), - InstanceId: types.StringValue("iid"), - ProjectId: types.StringValue("pid"), - Host: types.StringValue("host"), + Id: types.StringValue("pid,iid,cid"), + CredentialId: types.StringValue("cid"), + InstanceId: types.StringValue("iid"), + ProjectId: types.StringValue("pid"), + Host: types.StringValue("host"), Hosts: types.ListValueMust(types.StringType, []attr.Value{ types.StringValue("host_1"), types.StringValue(""), @@ -96,18 +96,18 @@ func TestMapFields(t *testing.T) { }, }, Model{ - Id: types.StringValue("pid,iid,cid"), - CredentialsId: types.StringValue("cid"), - InstanceId: types.StringValue("iid"), - ProjectId: types.StringValue("pid"), - Host: types.StringValue(""), - Hosts: types.ListValueMust(types.StringType, []attr.Value{}), - HttpAPIURI: types.StringNull(), - Name: types.StringNull(), - Password: types.StringValue(""), - Port: types.Int64Value(2123456789), - Uri: types.StringNull(), - Username: types.StringValue(""), + Id: types.StringValue("pid,iid,cid"), + CredentialId: types.StringValue("cid"), + InstanceId: types.StringValue("iid"), + ProjectId: types.StringValue("pid"), + Host: types.StringValue(""), + Hosts: types.ListValueMust(types.StringType, []attr.Value{}), + HttpAPIURI: types.StringNull(), + Name: types.StringNull(), + Password: types.StringValue(""), + Port: types.Int64Value(2123456789), + Uri: types.StringNull(), + Username: types.StringValue(""), }, true, }, diff --git a/stackit/internal/services/redis/redis_acc_test.go b/stackit/internal/services/redis/redis_acc_test.go index 2ae8f9d5..0d2bfbe2 100644 --- a/stackit/internal/services/redis/redis_acc_test.go +++ b/stackit/internal/services/redis/redis_acc_test.go @@ -56,7 +56,7 @@ func resourceConfig(acls *string) string { instanceResource["version"], aclsLine, instanceResource["metrics_frequency"], - resourceConfigCredentials(), + resourceConfigCredential(), ) } @@ -82,13 +82,13 @@ func resourceConfigWithUpdate() string { instanceResource["plan_name"], instanceResource["version"], instanceResource["sgw_acl_valid"], - resourceConfigCredentials(), + resourceConfigCredential(), ) } -func resourceConfigCredentials() string { +func resourceConfigCredential() string { return ` - resource "stackit_redis_credential" "credentials" { + resource "stackit_redis_credential" "credential" { project_id = stackit_redis_instance.instance.project_id instance_id = stackit_redis_instance.instance.instance_id } @@ -119,17 +119,17 @@ func TestAccRedisResource(t *testing.T) { resource.TestCheckResourceAttr("stackit_redis_instance.instance", "name", instanceResource["name"]), resource.TestCheckResourceAttrSet("stackit_redis_instance.instance", "parameters.sgw_acl"), - // Credentials data + // Credential data resource.TestCheckResourceAttrPair( - "stackit_redis_credential.credentials", "project_id", + "stackit_redis_credential.credential", "project_id", "stackit_redis_instance.instance", "project_id", ), resource.TestCheckResourceAttrPair( - "stackit_redis_credential.credentials", "instance_id", + "stackit_redis_credential.credential", "instance_id", "stackit_redis_instance.instance", "instance_id", ), - resource.TestCheckResourceAttrSet("stackit_redis_credential.credentials", "credentials_id"), - resource.TestCheckResourceAttrSet("stackit_redis_credential.credentials", "host"), + resource.TestCheckResourceAttrSet("stackit_redis_credential.credential", "credential_id"), + resource.TestCheckResourceAttrSet("stackit_redis_credential.credential", "host"), ), }, // data source @@ -142,10 +142,10 @@ func TestAccRedisResource(t *testing.T) { instance_id = stackit_redis_instance.instance.instance_id } - data "stackit_redis_credential" "credentials" { - project_id = stackit_redis_credential.credentials.project_id - instance_id = stackit_redis_credential.credentials.instance_id - credentials_id = stackit_redis_credential.credentials.credentials_id + data "stackit_redis_credential" "credential" { + project_id = stackit_redis_credential.credential.project_id + instance_id = stackit_redis_credential.credential.instance_id + credential_id = stackit_redis_credential.credential.credential_id }`, resourceConfig(nil), ), @@ -153,19 +153,19 @@ func TestAccRedisResource(t *testing.T) { // Instance data resource.TestCheckResourceAttr("data.stackit_redis_instance.instance", "project_id", instanceResource["project_id"]), resource.TestCheckResourceAttrPair("stackit_redis_instance.instance", "instance_id", - "data.stackit_redis_credential.credentials", "instance_id"), + "data.stackit_redis_credential.credential", "instance_id"), resource.TestCheckResourceAttrPair("data.stackit_redis_instance.instance", "instance_id", - "data.stackit_redis_credential.credentials", "instance_id"), + "data.stackit_redis_credential.credential", "instance_id"), resource.TestCheckResourceAttr("data.stackit_redis_instance.instance", "plan_id", instanceResource["plan_id"]), resource.TestCheckResourceAttr("data.stackit_redis_instance.instance", "name", instanceResource["name"]), resource.TestCheckResourceAttrSet("data.stackit_redis_instance.instance", "parameters.sgw_acl"), // Credentials data - resource.TestCheckResourceAttr("data.stackit_redis_credential.credentials", "project_id", instanceResource["project_id"]), - resource.TestCheckResourceAttrSet("data.stackit_redis_credential.credentials", "credentials_id"), - resource.TestCheckResourceAttrSet("data.stackit_redis_credential.credentials", "host"), - resource.TestCheckResourceAttrSet("data.stackit_redis_credential.credentials", "port"), - resource.TestCheckResourceAttrSet("data.stackit_redis_credential.credentials", "uri"), + resource.TestCheckResourceAttr("data.stackit_redis_credential.credential", "project_id", instanceResource["project_id"]), + resource.TestCheckResourceAttrSet("data.stackit_redis_credential.credential", "credential_id"), + resource.TestCheckResourceAttrSet("data.stackit_redis_credential.credential", "host"), + resource.TestCheckResourceAttrSet("data.stackit_redis_credential.credential", "port"), + resource.TestCheckResourceAttrSet("data.stackit_redis_credential.credential", "uri"), ), }, // Import @@ -186,21 +186,21 @@ func TestAccRedisResource(t *testing.T) { ImportStateVerify: true, }, { - ResourceName: "stackit_redis_credential.credentials", + ResourceName: "stackit_redis_credential.credential", ImportStateIdFunc: func(s *terraform.State) (string, error) { - r, ok := s.RootModule().Resources["stackit_redis_credential.credentials"] + r, ok := s.RootModule().Resources["stackit_redis_credential.credential"] if !ok { - return "", fmt.Errorf("couldn't find resource stackit_redis_credential.credentials") + return "", fmt.Errorf("couldn't find resource stackit_redis_credential.credential") } instanceId, ok := r.Primary.Attributes["instance_id"] if !ok { return "", fmt.Errorf("couldn't find attribute instance_id") } - credentialsId, ok := r.Primary.Attributes["credentials_id"] + credentialId, ok := r.Primary.Attributes["credential_id"] if !ok { - return "", fmt.Errorf("couldn't find attribute credentials_id") + return "", fmt.Errorf("couldn't find attribute credential_id") } - return fmt.Sprintf("%s,%s,%s", testutil.ProjectId, instanceId, credentialsId), nil + return fmt.Sprintf("%s,%s,%s", testutil.ProjectId, instanceId, credentialId), nil }, ImportState: true, ImportStateVerify: true,