Skip to content
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

Cloud Stack: Add profiles information #1341

Merged
merged 1 commit into from
Feb 9, 2024
Merged
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
4 changes: 4 additions & 0 deletions docs/data-sources/cloud_stack.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ available at “https://<stack_slug>.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
Expand Down
4 changes: 4 additions & 0 deletions docs/resources/cloud_stack.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ available at “https://<stack_slug>.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
Expand Down
24 changes: 24 additions & 0 deletions internal/common/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}
172 changes: 45 additions & 127 deletions internal/resources/cloud/resource_cloud_stack.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,135 +101,48 @@ available at “https://<stack_slug>.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 {
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions internal/resources/cloud/resource_cloud_stack_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
Loading