feat(observability): add description to credential resource (#992)
relates to STACKITTPR-333, #974
This commit is contained in:
parent
4b46119433
commit
39c52f4367
5 changed files with 34 additions and 6 deletions
|
|
@ -16,6 +16,7 @@ Observability credential resource schema. Must have a `region` specified in the
|
|||
resource "stackit_observability_credential" "example" {
|
||||
project_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
|
||||
instance_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
|
||||
description = "Description of the credential."
|
||||
}
|
||||
```
|
||||
|
||||
|
|
@ -27,6 +28,10 @@ resource "stackit_observability_credential" "example" {
|
|||
- `instance_id` (String) The Observability Instance ID the credential belongs to.
|
||||
- `project_id` (String) STACKIT project ID to which the credential is associated.
|
||||
|
||||
### Optional
|
||||
|
||||
- `description` (String) A description of the credential.
|
||||
|
||||
### Read-Only
|
||||
|
||||
- `id` (String) Terraform's internal resource ID. It is structured as "`project_id`,`instance_id`,`username`".
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
resource "stackit_observability_credential" "example" {
|
||||
project_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
|
||||
instance_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
|
||||
description = "Description of the credential."
|
||||
}
|
||||
|
|
|
|||
|
|
@ -29,11 +29,12 @@ var (
|
|||
)
|
||||
|
||||
type Model struct {
|
||||
Id types.String `tfsdk:"id"`
|
||||
ProjectId types.String `tfsdk:"project_id"`
|
||||
InstanceId types.String `tfsdk:"instance_id"`
|
||||
Username types.String `tfsdk:"username"`
|
||||
Password types.String `tfsdk:"password"`
|
||||
Id types.String `tfsdk:"id"`
|
||||
ProjectId types.String `tfsdk:"project_id"`
|
||||
InstanceId types.String `tfsdk:"instance_id"`
|
||||
Description types.String `tfsdk:"description"`
|
||||
Username types.String `tfsdk:"username"`
|
||||
Password types.String `tfsdk:"password"`
|
||||
}
|
||||
|
||||
// NewCredentialResource is a helper function to simplify the provider implementation.
|
||||
|
|
@ -97,6 +98,13 @@ func (r *credentialResource) Schema(_ context.Context, _ resource.SchemaRequest,
|
|||
stringplanmodifier.RequiresReplace(),
|
||||
},
|
||||
},
|
||||
"description": schema.StringAttribute{
|
||||
Description: "A description of the credential.",
|
||||
Optional: true,
|
||||
PlanModifiers: []planmodifier.String{
|
||||
stringplanmodifier.RequiresReplace(),
|
||||
},
|
||||
},
|
||||
"username": schema.StringAttribute{
|
||||
Description: "Credential username",
|
||||
Computed: true,
|
||||
|
|
@ -130,8 +138,13 @@ func (r *credentialResource) Create(ctx context.Context, req resource.CreateRequ
|
|||
|
||||
projectId := model.ProjectId.ValueString()
|
||||
instanceId := model.InstanceId.ValueString()
|
||||
description := model.Description.ValueStringPointer()
|
||||
|
||||
got, err := r.client.CreateCredentials(ctx, instanceId, projectId).Execute()
|
||||
got, err := r.client.CreateCredentials(ctx, instanceId, projectId).CreateCredentialsPayload(
|
||||
observability.CreateCredentialsPayload{
|
||||
Description: description,
|
||||
},
|
||||
).Execute()
|
||||
if err != nil {
|
||||
core.LogAndAddError(ctx, &resp.Diagnostics, "Error creating credential", fmt.Sprintf("Calling API: %v", err))
|
||||
return
|
||||
|
|
|
|||
|
|
@ -104,6 +104,8 @@ var testConfigVarsMax = config.Variables{
|
|||
"match": config.StringVariable("alert1"),
|
||||
"match_regex": config.StringVariable("alert1"),
|
||||
"matchers": config.StringVariable("instance =~ \".*\""),
|
||||
// credential
|
||||
"credential_description": config.StringVariable("This is a description for the test credential."),
|
||||
// logalertgroup
|
||||
"logalertgroup_for_time": config.StringVariable("60s"),
|
||||
"logalertgroup_label": config.StringVariable("label1"),
|
||||
|
|
@ -194,6 +196,7 @@ func TestAccResourceMin(t *testing.T) {
|
|||
"stackit_observability_instance.instance", "instance_id",
|
||||
"stackit_observability_credential.credential", "instance_id",
|
||||
),
|
||||
resource.TestCheckNoResourceAttr("stackit_observability_credential.credential", "description"),
|
||||
resource.TestCheckResourceAttrSet("stackit_observability_credential.credential", "username"),
|
||||
resource.TestCheckResourceAttrSet("stackit_observability_credential.credential", "password"),
|
||||
|
||||
|
|
@ -436,6 +439,7 @@ func TestAccResourceMin(t *testing.T) {
|
|||
"stackit_observability_instance.instance", "instance_id",
|
||||
"stackit_observability_credential.credential", "instance_id",
|
||||
),
|
||||
resource.TestCheckNoResourceAttr("stackit_observability_credential.credential", "description"),
|
||||
resource.TestCheckResourceAttrSet("stackit_observability_credential.credential", "username"),
|
||||
resource.TestCheckResourceAttrSet("stackit_observability_credential.credential", "password"),
|
||||
|
||||
|
|
@ -575,6 +579,7 @@ func TestAccResourceMax(t *testing.T) {
|
|||
"stackit_observability_instance.instance", "instance_id",
|
||||
"stackit_observability_credential.credential", "instance_id",
|
||||
),
|
||||
resource.TestCheckResourceAttr("stackit_observability_credential.credential", "description", testutil.ConvertConfigVariable(testConfigVarsMax["credential_description"])),
|
||||
resource.TestCheckResourceAttrSet("stackit_observability_credential.credential", "username"),
|
||||
resource.TestCheckResourceAttrSet("stackit_observability_credential.credential", "password"),
|
||||
|
||||
|
|
@ -966,6 +971,7 @@ func TestAccResourceMax(t *testing.T) {
|
|||
"stackit_observability_instance.instance", "instance_id",
|
||||
"stackit_observability_credential.credential", "instance_id",
|
||||
),
|
||||
resource.TestCheckResourceAttr("stackit_observability_credential.credential", "description", testutil.ConvertConfigVariable(testConfigVarsMax["credential_description"])),
|
||||
resource.TestCheckResourceAttrSet("stackit_observability_credential.credential", "username"),
|
||||
resource.TestCheckResourceAttrSet("stackit_observability_credential.credential", "password"),
|
||||
|
||||
|
|
|
|||
|
|
@ -47,6 +47,8 @@ variable "match" {}
|
|||
variable "match_regex" {}
|
||||
variable "matchers" {}
|
||||
|
||||
variable "credential_description" {}
|
||||
|
||||
variable "logalertgroup_name" {}
|
||||
variable "logalertgroup_alert" {}
|
||||
variable "logalertgroup_expression" {}
|
||||
|
|
@ -91,6 +93,7 @@ resource "stackit_observability_alertgroup" "alertgroup" {
|
|||
resource "stackit_observability_credential" "credential" {
|
||||
project_id = var.project_id
|
||||
instance_id = stackit_observability_instance.instance.instance_id
|
||||
description = var.credential_description
|
||||
}
|
||||
|
||||
resource "stackit_observability_instance" "instance" {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue