-
Notifications
You must be signed in to change notification settings - Fork 248
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: rebase newrelic_alert_policy resource on newrelic-client-go (…
- Loading branch information
Showing
8 changed files
with
125 additions
and
88 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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,42 @@ | ||
package newrelic | ||
|
||
import ( | ||
"strconv" | ||
"time" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/helper/schema" | ||
"github.com/newrelic/newrelic-client-go/pkg/alerts" | ||
) | ||
|
||
func expandAlertPolicy(d *schema.ResourceData) *alerts.Policy { | ||
policy := alerts.Policy{ | ||
Name: d.Get("name").(string), | ||
} | ||
|
||
if attr, ok := d.GetOk("incident_preference"); ok { | ||
policy.IncidentPreference = attr.(string) | ||
} | ||
|
||
return &policy | ||
} | ||
|
||
func flattenAlertPolicyDataSource(policy *alerts.Policy, d *schema.ResourceData) error { | ||
d.SetId(strconv.Itoa(policy.ID)) | ||
|
||
return flattenAlertPolicy(policy, d) | ||
} | ||
|
||
func flattenAlertPolicy(policy *alerts.Policy, d *schema.ResourceData) error { | ||
// New Relic provides created_at and updated_at as millisecond unix timestamps | ||
// https://www.terraform.io/docs/extend/schemas/schema-types.html#date-amp-time-data | ||
// "TypeString is also used for date/time data, the preferred format is RFC 3339." | ||
created := time.Time(*policy.CreatedAt).Format(time.RFC3339) | ||
updated := time.Time(*policy.UpdatedAt).Format(time.RFC3339) | ||
|
||
d.Set("name", policy.Name) | ||
d.Set("incident_preference", policy.IncidentPreference) | ||
d.Set("created_at", created) | ||
d.Set("updated_at", updated) | ||
|
||
return nil | ||
} |
2 changes: 1 addition & 1 deletion
2
vendor/github.com/newrelic/newrelic-client-go/internal/version/version.go
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
74 changes: 54 additions & 20 deletions
74
vendor/github.com/newrelic/newrelic-client-go/pkg/alerts/alerts_types.go
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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