Skip to content

Commit

Permalink
revert one file
Browse files Browse the repository at this point in the history
  • Loading branch information
eleijonmarck committed Sep 17, 2024
1 parent df849f1 commit 0f7d8a6
Showing 1 changed file with 15 additions and 52 deletions.
67 changes: 15 additions & 52 deletions internal/resources/grafana/resource_alerting_message_template.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,29 +7,28 @@ import (
"time"

"github.com/go-openapi/runtime"
goapi "github.com/grafana/grafana-openapi-client-go/client"
"github.com/grafana/grafana-openapi-client-go/client/provisioning"
"github.com/grafana/grafana-openapi-client-go/models"
"github.com/grafana/terraform-provider-grafana/v3/internal/common"
"github.com/grafana/terraform-provider-grafana/internal/common"

Check failure on line 12 in internal/resources/grafana/resource_alerting_message_template.go

View workflow job for this annotation

GitHub Actions / docs

no required module provides package github.com/grafana/terraform-provider-grafana/internal/common; to add it:

Check failure on line 12 in internal/resources/grafana/resource_alerting_message_template.go

View workflow job for this annotation

GitHub Actions / unit tests

no required module provides package github.com/grafana/terraform-provider-grafana/internal/common; to add it:

Check failure on line 12 in internal/resources/grafana/resource_alerting_message_template.go

View workflow job for this annotation

GitHub Actions / integration

no required module provides package github.com/grafana/terraform-provider-grafana/internal/common; to add it:

Check failure on line 12 in internal/resources/grafana/resource_alerting_message_template.go

View workflow job for this annotation

GitHub Actions / cloudinstance

no required module provides package github.com/grafana/terraform-provider-grafana/internal/common; to add it:

Check failure on line 12 in internal/resources/grafana/resource_alerting_message_template.go

View workflow job for this annotation

GitHub Actions / cloudinstance

no required module provides package github.com/grafana/terraform-provider-grafana/internal/common; to add it:

Check failure on line 12 in internal/resources/grafana/resource_alerting_message_template.go

View workflow job for this annotation

GitHub Actions / cloudinstance

no required module provides package github.com/grafana/terraform-provider-grafana/internal/common; to add it:

Check failure on line 12 in internal/resources/grafana/resource_alerting_message_template.go

View workflow job for this annotation

GitHub Actions / 11.0.0 - oss - other

no required module provides package github.com/grafana/terraform-provider-grafana/internal/common; to add it:

Check failure on line 12 in internal/resources/grafana/resource_alerting_message_template.go

View workflow job for this annotation

GitHub Actions / 11.0.0 - oss - other

no required module provides package github.com/grafana/terraform-provider-grafana/internal/common; to add it:

Check failure on line 12 in internal/resources/grafana/resource_alerting_message_template.go

View workflow job for this annotation

GitHub Actions / 11.0.0 - oss - other

no required module provides package github.com/grafana/terraform-provider-grafana/internal/common; to add it:

Check failure on line 12 in internal/resources/grafana/resource_alerting_message_template.go

View workflow job for this annotation

GitHub Actions / 11.0.0 - oss - long

no required module provides package github.com/grafana/terraform-provider-grafana/internal/common; to add it:

Check failure on line 12 in internal/resources/grafana/resource_alerting_message_template.go

View workflow job for this annotation

GitHub Actions / 11.0.0 - oss - long

no required module provides package github.com/grafana/terraform-provider-grafana/internal/common; to add it:

Check failure on line 12 in internal/resources/grafana/resource_alerting_message_template.go

View workflow job for this annotation

GitHub Actions / 11.0.0 - oss - long

no required module provides package github.com/grafana/terraform-provider-grafana/internal/common; to add it:

Check failure on line 12 in internal/resources/grafana/resource_alerting_message_template.go

View workflow job for this annotation

GitHub Actions / 10.4.3 - oss - long

no required module provides package github.com/grafana/terraform-provider-grafana/internal/common; to add it:

Check failure on line 12 in internal/resources/grafana/resource_alerting_message_template.go

View workflow job for this annotation

GitHub Actions / 10.4.3 - oss - long

no required module provides package github.com/grafana/terraform-provider-grafana/internal/common; to add it:

Check failure on line 12 in internal/resources/grafana/resource_alerting_message_template.go

View workflow job for this annotation

GitHub Actions / 10.4.3 - oss - long

no required module provides package github.com/grafana/terraform-provider-grafana/internal/common; to add it:

Check failure on line 12 in internal/resources/grafana/resource_alerting_message_template.go

View workflow job for this annotation

GitHub Actions / 10.4.3 - enterprise - enterprise

no required module provides package github.com/grafana/terraform-provider-grafana/internal/common; to add it:

Check failure on line 12 in internal/resources/grafana/resource_alerting_message_template.go

View workflow job for this annotation

GitHub Actions / 10.4.3 - enterprise - enterprise

no required module provides package github.com/grafana/terraform-provider-grafana/internal/common; to add it:

Check failure on line 12 in internal/resources/grafana/resource_alerting_message_template.go

View workflow job for this annotation

GitHub Actions / 10.4.3 - enterprise - enterprise

no required module provides package github.com/grafana/terraform-provider-grafana/internal/common; to add it:

Check failure on line 12 in internal/resources/grafana/resource_alerting_message_template.go

View workflow job for this annotation

GitHub Actions / 11.0.0 - enterprise - generate

no required module provides package github.com/grafana/terraform-provider-grafana/internal/common; to add it:

Check failure on line 12 in internal/resources/grafana/resource_alerting_message_template.go

View workflow job for this annotation

GitHub Actions / 11.0.0 - enterprise - generate

no required module provides package github.com/grafana/terraform-provider-grafana/internal/common; to add it:

Check failure on line 12 in internal/resources/grafana/resource_alerting_message_template.go

View workflow job for this annotation

GitHub Actions / 11.0.0 - enterprise - generate

no required module provides package github.com/grafana/terraform-provider-grafana/internal/common; to add it:

Check failure on line 12 in internal/resources/grafana/resource_alerting_message_template.go

View workflow job for this annotation

GitHub Actions / 9.5.18 - oss - other

no required module provides package github.com/grafana/terraform-provider-grafana/internal/common; to add it:

Check failure on line 12 in internal/resources/grafana/resource_alerting_message_template.go

View workflow job for this annotation

GitHub Actions / 9.5.18 - oss - other

no required module provides package github.com/grafana/terraform-provider-grafana/internal/common; to add it:

Check failure on line 12 in internal/resources/grafana/resource_alerting_message_template.go

View workflow job for this annotation

GitHub Actions / 10.4.3 - oss - basic

no required module provides package github.com/grafana/terraform-provider-grafana/internal/common; to add it:

Check failure on line 12 in internal/resources/grafana/resource_alerting_message_template.go

View workflow job for this annotation

GitHub Actions / 9.5.18 - oss - other

no required module provides package github.com/grafana/terraform-provider-grafana/internal/common; to add it:

Check failure on line 12 in internal/resources/grafana/resource_alerting_message_template.go

View workflow job for this annotation

GitHub Actions / 10.4.3 - oss - basic

no required module provides package github.com/grafana/terraform-provider-grafana/internal/common; to add it:

Check failure on line 12 in internal/resources/grafana/resource_alerting_message_template.go

View workflow job for this annotation

GitHub Actions / 10.4.3 - oss - basic

no required module provides package github.com/grafana/terraform-provider-grafana/internal/common; to add it:

Check failure on line 12 in internal/resources/grafana/resource_alerting_message_template.go

View workflow job for this annotation

GitHub Actions / 11.0.0 - subpath - basic

no required module provides package github.com/grafana/terraform-provider-grafana/internal/common; to add it:

Check failure on line 12 in internal/resources/grafana/resource_alerting_message_template.go

View workflow job for this annotation

GitHub Actions / 11.0.0 - subpath - basic

no required module provides package github.com/grafana/terraform-provider-grafana/internal/common; to add it:

Check failure on line 12 in internal/resources/grafana/resource_alerting_message_template.go

View workflow job for this annotation

GitHub Actions / 11.0.0 - subpath - basic

no required module provides package github.com/grafana/terraform-provider-grafana/internal/common; to add it:

Check failure on line 12 in internal/resources/grafana/resource_alerting_message_template.go

View workflow job for this annotation

GitHub Actions / 11.0.0 - subpath - other

no required module provides package github.com/grafana/terraform-provider-grafana/internal/common; to add it:

Check failure on line 12 in internal/resources/grafana/resource_alerting_message_template.go

View workflow job for this annotation

GitHub Actions / 11.0.0 - subpath - other

no required module provides package github.com/grafana/terraform-provider-grafana/internal/common; to add it:

Check failure on line 12 in internal/resources/grafana/resource_alerting_message_template.go

View workflow job for this annotation

GitHub Actions / 11.0.0 - subpath - other

no required module provides package github.com/grafana/terraform-provider-grafana/internal/common; to add it:

Check failure on line 12 in internal/resources/grafana/resource_alerting_message_template.go

View workflow job for this annotation

GitHub Actions / 9.5.18 - oss - long

no required module provides package github.com/grafana/terraform-provider-grafana/internal/common; to add it:

Check failure on line 12 in internal/resources/grafana/resource_alerting_message_template.go

View workflow job for this annotation

GitHub Actions / 9.5.18 - oss - long

no required module provides package github.com/grafana/terraform-provider-grafana/internal/common; to add it:

Check failure on line 12 in internal/resources/grafana/resource_alerting_message_template.go

View workflow job for this annotation

GitHub Actions / 9.5.18 - oss - long

no required module provides package github.com/grafana/terraform-provider-grafana/internal/common; to add it:

Check failure on line 12 in internal/resources/grafana/resource_alerting_message_template.go

View workflow job for this annotation

GitHub Actions / 11.0.0 - oss - examples

no required module provides package github.com/grafana/terraform-provider-grafana/internal/common; to add it:

Check failure on line 12 in internal/resources/grafana/resource_alerting_message_template.go

View workflow job for this annotation

GitHub Actions / 11.0.0 - oss - examples

no required module provides package github.com/grafana/terraform-provider-grafana/internal/common; to add it:

Check failure on line 12 in internal/resources/grafana/resource_alerting_message_template.go

View workflow job for this annotation

GitHub Actions / 11.0.0 - oss - examples

no required module provides package github.com/grafana/terraform-provider-grafana/internal/common; to add it:

Check failure on line 12 in internal/resources/grafana/resource_alerting_message_template.go

View workflow job for this annotation

GitHub Actions / 11.0.0 - enterprise - enterprise

no required module provides package github.com/grafana/terraform-provider-grafana/internal/common; to add it:

Check failure on line 12 in internal/resources/grafana/resource_alerting_message_template.go

View workflow job for this annotation

GitHub Actions / 11.0.0 - enterprise - enterprise

no required module provides package github.com/grafana/terraform-provider-grafana/internal/common; to add it:

Check failure on line 12 in internal/resources/grafana/resource_alerting_message_template.go

View workflow job for this annotation

GitHub Actions / 11.0.0 - enterprise - enterprise

no required module provides package github.com/grafana/terraform-provider-grafana/internal/common; to add it:

Check failure on line 12 in internal/resources/grafana/resource_alerting_message_template.go

View workflow job for this annotation

GitHub Actions / 9.5.18 - enterprise - enterprise

no required module provides package github.com/grafana/terraform-provider-grafana/internal/common; to add it:

Check failure on line 12 in internal/resources/grafana/resource_alerting_message_template.go

View workflow job for this annotation

GitHub Actions / 9.5.18 - enterprise - enterprise

no required module provides package github.com/grafana/terraform-provider-grafana/internal/common; to add it:

Check failure on line 12 in internal/resources/grafana/resource_alerting_message_template.go

View workflow job for this annotation

GitHub Actions / 9.5.18 - enterprise - enterprise

no required module provides package github.com/grafana/terraform-provider-grafana/internal/common; to add it:

Check failure on line 12 in internal/resources/grafana/resource_alerting_message_template.go

View workflow job for this annotation

GitHub Actions / 11.0.0 - oss - basic

no required module provides package github.com/grafana/terraform-provider-grafana/internal/common; to add it:

Check failure on line 12 in internal/resources/grafana/resource_alerting_message_template.go

View workflow job for this annotation

GitHub Actions / 11.0.0 - oss - basic

no required module provides package github.com/grafana/terraform-provider-grafana/internal/common; to add it:

Check failure on line 12 in internal/resources/grafana/resource_alerting_message_template.go

View workflow job for this annotation

GitHub Actions / 11.0.0 - oss - basic

no required module provides package github.com/grafana/terraform-provider-grafana/internal/common; to add it:

Check failure on line 12 in internal/resources/grafana/resource_alerting_message_template.go

View workflow job for this annotation

GitHub Actions / 10.4.3 - enterprise - generate

no required module provides package github.com/grafana/terraform-provider-grafana/internal/common; to add it:

Check failure on line 12 in internal/resources/grafana/resource_alerting_message_template.go

View workflow job for this annotation

GitHub Actions / 10.4.3 - enterprise - generate

no required module provides package github.com/grafana/terraform-provider-grafana/internal/common; to add it:

Check failure on line 12 in internal/resources/grafana/resource_alerting_message_template.go

View workflow job for this annotation

GitHub Actions / 10.4.3 - enterprise - generate

no required module provides package github.com/grafana/terraform-provider-grafana/internal/common; to add it:

Check failure on line 12 in internal/resources/grafana/resource_alerting_message_template.go

View workflow job for this annotation

GitHub Actions / 10.4.3 - oss - other

no required module provides package github.com/grafana/terraform-provider-grafana/internal/common; to add it:

Check failure on line 12 in internal/resources/grafana/resource_alerting_message_template.go

View workflow job for this annotation

GitHub Actions / 10.4.3 - oss - other

no required module provides package github.com/grafana/terraform-provider-grafana/internal/common; to add it:

Check failure on line 12 in internal/resources/grafana/resource_alerting_message_template.go

View workflow job for this annotation

GitHub Actions / 10.4.3 - oss - other

no required module provides package github.com/grafana/terraform-provider-grafana/internal/common; to add it:

Check failure on line 12 in internal/resources/grafana/resource_alerting_message_template.go

View workflow job for this annotation

GitHub Actions / 11.0.0 - tls - basic

no required module provides package github.com/grafana/terraform-provider-grafana/internal/common; to add it:

Check failure on line 12 in internal/resources/grafana/resource_alerting_message_template.go

View workflow job for this annotation

GitHub Actions / 11.0.0 - tls - basic

no required module provides package github.com/grafana/terraform-provider-grafana/internal/common; to add it:

Check failure on line 12 in internal/resources/grafana/resource_alerting_message_template.go

View workflow job for this annotation

GitHub Actions / 11.0.0 - tls - basic

no required module provides package github.com/grafana/terraform-provider-grafana/internal/common; to add it:

Check failure on line 12 in internal/resources/grafana/resource_alerting_message_template.go

View workflow job for this annotation

GitHub Actions / 9.5.18 - oss - basic

no required module provides package github.com/grafana/terraform-provider-grafana/internal/common; to add it:

Check failure on line 12 in internal/resources/grafana/resource_alerting_message_template.go

View workflow job for this annotation

GitHub Actions / 9.5.18 - oss - basic

no required module provides package github.com/grafana/terraform-provider-grafana/internal/common; to add it:

Check failure on line 12 in internal/resources/grafana/resource_alerting_message_template.go

View workflow job for this annotation

GitHub Actions / 9.5.18 - oss - basic

no required module provides package github.com/grafana/terraform-provider-grafana/internal/common; to add it:
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)

