Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion docs/data-sources/logme_credential.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,14 @@ data "stackit_logme_credential" "example" {
- `instance_id` (String) ID of the LogMe instance.
- `project_id` (String) STACKIT project ID to which the instance is associated.

### Optional

- `region` (String) The resource region. If not defined, the provider region is used.

### Read-Only

- `host` (String)
- `id` (String) Terraform's internal data source. identifier. It is structured as "`project_id`,`instance_id`,`credential_id`".
- `id` (String) Terraform's internal data source. identifier. It is structured as "`project_id`,`region`,`instance_id`,`credential_id`".
- `password` (String, Sensitive)
- `port` (Number)
- `uri` (String, Sensitive)
Expand Down
6 changes: 5 additions & 1 deletion docs/data-sources/logme_instance.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,17 @@ data "stackit_logme_instance" "example" {
- `instance_id` (String) ID of the LogMe instance.
- `project_id` (String) STACKIT Project ID to which the instance is associated.

### Optional

- `region` (String) The resource region. If not defined, the provider region is used.

### Read-Only

- `cf_guid` (String)
- `cf_organization_guid` (String)
- `cf_space_guid` (String)
- `dashboard_url` (String)
- `id` (String) Terraform's internal data source. identifier. It is structured as "`project_id`,`instance_id`".
- `id` (String) Terraform's internal data source. identifier. It is structured as "`project_id`,`region`,`instance_id`".
- `image_url` (String)
- `name` (String) Instance name.
- `parameters` (Attributes) (see [below for nested schema](#nestedatt--parameters))
Expand Down
8 changes: 6 additions & 2 deletions docs/resources/logme_credential.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,15 @@ resource "stackit_logme_credential" "example" {
- `instance_id` (String) ID of the LogMe instance.
- `project_id` (String) STACKIT Project ID to which the instance is associated.

### Optional

- `region` (String) The resource region. If not defined, the provider region is used.

### Read-Only

- `credential_id` (String) The credential's ID.
- `host` (String)
- `id` (String) Terraform's internal resource identifier. It is structured as "`project_id`,`instance_id`,`credential_id`".
- `id` (String) Terraform's internal resource identifier. It is structured as "`project_id`,`region`,`instance_id`,`credential_id`".
- `password` (String, Sensitive)
- `port` (Number)
- `uri` (String, Sensitive)
Expand All @@ -47,6 +51,6 @@ In Terraform v1.5.0 and later, the [` + "`" + `import` + "`" + ` block](https://
# Only use the import statement, if you want to import an existing logme credential
import {
to = stackit_logme_credential.import-example
id = "${var.project_id},${var.logme_instance_id},${var.logme_credentials_id}"
id = "${var.project_id},${var.region},${var.logme_instance_id},${var.logme_credentials_id}"
}
```
5 changes: 3 additions & 2 deletions docs/resources/logme_instance.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,15 @@ resource "stackit_logme_instance" "example" {
### Optional

- `parameters` (Attributes) Configuration parameters. Please note that removing a previously configured field from your Terraform configuration won't replace its value in the API. To update a previously configured field, explicitly set a new value for it. (see [below for nested schema](#nestedatt--parameters))
- `region` (String) The resource region. If not defined, the provider region is used.

### Read-Only

- `cf_guid` (String)
- `cf_organization_guid` (String)
- `cf_space_guid` (String)
- `dashboard_url` (String)
- `id` (String) Terraform's internal resource ID. It is structured as "`project_id`,`instance_id`".
- `id` (String) Terraform's internal resource ID. It is structured as "`project_id`,`region`,`instance_id`".
- `image_url` (String)
- `instance_id` (String) ID of the LogMe instance.
- `plan_id` (String) The selected plan ID.
Expand Down Expand Up @@ -87,6 +88,6 @@ In Terraform v1.5.0 and later, the [` + "`" + `import` + "`" + ` block](https://
# Only use the import statement, if you want to import an existing logme instance
import {
to = stackit_logme_instance.import-example
id = "${var.project_id},${var.logme_instance_id}"
id = "${var.project_id},${var.region},${var.logme_instance_id}"
}
```
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Only use the import statement, if you want to import an existing logme credential
import {
to = stackit_logme_credential.import-example
id = "${var.project_id},${var.logme_instance_id},${var.logme_credentials_id}"
id = "${var.project_id},${var.region},${var.logme_instance_id},${var.logme_credentials_id}"
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Only use the import statement, if you want to import an existing logme instance
import {
to = stackit_logme_instance.import-example
id = "${var.project_id},${var.logme_instance_id}"
id = "${var.project_id},${var.region},${var.logme_instance_id}"
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ require (
github.com/stackitcloud/stackit-sdk-go/services/intake v0.11.0
github.com/stackitcloud/stackit-sdk-go/services/kms v1.12.0
github.com/stackitcloud/stackit-sdk-go/services/loadbalancer v1.15.0
github.com/stackitcloud/stackit-sdk-go/services/logme v1.0.1
github.com/stackitcloud/stackit-sdk-go/services/logme v1.1.0
github.com/stackitcloud/stackit-sdk-go/services/logs v0.10.0
github.com/stackitcloud/stackit-sdk-go/services/mariadb v1.0.1
github.com/stackitcloud/stackit-sdk-go/services/modelserving v0.11.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -696,8 +696,8 @@ github.com/stackitcloud/stackit-sdk-go/services/kms v1.12.0 h1:rydjdSL+j6Yd+3T7k
github.com/stackitcloud/stackit-sdk-go/services/kms v1.12.0/go.mod h1:pVaCmb1ZHAPGVRlSlBlVOjThp9Tb2sX9+nRX0M+d1KU=
github.com/stackitcloud/stackit-sdk-go/services/loadbalancer v1.15.0 h1:YWpy3VDKrTKVgvnHgbLFYRZ4qUKiNxzCejUNdWIYZ6Q=
github.com/stackitcloud/stackit-sdk-go/services/loadbalancer v1.15.0/go.mod h1:+Ld3dn648I+YKcBV3fEkYpDSr3fel421+LurJGywSBs=
github.com/stackitcloud/stackit-sdk-go/services/logme v1.0.1 h1:iteL61eMMPWT6872nF4Ko/tBU1IXemvS++XR09pj6NA=
github.com/stackitcloud/stackit-sdk-go/services/logme v1.0.1/go.mod h1:JDOOYaGgcBts2x52nKPRMFgSZe7qqOFmfz1xIXCQgRY=
github.com/stackitcloud/stackit-sdk-go/services/logme v1.1.0 h1:r+MzTC/qI8t4zTB029bp75iLzsx1/F4LzTiZeIwM5Vg=
github.com/stackitcloud/stackit-sdk-go/services/logme v1.1.0/go.mod h1:JDOOYaGgcBts2x52nKPRMFgSZe7qqOFmfz1xIXCQgRY=
github.com/stackitcloud/stackit-sdk-go/services/logs v0.10.0 h1:g7zpfQFFq3UhAWrMK9rPaZY6dLMAuMJf5g6+r7VRTXc=
github.com/stackitcloud/stackit-sdk-go/services/logs v0.10.0/go.mod h1:tvRejL8w5KpGBbLFPQ+dXOJURgZ3OMbZmwxlKQrGMuA=
github.com/stackitcloud/stackit-sdk-go/services/mariadb v1.0.1 h1:Ll1erKKms7OnFva3bRXOs9PEYLoWJp5prSg985K0glk=
Expand Down
35 changes: 23 additions & 12 deletions stackit/internal/services/logme/credential/datasource.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
"github.com/stackitcloud/terraform-provider-stackit/stackit/internal/validate"

"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
logmeSdk "github.com/stackitcloud/stackit-sdk-go/services/logme/v1api"
logmeSdk "github.com/stackitcloud/stackit-sdk-go/services/logme/v2api"
)

// Ensure the implementation satisfies the expected interfaces.
Expand All @@ -32,37 +32,40 @@ func NewCredentialDataSource() datasource.DataSource {

// credentialDataSource is the data source implementation.
type credentialDataSource struct {
client *logmeSdk.APIClient
client *logmeSdk.APIClient
providerData core.ProviderData
}

// Metadata returns the data source type name.
func (r *credentialDataSource) Metadata(_ context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) {
func (d *credentialDataSource) Metadata(_ context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) {
resp.TypeName = req.ProviderTypeName + "_logme_credential"
}

// Configure adds the provider configured client to the data source.
func (r *credentialDataSource) Configure(ctx context.Context, req datasource.ConfigureRequest, resp *datasource.ConfigureResponse) {
providerData, ok := conversion.ParseProviderData(ctx, req.ProviderData, &resp.Diagnostics)
func (d *credentialDataSource) Configure(ctx context.Context, req datasource.ConfigureRequest, resp *datasource.ConfigureResponse) {
var ok bool
d.providerData, ok = conversion.ParseProviderData(ctx, req.ProviderData, &resp.Diagnostics)
if !ok {
return
}

apiClient := logmeUtils.ConfigureClient(ctx, &providerData, &resp.Diagnostics)
apiClient := logmeUtils.ConfigureClient(ctx, &d.providerData, &resp.Diagnostics)
if resp.Diagnostics.HasError() {
return
}
r.client = apiClient
d.client = apiClient
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) {
func (d *credentialDataSource) Schema(_ context.Context, _ datasource.SchemaRequest, resp *datasource.SchemaResponse) {
descriptions := map[string]string{ //nolint:gosec // description for credential id
"main": "LogMe credential data source schema. Must have a `region` specified in the provider configuration.",
"id": "Terraform's internal data source. identifier. It is structured as \"`project_id`,`instance_id`,`credential_id`\".",
"id": "Terraform's internal data source. identifier. It is structured as \"`project_id`,`region`,`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.",
"region": "The resource region. If not defined, the provider region is used.",
}

resp.Schema = schema.Schema{
Expand Down Expand Up @@ -113,12 +116,18 @@ func (r *credentialDataSource) Schema(_ context.Context, _ datasource.SchemaRequ
"username": schema.StringAttribute{
Computed: true,
},
"region": schema.StringAttribute{
Optional: true,
// must be computed to allow for storing the override value from the provider
Computed: true,
Description: descriptions["region"],
},
},
}
}

// Read refreshes the Terraform state with the latest data.
func (r *credentialDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) { // nolint:gocritic // function signature required by Terraform
func (d *credentialDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) { // nolint:gocritic // function signature required by Terraform
var model Model
diags := req.Config.Get(ctx, &model)
resp.Diagnostics.Append(diags...)
Expand All @@ -129,13 +138,15 @@ func (r *credentialDataSource) Read(ctx context.Context, req datasource.ReadRequ
ctx = core.InitProviderContext(ctx)

projectId := model.ProjectId.ValueString()
region := d.providerData.GetRegionWithOverride(model.Region)
instanceId := model.InstanceId.ValueString()
credentialId := model.CredentialId.ValueString()
ctx = tflog.SetField(ctx, "project_id", projectId)
ctx = tflog.SetField(ctx, "region", region)
ctx = tflog.SetField(ctx, "instance_id", instanceId)
ctx = tflog.SetField(ctx, "credential_id", credentialId)

recordSetResp, err := r.client.DefaultAPI.GetCredentials(ctx, projectId, instanceId, credentialId).Execute()
recordSetResp, err := d.client.DefaultAPI.GetCredentials(ctx, projectId, region, instanceId, credentialId).Execute()
if err != nil {
utils.LogError(
ctx,
Expand All @@ -154,7 +165,7 @@ func (r *credentialDataSource) Read(ctx context.Context, req datasource.ReadRequ
ctx = core.LogResponse(ctx)

// Map response body to schema
err = mapFields(recordSetResp, &model)
err = mapFields(recordSetResp, &model, region)
if err != nil {
core.LogAndAddError(ctx, &resp.Diagnostics, "Error reading credential", fmt.Sprintf("Processing API payload: %v", err))
return
Expand Down
Loading
Loading