Rename credentials_id field to credential_id (#80)

* Rename credentials_id field to credential_id

* Address review comments
This commit is contained in:
João Palet 2023-10-12 15:57:05 +02:00 committed by GitHub
parent b02db190bf
commit 5a5ac6640c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
43 changed files with 722 additions and 722 deletions

View file

@ -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")
}

View file

@ -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 {

View file

@ -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,
},

View file

@ -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,

View file

@ -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")
}

View file

@ -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 {

View file

@ -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,
},

View file

@ -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,

View file

@ -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")
}

View file

@ -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 {

View file

@ -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,
},

View file

@ -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,

View file

@ -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")
}

View file

@ -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 {

View file

@ -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,
},

View file

@ -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,

View file

@ -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")
}

View file

@ -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 {

View file

@ -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,
},

View file

@ -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,

View file

@ -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")
}

View file

@ -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 {

View file

@ -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,
},

View file

@ -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,