-
Notifications
You must be signed in to change notification settings - Fork 16
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
Reimplement notification groups with tf-framework #221
Reimplement notification groups with tf-framework #221
Conversation
f26e8cd
to
2875806
Compare
2875806
to
f8eef7b
Compare
resp.Schema = schema.Schema{ | ||
Description: "This data source allows access to details of a specific notitication group setting.", | ||
|
||
Attributes: map[string]schema.Attribute{ | ||
"id": schema.StringAttribute{ | ||
Description: "The ID of the notitication group", | ||
|
||
Required: true, | ||
}, | ||
"name": schema.StringAttribute{ | ||
Description: "The name of the notification group", | ||
|
||
Computed: true, | ||
}, | ||
"notification_level": schema.StringAttribute{ | ||
MarkdownDescription: "The level of notitication (`all` or `critical`)", | ||
|
||
Computed: true, | ||
}, | ||
"child_notification_group_ids": schema.SetAttribute{ | ||
Description: "A set of notification group IDs", | ||
|
||
ElementType: types.StringType, | ||
Computed: true, | ||
}, | ||
"child_channel_ids": schema.SetAttribute{ | ||
Description: "A set of notification channel IDs", | ||
|
||
ElementType: types.StringType, | ||
Computed: true, | ||
}, | ||
}, | ||
// TODO: migrate to nested attributes (terraform plugin protocol v6 is required) | ||
Blocks: map[string]schema.Block{ | ||
"monitor": schema.SetNestedBlock{ | ||
Description: "A set of notification target monitor rules", | ||
|
||
NestedObject: schema.NestedBlockObject{ | ||
Attributes: map[string]schema.Attribute{ | ||
"id": schema.StringAttribute{ | ||
Description: "The monitor rule ID", | ||
|
||
Computed: true, | ||
}, | ||
"skip_default": schema.BoolAttribute{ | ||
Description: "If true, send notifications to this notification group only", | ||
|
||
Computed: true, | ||
}, | ||
}, | ||
}, | ||
}, | ||
"service": schema.SetNestedBlock{ | ||
Description: "A set of notification target services", | ||
|
||
NestedObject: schema.NestedBlockObject{ | ||
Attributes: map[string]schema.Attribute{ | ||
"name": schema.StringAttribute{ | ||
Description: "the name of the service", | ||
|
||
Computed: true, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Original schema:
terraform-provider-mackerel/mackerel/data_source_mackerel_notification_group.go
Lines 15 to 48 in 3c50804
Schema: map[string]*schema.Schema{ | |
"id": { | |
Type: schema.TypeString, | |
Required: true, | |
}, | |
"name": { | |
Type: schema.TypeString, | |
Computed: true, | |
}, | |
"notification_level": { | |
Type: schema.TypeString, | |
Computed: true, | |
}, | |
"child_notification_group_ids": { | |
Type: schema.TypeSet, | |
Computed: true, | |
Elem: &schema.Schema{Type: schema.TypeString}, | |
}, | |
"child_channel_ids": { | |
Type: schema.TypeSet, | |
Computed: true, | |
Elem: &schema.Schema{Type: schema.TypeString}, | |
}, | |
"monitor": { | |
Type: schema.TypeSet, | |
Computed: true, | |
Elem: monitorResource, | |
}, | |
"service": { | |
Type: schema.TypeSet, | |
Computed: true, | |
Elem: serviceResource, | |
}, | |
}, |
resp.Schema = schema.Schema{ | ||
Description: "This resouce allows creating and management of notification groups", | ||
|
||
Attributes: map[string]schema.Attribute{ | ||
"id": schema.StringAttribute{ | ||
Description: "The ID of the notitication group", | ||
|
||
Computed: true, | ||
PlanModifiers: []planmodifier.String{ | ||
stringplanmodifier.UseStateForUnknown(), | ||
}, | ||
}, | ||
"name": schema.StringAttribute{ | ||
Description: "The name of the notification group", | ||
|
||
Required: true, | ||
}, | ||
"notification_level": schema.StringAttribute{ | ||
MarkdownDescription: "The level of notitication (`all` or `critical`)", | ||
|
||
Optional: true, | ||
Computed: true, | ||
Validators: []validator.String{ | ||
mackerel.NotificationLevelValidator(), | ||
}, | ||
Default: stringdefault.StaticString("all"), | ||
}, | ||
"child_notification_group_ids": schema.SetAttribute{ | ||
Description: "A set of notification group IDs", | ||
|
||
ElementType: types.StringType, | ||
Optional: true, | ||
}, | ||
"child_channel_ids": schema.SetAttribute{ | ||
Description: "A set of notification channel IDs", | ||
|
||
ElementType: types.StringType, | ||
Optional: true, | ||
}, | ||
}, | ||
// TODO: migrate to nested attributes | ||
Blocks: map[string]schema.Block{ | ||
"monitor": schema.SetNestedBlock{ | ||
Description: "Configuration block(s) with monitor rules", | ||
|
||
NestedObject: schema.NestedBlockObject{ | ||
Attributes: map[string]schema.Attribute{ | ||
"id": schema.StringAttribute{ | ||
Description: "The monitor rule ID", | ||
|
||
Required: true, | ||
}, | ||
"skip_default": schema.BoolAttribute{ | ||
Description: "If true, send notifications to this notification group only.", | ||
|
||
Optional: true, | ||
Computed: true, | ||
Default: booldefault.StaticBool(false), | ||
}, | ||
}, | ||
}, | ||
}, | ||
"service": schema.SetNestedBlock{ | ||
Description: "Configuration block(s) with services", | ||
|
||
NestedObject: schema.NestedBlockObject{ | ||
Attributes: map[string]schema.Attribute{ | ||
"name": schema.StringAttribute{ | ||
Description: "The name of the service", | ||
|
||
Required: true, | ||
Validators: []validator.String{ | ||
mackerel.ServiceNameValidator(), | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Original schema:
terraform-provider-mackerel/mackerel/resource_mackerel_notification_group.go
Lines 44 to 75 in 3c50804
Schema: map[string]*schema.Schema{ | |
"name": { | |
Type: schema.TypeString, | |
Required: true, | |
}, | |
"notification_level": { | |
Type: schema.TypeString, | |
Optional: true, | |
ValidateFunc: validation.StringInSlice([]string{"all", "critical"}, false), | |
Default: "all", | |
}, | |
"child_notification_group_ids": { | |
Type: schema.TypeSet, | |
Optional: true, | |
Elem: &schema.Schema{Type: schema.TypeString}, | |
}, | |
"child_channel_ids": { | |
Type: schema.TypeSet, | |
Optional: true, | |
Elem: &schema.Schema{Type: schema.TypeString}, | |
}, | |
"monitor": { | |
Type: schema.TypeSet, | |
Optional: true, | |
Elem: monitorResource, | |
}, | |
"service": { | |
Type: schema.TypeSet, | |
Optional: true, | |
Elem: serviceResource, | |
}, | |
}, |
Attributes: map[string]schema.Attribute{ | ||
"name": schema.StringAttribute{ | ||
Description: "The name of the service", | ||
|
||
Required: true, | ||
Validators: []validator.String{ | ||
mackerel.ServiceNameValidator(), | ||
}, | ||
}, | ||
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
terraform-provider-mackerel/mackerel/resource_mackerel_notification_group.go
Lines 12 to 19 in 3c50804
var serviceResource = &schema.Resource{ | |
Schema: map[string]*schema.Schema{ | |
"name": { | |
Type: schema.TypeString, | |
Required: true, | |
}, | |
}, | |
} |
Attributes: map[string]schema.Attribute{ | ||
"id": schema.StringAttribute{ | ||
Description: "The monitor rule ID", | ||
|
||
Required: true, | ||
}, | ||
"skip_default": schema.BoolAttribute{ | ||
Description: "If true, send notifications to this notification group only.", | ||
|
||
Optional: true, | ||
Computed: true, | ||
Default: booldefault.StaticBool(false), | ||
}, | ||
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
terraform-provider-mackerel/mackerel/resource_mackerel_notification_group.go
Lines 21 to 33 in 3c50804
var monitorResource = &schema.Resource{ | |
Schema: map[string]*schema.Schema{ | |
"id": { | |
Type: schema.TypeString, | |
Required: true, | |
}, | |
"skip_default": { | |
Type: schema.TypeBool, | |
Optional: true, | |
Default: false, | |
}, | |
}, | |
} |
}, | ||
}, | ||
// TODO: migrate to nested attributes | ||
Blocks: map[string]schema.Block{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Blocks are a restricted version of nested object attributes (e.g. cannot be used as expressions).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Optional: true, | ||
Computed: true, | ||
Default: booldefault.StaticBool(false), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Attributes with a default value are both inputs and outputs. If the user provides a value, they are act as input. If not, the provider computes and provides a default value. So they need not to be only optional but also computed.
f8eef7b
to
4cfea49
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
}, | ||
}, | ||
// TODO: migrate to nested attributes | ||
Blocks: map[string]schema.Block{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Output from acceptance testing: