diff --git a/docs/data-sources/cloud_stack.md b/docs/data-sources/cloud_stack.md index a96505d16..57c768b10 100644 --- a/docs/data-sources/cloud_stack.md +++ b/docs/data-sources/cloud_stack.md @@ -53,6 +53,10 @@ available at “https://.grafana.net". - `org_id` (Number) Organization id to assign to this stack. - `org_name` (String) Organization name to assign to this stack. - `org_slug` (String) Organization slug to assign to this stack. +- `profiles_name` (String) +- `profiles_status` (String) +- `profiles_url` (String) +- `profiles_user_id` (Number) - `prometheus_name` (String) Prometheus name for this instance. - `prometheus_remote_endpoint` (String) Use this URL to query hosted metrics data e.g. Prometheus data source in Grafana - `prometheus_remote_write_endpoint` (String) Use this URL to send prometheus metrics to Grafana cloud diff --git a/docs/resources/cloud_stack.md b/docs/resources/cloud_stack.md index 84f96c5ca..daa1832d9 100644 --- a/docs/resources/cloud_stack.md +++ b/docs/resources/cloud_stack.md @@ -56,6 +56,10 @@ available at “https://.grafana.net". - `org_id` (Number) Organization id to assign to this stack. - `org_name` (String) Organization name to assign to this stack. - `org_slug` (String) Organization slug to assign to this stack. +- `profiles_name` (String) +- `profiles_status` (String) +- `profiles_url` (String) +- `profiles_user_id` (Number) - `prometheus_name` (String) Prometheus name for this instance. - `prometheus_remote_endpoint` (String) Use this URL to query hosted metrics data e.g. Prometheus data source in Grafana - `prometheus_remote_write_endpoint` (String) Use this URL to send prometheus metrics to Grafana cloud diff --git a/internal/common/schema.go b/internal/common/schema.go index c6db54d03..747f903b2 100644 --- a/internal/common/schema.go +++ b/internal/common/schema.go @@ -74,3 +74,27 @@ func ValidateDurationWithDays(i interface{}, p cty.Path) diag.Diagnostics { } return nil } + +func ComputedInt() *schema.Schema { + return computedWithDescription(schema.TypeInt, "") +} + +func ComputedIntWithDescription(description string) *schema.Schema { + return computedWithDescription(schema.TypeInt, description) +} + +func ComputedString() *schema.Schema { + return computedWithDescription(schema.TypeString, "") +} + +func ComputedStringWithDescription(description string) *schema.Schema { + return computedWithDescription(schema.TypeString, description) +} + +func computedWithDescription(t schema.ValueType, description string) *schema.Schema { + return &schema.Schema{ + Type: t, + Computed: true, + Description: description, + } +} diff --git a/internal/resources/cloud/resource_cloud_stack.go b/internal/resources/cloud/resource_cloud_stack.go index 924d048ac..e1dfd5080 100644 --- a/internal/resources/cloud/resource_cloud_stack.go +++ b/internal/resources/cloud/resource_cloud_stack.go @@ -101,135 +101,48 @@ available at “https://.grafana.net".`, }, Description: "How long to wait for readiness (if enabled).", }, - "org_id": { - Type: schema.TypeInt, - Computed: true, - Description: "Organization id to assign to this stack.", - }, - "org_slug": { - Type: schema.TypeString, - Computed: true, - Description: "Organization slug to assign to this stack.", - }, - "org_name": { - Type: schema.TypeString, - Computed: true, - Description: "Organization name to assign to this stack.", - }, - "status": { - Type: schema.TypeString, - Computed: true, - Description: "Status of the stack.", - }, - - // Hosted Metrics - "prometheus_user_id": { - Type: schema.TypeInt, - Computed: true, - Description: "Prometheus user ID. Used for e.g. remote_write.", - }, - "prometheus_url": { - Type: schema.TypeString, - Computed: true, - Description: "Prometheus url for this instance.", - }, - "prometheus_name": { - Type: schema.TypeString, - Computed: true, - Description: "Prometheus name for this instance.", - }, - "prometheus_remote_endpoint": { - Type: schema.TypeString, - Computed: true, - Description: "Use this URL to query hosted metrics data e.g. Prometheus data source in Grafana", - }, - "prometheus_remote_write_endpoint": { - Type: schema.TypeString, - Computed: true, - Description: "Use this URL to send prometheus metrics to Grafana cloud", - }, - "prometheus_status": { - Type: schema.TypeString, - Computed: true, - Description: "Prometheus status for this instance.", - }, - - // Alerting - "alertmanager_user_id": { - Type: schema.TypeInt, - Computed: true, - Description: "User ID of the Alertmanager instance configured for this stack.", - }, - "alertmanager_name": { - Type: schema.TypeString, - Computed: true, - Description: "Name of the Alertmanager instance configured for this stack.", - }, - "alertmanager_url": { - Type: schema.TypeString, - Computed: true, - Description: "Base URL of the Alertmanager instance configured for this stack.", - }, - "alertmanager_status": { - Type: schema.TypeString, - Computed: true, - Description: "Status of the Alertmanager instance configured for this stack.", - }, - - // Hosted Logs - "logs_user_id": { - Type: schema.TypeInt, - Computed: true, - }, - "logs_name": { - Type: schema.TypeString, - Computed: true, - }, - "logs_url": { - Type: schema.TypeString, - Computed: true, - }, - "logs_status": { - Type: schema.TypeString, - Computed: true, - }, - - // Traces - "traces_user_id": { - Type: schema.TypeInt, - Computed: true, - }, - "traces_name": { - Type: schema.TypeString, - Computed: true, - }, - "traces_url": { - Type: schema.TypeString, - Computed: true, - Description: "Base URL of the Traces instance configured for this stack. To use this in the Tempo data source in Grafana, append `/tempo` to the URL.", - }, - "traces_status": { - Type: schema.TypeString, - Computed: true, - }, + "org_id": common.ComputedIntWithDescription("Organization id to assign to this stack."), + "org_slug": common.ComputedStringWithDescription("Organization slug to assign to this stack."), + "org_name": common.ComputedStringWithDescription("Organization name to assign to this stack."), + "status": common.ComputedStringWithDescription("Status of the stack."), + + // Metrics (Mimir/Prometheus) + "prometheus_user_id": common.ComputedIntWithDescription("Prometheus user ID. Used for e.g. remote_write."), + "prometheus_url": common.ComputedStringWithDescription("Prometheus url for this instance."), + "prometheus_name": common.ComputedStringWithDescription("Prometheus name for this instance."), + "prometheus_remote_endpoint": common.ComputedStringWithDescription("Use this URL to query hosted metrics data e.g. Prometheus data source in Grafana"), + "prometheus_remote_write_endpoint": common.ComputedStringWithDescription("Use this URL to send prometheus metrics to Grafana cloud"), + "prometheus_status": common.ComputedStringWithDescription("Prometheus status for this instance."), + + // Alertmanager + "alertmanager_user_id": common.ComputedIntWithDescription("User ID of the Alertmanager instance configured for this stack."), + "alertmanager_name": common.ComputedStringWithDescription("Name of the Alertmanager instance configured for this stack."), + "alertmanager_url": common.ComputedStringWithDescription("Base URL of the Alertmanager instance configured for this stack."), + "alertmanager_status": common.ComputedStringWithDescription("Status of the Alertmanager instance configured for this stack."), + + // Logs (Loki) + "logs_user_id": common.ComputedInt(), + "logs_name": common.ComputedString(), + "logs_url": common.ComputedString(), + "logs_status": common.ComputedString(), + + // Traces (Tempo) + "traces_user_id": common.ComputedInt(), + "traces_name": common.ComputedString(), + "traces_url": common.ComputedStringWithDescription("Base URL of the Traces instance configured for this stack. To use this in the Tempo data source in Grafana, append `/tempo` to the URL."), + "traces_status": common.ComputedString(), + + // Profiles (Pyroscope) + "profiles_user_id": common.ComputedInt(), + "profiles_name": common.ComputedString(), + "profiles_url": common.ComputedString(), + "profiles_status": common.ComputedString(), // Graphite - "graphite_user_id": { - Type: schema.TypeInt, - Computed: true, - }, - "graphite_name": { - Type: schema.TypeString, - Computed: true, - }, - "graphite_url": { - Type: schema.TypeString, - Computed: true, - }, - "graphite_status": { - Type: schema.TypeString, - Computed: true, - }, + "graphite_user_id": common.ComputedInt(), + "graphite_name": common.ComputedString(), + "graphite_url": common.ComputedString(), + "graphite_status": common.ComputedString(), }, CustomizeDiff: customdiff.All( customdiff.ComputedIf("url", func(_ context.Context, diff *schema.ResourceDiff, meta interface{}) bool { @@ -404,6 +317,11 @@ func FlattenStack(d *schema.ResourceData, stack *gcom.FormattedApiInstance) erro d.Set("traces_url", stack.HtInstanceUrl) d.Set("traces_status", stack.HtInstanceStatus) + d.Set("profiles_user_id", stack.HpInstanceId) + d.Set("profiles_name", stack.HpInstanceName) + d.Set("profiles_url", stack.HpInstanceUrl) + d.Set("profiles_status", stack.HpInstanceStatus) + d.Set("graphite_user_id", stack.HmInstanceGraphiteId) d.Set("graphite_name", stack.HmInstanceGraphiteName) d.Set("graphite_url", stack.HmInstanceGraphiteUrl) diff --git a/internal/resources/cloud/resource_cloud_stack_test.go b/internal/resources/cloud/resource_cloud_stack_test.go index 5a3b2e8d7..5e3f28929 100644 --- a/internal/resources/cloud/resource_cloud_stack_test.go +++ b/internal/resources/cloud/resource_cloud_stack_test.go @@ -41,6 +41,10 @@ func TestResourceStack_Basic(t *testing.T) { resource.TestCheckResourceAttrSet("grafana_cloud_stack.test", "logs_user_id"), resource.TestCheckResourceAttrSet("grafana_cloud_stack.test", "traces_user_id"), resource.TestCheckResourceAttrSet("grafana_cloud_stack.test", "graphite_user_id"), + resource.TestCheckResourceAttrSet("grafana_cloud_stack.test", "profiles_user_id"), + resource.TestCheckResourceAttrSet("grafana_cloud_stack.test", "profiles_name"), + resource.TestCheckResourceAttrSet("grafana_cloud_stack.test", "profiles_url"), + resource.TestCheckResourceAttrSet("grafana_cloud_stack.test", "profiles_status"), ) resource.ParallelTest(t, resource.TestCase{