func resourceMessageTemplate() *common.Resource {
schema := &schema.Resource{
func ResourceMessageTemplate() *schema.Resource {
return &schema.Resource{
Description: `
Manages Grafana Alerting message templates.
* [Official documentation](https://grafana.com/docs/grafana/latest/alerting/set-up/provision-alerting-resources/terraform-provisioning/)
* [HTTP API](https://grafana.com/docs/grafana/latest/developers/http_api/alerting_provisioning/#templates)
* [Official documentation](https://grafana.com/docs/grafana/latest/alerting/manage-notifications/template-notifications/create-notification-templates/)
* [HTTP API](https://grafana.com/docs/grafana/next/developers/http_api/alerting_provisioning/#templates)
This resource requires Grafana 9.1.0 or later.
`,
CreateContext: common.WithAlertingMutex[schema.CreateContextFunc](putMessageTemplate),
CreateContext: putMessageTemplate,
ReadContext: readMessageTemplate,
UpdateContext: common.WithAlertingMutex[schema.UpdateContextFunc](putMessageTemplate),
DeleteContext: common.WithAlertingMutex[schema.DeleteContextFunc](deleteMessageTemplate),
UpdateContext: putMessageTemplate,
DeleteContext: deleteMessageTemplate,
Importer: &schema.ResourceImporter{
StateContext: schema.ImportStatePassthroughContext,
},
Expand All @@ -51,46 +50,8 @@ This resource requires Grafana 9.1.0 or later.
return strings.TrimSpace(v.(string))
},
},
"disable_provenance": {
Type: schema.TypeBool,
Optional: true,
Default: false,
ForceNew: true, // TODO: The API doesn't return provenance, so we have to force new for now.
Description: "Allow modifying the message template from other sources than Terraform or the Grafana API.",
},
},
}

