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

[CLOUDGA-22303] Add support for integration type PROMETHEUS #130

Merged
merged 3 commits into from
Nov 22, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
9 changes: 9 additions & 0 deletions docs/resources/integration.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ resource "ybm_integration" "sumologic" {
- `datadog_spec` (Attributes) The specifications of a Datadog integration. (see [below for nested schema](#nestedatt--datadog_spec))
- `googlecloud_spec` (Attributes) The specifications of a Google Cloud integration. (see [below for nested schema](#nestedatt--googlecloud_spec))
- `grafana_spec` (Attributes) The specifications of a Grafana integration. (see [below for nested schema](#nestedatt--grafana_spec))
- `prometheus_spec` (Attributes) The specifications of a Prometheus integration. (see [below for nested schema](#nestedatt--prometheus_spec))
- `sumologic_spec` (Attributes) The specifications of a Sumo Logic integration. (see [below for nested schema](#nestedatt--sumologic_spec))

### Read-Only
Expand Down Expand Up @@ -116,6 +117,14 @@ Required:
- `zone` (String) Grafana Zone.


<a id="nestedatt--prometheus_spec"></a>
### Nested Schema for `prometheus_spec`

Required:

- `endpoint` (String) Prometheus OTLP endpoint URL
bhupendray-yb marked this conversation as resolved.
Show resolved Hide resolved


<a id="nestedatt--sumologic_spec"></a>
### Nested Schema for `sumologic_spec`

Expand Down
5 changes: 5 additions & 0 deletions managed/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,10 @@ type DataDogSpec struct {
ApiKey types.String `tfsdk:"api_key"`
}

type PrometheusSpec struct {
Endpoint types.String `tfsdk:"endpoint"`
}

type GrafanaSpec struct {
AccessTokenPolicy types.String `tfsdk:"access_policy_token"`
Zone types.String `tfsdk:"zone"`
Expand Down Expand Up @@ -354,6 +358,7 @@ type TelemetryProvider struct {
ConfigName types.String `tfsdk:"config_name"`
Type types.String `tfsdk:"type"`
DataDogSpec *DataDogSpec `tfsdk:"datadog_spec"`
PrometheusSpec *PrometheusSpec `tfsdk:"prometheus_spec"`
GrafanaSpec *GrafanaSpec `tfsdk:"grafana_spec"`
SumoLogicSpec *SumoLogicSpec `tfsdk:"sumologic_spec"`
GoogleCloudSpec *GCPServiceAccount `tfsdk:"googlecloud_spec"`
Expand Down
32 changes: 30 additions & 2 deletions managed/resource_integration.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func (r resourceIntegrationType) getSchemaAttributes() map[string]tfsdk.Attribut
Description: "Defines different exporter destination types.",
Type: types.StringType,
Required: true,
Validators: []tfsdk.AttributeValidator{stringvalidator.OneOf("DATADOG", "GRAFANA", "SUMOLOGIC", "GOOGLECLOUD")},
Validators: []tfsdk.AttributeValidator{stringvalidator.OneOf("DATADOG", "GRAFANA", "SUMOLOGIC", "GOOGLECLOUD", "PROMETHEUS")},
},
"is_valid": {
Description: "Signifies whether the integration configuration is valid or not",
Expand All @@ -80,6 +80,18 @@ func (r resourceIntegrationType) getSchemaAttributes() map[string]tfsdk.Attribut
},
}),
},
"prometheus_spec": {
Description: "The specifications of a Prometheus integration.",
Optional: true,
Validators: onlyContainsPath("prometheus_spec"),
Attributes: tfsdk.SingleNestedAttributes(map[string]tfsdk.Attribute{
"endpoint": {
Description: "Prometheus OTLP endpoint URL",
bhupendray-yb marked this conversation as resolved.
Show resolved Hide resolved
Type: types.StringType,
Required: true,
},
}),
},
"grafana_spec": {
Description: "The specifications of a Grafana integration.",
Optional: true,
Expand Down Expand Up @@ -200,7 +212,7 @@ func (r resourceIntegrationType) getSchemaAttributes() map[string]tfsdk.Attribut
}

func onlyContainsPath(requiredPath string) []tfsdk.AttributeValidator {
allPaths := []string{"datadog_spec", "grafana_spec", "sumologic_spec", "googlecloud_spec"}
allPaths := []string{"datadog_spec", "grafana_spec", "sumologic_spec", "googlecloud_spec", "prometheus_spec"}
var validators []tfsdk.AttributeValidator

for _, specPath := range allPaths {
Expand All @@ -227,6 +239,7 @@ func getIntegrationPlan(ctx context.Context, plan tfsdk.Plan, tp *TelemetryProvi
diags.Append(plan.GetAttribute(ctx, path.Root("config_name"), &tp.ConfigName)...)
diags.Append(plan.GetAttribute(ctx, path.Root("type"), &tp.Type)...)
diags.Append(plan.GetAttribute(ctx, path.Root("datadog_spec"), &tp.DataDogSpec)...)
diags.Append(plan.GetAttribute(ctx, path.Root("prometheus_spec"), &tp.PrometheusSpec)...)
diags.Append(plan.GetAttribute(ctx, path.Root("grafana_spec"), &tp.GrafanaSpec)...)
diags.Append(plan.GetAttribute(ctx, path.Root("sumologic_spec"), &tp.SumoLogicSpec)...)
diags.Append(plan.GetAttribute(ctx, path.Root("googlecloud_spec"), &tp.GoogleCloudSpec)...)
Expand All @@ -241,6 +254,8 @@ func getIDsFromIntegrationState(ctx context.Context, state tfsdk.State, tp *Tele
switch tp.Type.Value {
case string(openapiclient.TELEMETRYPROVIDERTYPEENUM_DATADOG):
state.GetAttribute(ctx, path.Root("datadog_spec"), &tp.DataDogSpec)
case string(openapiclient.TELEMETRYPROVIDERTYPEENUM_PROMETHEUS):
state.GetAttribute(ctx, path.Root("prometheus_spec"), &tp.PrometheusSpec)
case string(openapiclient.TELEMETRYPROVIDERTYPEENUM_GRAFANA):
state.GetAttribute(ctx, path.Root("grafana_spec"), &tp.GrafanaSpec)
case string(openapiclient.TELEMETRYPROVIDERTYPEENUM_SUMOLOGIC):
Expand Down Expand Up @@ -306,6 +321,15 @@ func (r resourceIntegration) Create(ctx context.Context, req tfsdk.CreateResourc
return
}
telemetryProviderSpec.SetDatadogSpec(*openapiclient.NewDatadogTelemetryProviderSpec(plan.DataDogSpec.ApiKey.Value, plan.DataDogSpec.Site.Value))
case openapiclient.TELEMETRYPROVIDERTYPEENUM_PROMETHEUS:
if plan.PrometheusSpec == nil {
resp.Diagnostics.AddError(
"prometheus_spec is required for type PROMETHEUS",
"prometheus_spec is required when telemetry sink is PROMETHEUS. Please include this field in the resource",
)
return
}
telemetryProviderSpec.SetPrometheusSpec(*openapiclient.NewPrometheusTelemetryProviderSpec(plan.PrometheusSpec.Endpoint.Value))
case openapiclient.TELEMETRYPROVIDERTYPEENUM_GRAFANA:
if plan.GrafanaSpec == nil {
resp.Diagnostics.AddError(
Expand Down Expand Up @@ -432,6 +456,10 @@ func resourceTelemetryProviderRead(accountId string, projectId string, configID
ApiKey: userProvidedTpDetails.DataDogSpec.ApiKey,
Site: types.String{Value: configSpec.DatadogSpec.Get().Site},
}
case openapiclient.TELEMETRYPROVIDERTYPEENUM_PROMETHEUS:
tp.PrometheusSpec = &PrometheusSpec{
Endpoint: types.String{Value: userProvidedTpDetails.PrometheusSpec.Endpoint.Value},
}
case openapiclient.TELEMETRYPROVIDERTYPEENUM_GRAFANA:
grafanaSpec := configSpec.GetGrafanaSpec()
tp.GrafanaSpec = &GrafanaSpec{
Expand Down
Loading