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
43 changes: 43 additions & 0 deletions docs/data-sources/logs_instance.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "stackit_logs_instance Data Source - stackit"
subcategory: ""
description: |-
Logs instance resource schema.
~> This resource is in beta and may be subject to breaking changes in the future. Use with caution. See our guide https://registry.terraform.io/providers/stackitcloud/stackit/latest/docs/guides/opting_into_beta_resources for how to opt-in to use beta resources.
---

# stackit_logs_instance (Data Source)

Logs instance resource schema.

~> This resource is in beta and may be subject to breaking changes in the future. Use with caution. See our [guide](https://registry.terraform.io/providers/stackitcloud/stackit/latest/docs/guides/opting_into_beta_resources) for how to opt-in to use beta resources.



<!-- schema generated by tfplugindocs -->
## Schema

### Required

- `instance_id` (String) The Logs instance ID
- `project_id` (String) STACKIT project ID associated with the logs instance

### Optional

- `region` (String) STACKIT region name the resource is located in. If not defined, the provider region is used.

### Read-Only

- `acl` (List of String) ACL entries for the logs instance
- `created` (String) Time when the distribution was created
- `datasource_url` (String) Logs instance datasource URL, can be used in Grafana as datasource URL
- `description` (String) The description of the Logs instance
- `display_name` (String) The displayed name of the Logs instance
- `id` (String) Terraform's internal resource identifier. It is structured as "`project_id`,`region`,`instance_id`".
- `ingest_otlp_url` (String) The Logs instance's ingest logs via OTLP URL
- `ingest_url` (String) The logs instance's ingest logs URL
- `query_range_url` (String) The Logs instance's query range URL
- `query_url` (String) The Logs instance's query URL
- `retention_days` (Number) The log retention time in days
- `status` (String) The status of the Logs instance
1 change: 1 addition & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ Note: AWS specific checks must be skipped as they do not work on STACKIT. For de
- `kms_custom_endpoint` (String) Custom endpoint for the KMS service
- `loadbalancer_custom_endpoint` (String) Custom endpoint for the Load Balancer service
- `logme_custom_endpoint` (String) Custom endpoint for the LogMe service
- `logs_custom_endpoint` (String) Custom endpoint for the Logs service
- `mariadb_custom_endpoint` (String) Custom endpoint for the MariaDB service
- `modelserving_custom_endpoint` (String) Custom endpoint for the AI Model Serving service
- `mongodbflex_custom_endpoint` (String) Custom endpoint for the MongoDB Flex service
Expand Down
43 changes: 43 additions & 0 deletions docs/resources/logs_instance.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "stackit_logs_instance Resource - stackit"
subcategory: ""
description: |-
Logs instance resource schema.
~> This resource is in beta and may be subject to breaking changes in the future. Use with caution. See our guide https://registry.terraform.io/providers/stackitcloud/stackit/latest/docs/guides/opting_into_beta_resources for how to opt-in to use beta resources.
---

# stackit_logs_instance (Resource)

Logs instance resource schema.

~> This resource is in beta and may be subject to breaking changes in the future. Use with caution. See our [guide](https://registry.terraform.io/providers/stackitcloud/stackit/latest/docs/guides/opting_into_beta_resources) for how to opt-in to use beta resources.



<!-- schema generated by tfplugindocs -->
## Schema

### Required

- `display_name` (String) The displayed name of the Logs instance
- `project_id` (String) STACKIT project ID associated with the logs instance
- `retention_days` (Number) The log retention time in days

### Optional

- `acl` (List of String) ACL entries for the logs instance
- `description` (String) The description of the Logs instance
- `region` (String) STACKIT region name the resource is located in. If not defined, the provider region is used.

### Read-Only

- `created` (String) Time when the distribution was created
- `datasource_url` (String) Logs instance datasource URL, can be used in Grafana as datasource URL
- `id` (String) Terraform's internal resource identifier. It is structured as "`project_id`,`region`,`instance_id`".
- `ingest_otlp_url` (String) The Logs instance's ingest logs via OTLP URL
- `ingest_url` (String) The logs instance's ingest logs URL
- `instance_id` (String) The Logs instance ID
- `query_range_url` (String) The Logs instance's query range URL
- `query_url` (String) The Logs instance's query URL
- `status` (String) The status of the Logs instance
5 changes: 5 additions & 0 deletions examples/data-sources/stackit_logs/data-source.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
data "stackit_logs_instance" "logs" {
project_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
region = "eu01"
instance_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
}
23 changes: 23 additions & 0 deletions examples/resources/stackit_logs/resource.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
resource "stackit_logs_instance" "git" {
project_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
region = "eu01"
display_name = "logs-instance-example"
retention_days = 30
}

resource "stackit_logs_instance" "logs" {
project_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
region = "eu01"
display_name = "logs-instance-example"
retention_days = 30
acl = [
"0.0.0.0/0"
]
description = "Example description"
}

# Only use the import statement, if you want to import an existing git resource
import {
to = stackit_logs_instance.import-example
id = "${var.project_id},${var.region},${var.logs_instance_id}"
}
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ require (
github.com/hashicorp/terraform-plugin-go v0.29.0
github.com/hashicorp/terraform-plugin-log v0.10.0
github.com/hashicorp/terraform-plugin-testing v1.14.0
github.com/stackitcloud/stackit-sdk-go/core v0.20.0
github.com/stackitcloud/stackit-sdk-go/core v0.20.1
github.com/stackitcloud/stackit-sdk-go/services/cdn v1.6.0
github.com/stackitcloud/stackit-sdk-go/services/dns v0.17.1
github.com/stackitcloud/stackit-sdk-go/services/git v0.8.0
Expand All @@ -20,6 +20,7 @@ require (
github.com/stackitcloud/stackit-sdk-go/services/kms v1.0.0
github.com/stackitcloud/stackit-sdk-go/services/loadbalancer v1.6.0
github.com/stackitcloud/stackit-sdk-go/services/logme v0.25.1
github.com/stackitcloud/stackit-sdk-go/services/logs v0.3.0
github.com/stackitcloud/stackit-sdk-go/services/mariadb v0.25.1
github.com/stackitcloud/stackit-sdk-go/services/modelserving v0.6.0
github.com/stackitcloud/stackit-sdk-go/services/mongodbflex v1.5.2
Expand Down
6 changes: 4 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,8 @@ github.com/sergi/go-diff v1.3.2-0.20230802210424-5b0b94c5c0d3 h1:n661drycOFuPLCN
github.com/sergi/go-diff v1.3.2-0.20230802210424-5b0b94c5c0d3/go.mod h1:A0bzQcvG0E7Rwjx0REVgAGH58e96+X0MeOfepqsbeW4=
github.com/skeema/knownhosts v1.3.1 h1:X2osQ+RAjK76shCbvhHHHVl3ZlgDm8apHEHFqRjnBY8=
github.com/skeema/knownhosts v1.3.1/go.mod h1:r7KTdC8l4uxWRyK2TpQZ/1o5HaSzh06ePQNxPwTcfiY=
github.com/stackitcloud/stackit-sdk-go/core v0.20.0 h1:4rrUk6uT1g4nOn5/g1uXukP07Tux/o5xbMz/f/qE1rY=
github.com/stackitcloud/stackit-sdk-go/core v0.20.0/go.mod h1:fqto7M82ynGhEnpZU6VkQKYWYoFG5goC076JWXTUPRQ=
github.com/stackitcloud/stackit-sdk-go/core v0.20.1 h1:odiuhhRXmxvEvnVTeZSN9u98edvw2Cd3DcnkepncP3M=
github.com/stackitcloud/stackit-sdk-go/core v0.20.1/go.mod h1:fqto7M82ynGhEnpZU6VkQKYWYoFG5goC076JWXTUPRQ=
github.com/stackitcloud/stackit-sdk-go/services/authorization v0.9.0 h1:7ZKd3b+E/R4TEVShLTXxx5FrsuDuJBOyuVOuKTMa4mo=
github.com/stackitcloud/stackit-sdk-go/services/authorization v0.9.0/go.mod h1:/FoXa6hF77Gv8brrvLBCKa5ie1Xy9xn39yfHwaln9Tw=
github.com/stackitcloud/stackit-sdk-go/services/cdn v1.6.0 h1:Q+qIdejeMsYMkbtVoI9BpGlKGdSVFRBhH/zj44SP8TM=
Expand All @@ -169,6 +169,8 @@ github.com/stackitcloud/stackit-sdk-go/services/loadbalancer v1.6.0 h1:q33ZaCBVE
github.com/stackitcloud/stackit-sdk-go/services/loadbalancer v1.6.0/go.mod h1:20QOZ3rBC9wTGgzXzLz9M6YheX0VaxWE0/JI+s8On7k=
github.com/stackitcloud/stackit-sdk-go/services/logme v0.25.1 h1:hv5WrRU9rN6Jx4OwdOGJRyaQrfA9p1tzEoQK6/CDyoA=
github.com/stackitcloud/stackit-sdk-go/services/logme v0.25.1/go.mod h1:ivt8lvnAoBZsde2jSAuicyn6RgTmHvvNAJ3whaUbAD4=
github.com/stackitcloud/stackit-sdk-go/services/logs v0.3.0 h1:N1gerABK2vH7/PBkxZeaWYJ7dz3rjeCHuto+FAuGx3w=
github.com/stackitcloud/stackit-sdk-go/services/logs v0.3.0/go.mod h1:m4IjH1/RtJOF072kjAB0E/ejoIc++myrKmIahphfO6Q=
github.com/stackitcloud/stackit-sdk-go/services/mariadb v0.25.1 h1:Db/ebOL2vbpIeh5XB2Ews2B9Lj5DJlMWIEJh60FfZ4Y=
github.com/stackitcloud/stackit-sdk-go/services/mariadb v0.25.1/go.mod h1:8jdN4v2euK3f9gfdzbRi8e4nBJ8g/Q5YF9aPB4M4fCQ=
github.com/stackitcloud/stackit-sdk-go/services/modelserving v0.6.0 h1:JZI+3sLVAtTFk4QJ/ao2bAumzBq+iV6dUvDoIrOKTcw=
Expand Down
1 change: 1 addition & 0 deletions stackit/internal/core/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ type ProviderData struct {
KMSCustomEndpoint string
LoadBalancerCustomEndpoint string
LogMeCustomEndpoint string
LogsCustomEndpoint string
MariaDBCustomEndpoint string
MongoDBFlexCustomEndpoint string
ModelServingCustomEndpoint string
Expand Down
167 changes: 167 additions & 0 deletions stackit/internal/services/logs/instance/datasource.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
package instance

import (
"context"
"errors"
"fmt"
"net/http"

"github.com/hashicorp/terraform-plugin-framework/datasource"
"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
"github.com/hashicorp/terraform-plugin-framework/schema/validator"
"github.com/hashicorp/terraform-plugin-framework/types"
"github.com/hashicorp/terraform-plugin-log/tflog"
"github.com/stackitcloud/stackit-sdk-go/core/oapierror"
"github.com/stackitcloud/stackit-sdk-go/services/logs"
"github.com/stackitcloud/terraform-provider-stackit/stackit/internal/conversion"
"github.com/stackitcloud/terraform-provider-stackit/stackit/internal/core"
"github.com/stackitcloud/terraform-provider-stackit/stackit/internal/features"
"github.com/stackitcloud/terraform-provider-stackit/stackit/internal/services/logs/utils"
"github.com/stackitcloud/terraform-provider-stackit/stackit/internal/validate"
)

var (
_ datasource.DataSource = &logsInstanceDataSource{}
)

func NewLogsInstanceDataSource() datasource.DataSource {
return &logsInstanceDataSource{}
}

type logsInstanceDataSource struct {
client *logs.APIClient
}

func (d *logsInstanceDataSource) Metadata(_ context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) {
resp.TypeName = req.ProviderTypeName + "_logs_instance"
}

func (d *logsInstanceDataSource) Configure(ctx context.Context, req datasource.ConfigureRequest, resp *datasource.ConfigureResponse) {
providerData, ok := conversion.ParseProviderData(ctx, req.ProviderData, &resp.Diagnostics)
if !ok {
return
}

apiClient := utils.ConfigureClient(ctx, &providerData, &resp.Diagnostics)
if resp.Diagnostics.HasError() {
return
}
d.client = apiClient
tflog.Info(ctx, "Logs client configured")
}

func (d *logsInstanceDataSource) Schema(_ context.Context, _ datasource.SchemaRequest, resp *datasource.SchemaResponse) {
resp.Schema = schema.Schema{
MarkdownDescription: features.AddBetaDescription("Logs instance resource schema.", core.Resource),
Description: fmt.Sprintf("Logs instance resource schema. %s", core.ResourceRegionFallbackDocstring),
Attributes: map[string]schema.Attribute{
"id": schema.StringAttribute{
Description: schemaDescriptions["id"],
Computed: true,
},
"instance_id": schema.StringAttribute{
Description: schemaDescriptions["instance_id"],
Required: true,
Validators: []validator.String{validate.UUID()},
},
"region": schema.StringAttribute{
Description: schemaDescriptions["region"],
Optional: true,
// must be computed to allow for storing the override value from the provider
Computed: true,
},
"project_id": schema.StringAttribute{
Description: schemaDescriptions["project_id"],
Required: true,
},
"acl": schema.ListAttribute{
Description: schemaDescriptions["acl"],
ElementType: types.StringType,
Computed: true,
},
"created": schema.StringAttribute{
Description: schemaDescriptions["created"],
Computed: true,
},
"datasource_url": schema.StringAttribute{
Description: schemaDescriptions["datasource_url"],
Computed: true,
},
"description": schema.StringAttribute{
Description: schemaDescriptions["description"],
Computed: true,
},
"display_name": schema.StringAttribute{
Description: schemaDescriptions["display_name"],
Computed: true,
},
"ingest_otlp_url": schema.StringAttribute{
Description: schemaDescriptions["ingest_otlp_url"],
Computed: true,
},
"ingest_url": schema.StringAttribute{
Description: schemaDescriptions["ingest_url"],
Computed: true,
},
"query_range_url": schema.StringAttribute{
Description: schemaDescriptions["query_range_url"],
Computed: true,
},
"query_url": schema.StringAttribute{
Description: schemaDescriptions["query_url"],
Computed: true,
},
"retention_days": schema.Int64Attribute{
Description: schemaDescriptions["retention_days"],
Computed: true,
},
"status": schema.StringAttribute{
Description: schemaDescriptions["status"],
Computed: true,
},
},
}
}

func (d *logsInstanceDataSource) 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...)
if resp.Diagnostics.HasError() {
return
}

ctx = core.InitProviderContext(ctx)

projectID := model.ProjectID.ValueString()
region := model.Region.ValueString()
instanceID := model.InstanceID.ValueString()

ctx = tflog.SetField(ctx, "project_id", projectID)
ctx = tflog.SetField(ctx, "region", region)
ctx = tflog.SetField(ctx, "instance_id", instanceID)

instanceResponse, err := d.client.GetLogsInstance(ctx, projectID, region, instanceID).Execute()
if err != nil {
var oapiErr *oapierror.GenericOpenAPIError
ok := errors.As(err, &oapiErr)
if ok && oapiErr.StatusCode == http.StatusNotFound {
resp.State.RemoveResource(ctx)
return
}
core.LogAndAddError(ctx, &resp.Diagnostics, "Error reading logs instance", fmt.Sprintf("Calling API: %v", err))
return
}

err = mapFields(ctx, instanceResponse, &model)
if err != nil {
core.LogAndAddError(ctx, &resp.Diagnostics, "Error reading logs instance", fmt.Sprintf("Processing response: %v", err))
return
}
diags = resp.State.Set(ctx, model)
resp.Diagnostics.Append(diags...)
if resp.Diagnostics.HasError() {
return
}
tflog.Info(ctx, "Logs Instance read")
}
Loading
Loading