return common.NewLegacySDKResource(
common.CategoryAlerting,
"grafana_message_template",
orgResourceIDString("name"),
schema,
).WithLister(listerFunctionOrgResource(listMessageTemplate))
}

func listMessageTemplate(ctx context.Context, client *goapi.GrafanaHTTPAPI, orgID int64) ([]string, error) {
var ids []string
// Retry if the API returns 500 because it may be that the alertmanager is not ready in the org yet.
// The alertmanager is provisioned asynchronously when the org is created.
if err := retry.RetryContext(ctx, 2*time.Minute, func() *retry.RetryError {
resp, err := client.Provisioning.GetTemplates()
if err != nil {
if orgID > 1 && (err.(*runtime.APIError).IsCode(500) || err.(*runtime.APIError).IsCode(403)) {
return retry.RetryableError(err)
}
return retry.NonRetryableError(err)
}

for _, template := range resp.Payload {
ids = append(ids, MakeOrgResourceID(orgID, template.Name))
}
return nil
}); err != nil {
return nil, err
}

return ids, nil
}

func readMessageTemplate(ctx context.Context, data *schema.ResourceData, meta interface{}) diag.Diagnostics {
Expand All @@ -110,6 +71,9 @@ func readMessageTemplate(ctx context.Context, data *schema.ResourceData, meta in
}

func putMessageTemplate(ctx context.Context, data *schema.ResourceData, meta interface{}) diag.Diagnostics {
lock := &meta.(*common.Client).AlertingMutex
lock.Lock()
defer lock.Unlock()
client, orgID := OAPIClientFromNewOrgResource(meta, data)

name := data.Get("name").(string)
Expand All @@ -123,9 +87,6 @@ func putMessageTemplate(ctx context.Context, data *schema.ResourceData, meta int
WithBody(&models.NotificationTemplateContent{
Template: content,
})
if v, ok := data.GetOk("disable_provenance"); ok && v.(bool) {
params.SetXDisableProvenance(&provenanceDisabled)
}
if _, err := client.Provisioning.PutTemplate(params); err != nil {
if orgID > 1 && err.(*runtime.APIError).IsCode(500) {
return retry.RetryableError(err)
Expand All @@ -143,10 +104,12 @@ func putMessageTemplate(ctx context.Context, data *schema.ResourceData, meta int
}

func deleteMessageTemplate(ctx context.Context, data *schema.ResourceData, meta interface{}) diag.Diagnostics {
lock := &meta.(*common.Client).AlertingMutex
lock.Lock()
defer lock.Unlock()
client, _, name := OAPIClientFromExistingOrgResource(meta, data.Id())

params := provisioning.NewDeleteTemplateParams().WithName(name)
_, err := client.Provisioning.DeleteTemplate(params)
_, err := client.Provisioning.DeleteTemplate(name)
diag, _ := common.CheckReadError("message template", data, err)
return diag
}

0 comments on commit 0f7d8a6

Please sign in to comment.