-
Notifications
You must be signed in to change notification settings - Fork 47
feat(logs) onboard logs service #1096
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
cgoetz-inovex
wants to merge
8
commits into
main
Choose a base branch
from
feat/STACKITTPR-448-logs-instance-datasource
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
6859226
feat(logs) onboard logs service
cgoetz-inovex 89e5e87
fix(logs) generate docs
cgoetz-inovex d25578e
fix(logs) update logs dependency to version with waiters
cgoetz-inovex 71751ad
fix(logs) linting errors
cgoetz-inovex b75ec60
Merge branch 'main' into feat/STACKITTPR-448-logs-instance-datasource
cgoetz-inovex 849bd4a
fix(logs) review issues
cgoetz-inovex b8cc6bc
Merge remote-tracking branch 'origin/main' into feat/STACKITTPR-448-l…
cgoetz-inovex 433019e
fix(logs) generate docs
cgoetz-inovex File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 data source 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 data source 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) The access control list entries for the Logs instance | ||
| - `created` (String) The date and time the creation of the Logs instance was initiated | ||
| - `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, possible values: Possible values are: `active`, `deleting`, `reconciling`. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) The access control list 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) The date and time the creation of the Logs instance was initiated | ||
| - `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, possible values: Possible values are: `active`, `deleting`, `reconciling`. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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" | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| resource "stackit_logs_instance" "logs" { | ||
| project_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" | ||
| region = "eu01" | ||
| display_name = "logs-instance-example" | ||
| retention_days = 30 | ||
| } | ||
|
|
||
| resource "stackit_logs_instance" "logs2" { | ||
| 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 logs instance | ||
| import { | ||
| to = stackit_logs_instance.import-example | ||
| id = "${var.project_id},${var.region},${var.logs_instance_id}" | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,179 @@ | ||||||
| package instance | ||||||
|
|
||||||
| import ( | ||||||
| "context" | ||||||
| "errors" | ||||||
| "fmt" | ||||||
| "net/http" | ||||||
|
|
||||||
| "github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator" | ||||||
| "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 data source schema.", core.Resource), | ||||||
| Description: fmt.Sprintf("Logs instance resource schema. %s", core.DatasourceRegionFallbackDocstring), | ||||||
| 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(), | ||||||
| validate.NoSeparator(), | ||||||
| }, | ||||||
| }, | ||||||
| "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, | ||||||
| Validators: []validator.String{ | ||||||
| validate.UUID(), | ||||||
| validate.NoSeparator(), | ||||||
| }, | ||||||
| }, | ||||||
| "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{ | ||||||
GokceGK marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
| Description: schemaDescriptions["display_name"], | ||||||
| Computed: true, | ||||||
| Validators: []validator.String{stringvalidator.LengthAtLeast(1)}, | ||||||
| }, | ||||||
| "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{ | ||||||
GokceGK marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
| 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 | ||||||
| } | ||||||
| ctx = core.LogResponse(ctx) | ||||||
|
|
||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| 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", map[string]interface{}{ | ||||||
| "instance_id": instanceID, | ||||||
| }) | ||||||
| } | ||||||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.