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

Fix customized diff function and outdated references to policy ownership relationship to inline and independent policies #88

Merged
merged 1 commit into from
Oct 30, 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
6 changes: 3 additions & 3 deletions chronosphere/resource_bucket.go
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ func reconcileNotificationPolicy(
}
if independent {
// Can only inline policies that are not independent
return diag.Errorf("cannot use notification_policy_data of owned policy, use a notification policy without team_id")
return diag.Errorf("cannot use notification_policy_data of named policy, use a notification policy without name")
}

// If policy wasn't set before and still isn't, no-op
Expand Down Expand Up @@ -405,8 +405,8 @@ func policyModelFromBucket(d *schema.ResourceData) (policy *configmodels.Configv
}

// When deleting policies, only bucket-owned policies are deleted, deletes of
// other owned policies are ignored to support migrating from an inline policy
// to an independent team-owned policy.
// other policies are ignored to support migrating from an inline policy
// to an independent policy.
func policyNotBucketOwned(err error) bool {
err = clienterror.Wrap(err)

Expand Down
2 changes: 1 addition & 1 deletion chronosphere/resource_notification_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ func isNotificationPolicyIndependentForCustomizeDiff(
return false
}

return !isRawAttributeNull(diff, "team_id")
return !isRawAttributeNull(diff, "name")
}

func expandMatcherSchema(m intschema.Matcher) *configmodels.Configv1LabelMatcher {
Expand Down
3 changes: 3 additions & 0 deletions chronosphere/resource_notification_policy_independent.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ func (independentNotificationPolicyConverter) fromModel(
// Note: BucketSlug being set should cause a change to be detected by TF.
// Since a policy is either bucket-owned or team-owned, a bucket owned policy
// will have no team, so the team will mismatch.
// TODO(brian.barnes): Now that policies can be unowned, it is no longer true
// that setting a bucket slug outside of terraform will lead to a mismatch, since
// team_id is not guaranteed to be set if a policy is not bucket-owned.
return &intschema.NotificationPolicy{
Name: m.Name,
Slug: m.Slug,
Expand Down
2 changes: 1 addition & 1 deletion chronosphere/tfschema/monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ var Monitor = map[string]*schema.Schema{
Optional: true,
ValidateDiagFunc: func(policyID any, _ cty.Path) diag.Diagnostics {
if localid.IsLocalID(policyID.(string)) {
return diag.Errorf("cannot directly reference unowned notification policy, use a notifcation policy with team_id set")
return diag.Errorf("cannot directly reference unnamed notification policy, use a notification policy with name set")
}
return nil
},
Expand Down
8 changes: 4 additions & 4 deletions chronosphere/tfschema/notification_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,18 @@ import (
const IndependentNotificationPolicyData = "__independent"

var NotificationPolicy = map[string]*schema.Schema{
// NB: slug may be set if bucket_id or team_id is set, but cannot be set if bucket_id and team_id are unset.
// NB: slug can only be set if name is set, but cannot be set if name is unset, e.g. inline.
"slug": {
Type: schema.TypeString,
Optional: true,
Computed: true,
ForceNew: true,
},
// NB: there is custom name ForceNew behavior in the DiffSuppressFunc.
"name": {
Type: schema.TypeString,
Optional: true,
},
// NB: there is custom team_id ForceNew behavior in the DiffSuppressFunc.
"team_id": {
Type: schema.TypeString,
Optional: true,
Expand All @@ -61,8 +61,8 @@ var NotificationPolicy = map[string]*schema.Schema{
DiffSuppressFunc: JSONNotificationPolicyDiffSuppress,
ValidateFunc: ValidateNotificationPolicyData,
},
// This field is for internal use only. We use it to force new resources when the ownership
// of a notification policy changes (from unowned to independent or vice versa)
// This field is for internal use only. We use it to force new resources when the name
// of a notification policy changes (from inline to independent or vice versa)
"is_independent": {
Type: schema.TypeBool,
Computed: true,
Expand Down
Loading