-
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 dashboards with terraform-plugin-framework #239
Conversation
e172623
to
907fe5c
Compare
907fe5c
to
7fa159b
Compare
s := schema.Schema{ | ||
Description: "This resource allows creating and management of dashboards.", | ||
Attributes: map[string]schema.Attribute{ | ||
"id": schema.StringAttribute{ | ||
Description: schemaDashboardIDDesc, | ||
Computed: true, | ||
PlanModifiers: []planmodifier.String{ | ||
stringplanmodifier.UseStateForUnknown(), | ||
}, | ||
}, | ||
"title": schema.StringAttribute{ | ||
Description: schemaDashboardTitleDesc, | ||
Required: true, | ||
}, | ||
"memo": schema.StringAttribute{ | ||
Description: schemaDashboardMemoDesc, | ||
Optional: true, | ||
Computed: true, | ||
Default: stringdefault.StaticString(""), | ||
}, | ||
"url_path": schema.StringAttribute{ | ||
Description: schemaDashboardURLPathDesc, | ||
Optional: true, | ||
Computed: true, | ||
Default: stringdefault.StaticString(""), | ||
}, | ||
"created_at": schema.Int64Attribute{ | ||
Description: schemaDashboardCreatedAtDesc, | ||
Computed: true, | ||
PlanModifiers: []planmodifier.Int64{ | ||
int64planmodifier.UseStateForUnknown(), | ||
}, | ||
}, | ||
"updated_at": schema.Int64Attribute{ | ||
Description: schemaDashboardUpdatedAtDesc, | ||
Computed: true, | ||
}, | ||
}, | ||
Blocks: map[string]schema.Block{ | ||
"graph": schemaDashboardResource_graph, | ||
"value": schemaDashboardResource_value, | ||
"markdown": schemaDashboardResource_markdown, | ||
"alert_status": schemaDashboardResource_alertStatus, | ||
}, | ||
} |
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_dashboard.go
Lines 143 to 342 in 2918d8d
Schema: map[string]*schema.Schema{ | |
"title": { | |
Type: schema.TypeString, | |
Required: true, | |
}, | |
"memo": { | |
Type: schema.TypeString, | |
Optional: true, | |
}, | |
"url_path": { | |
Type: schema.TypeString, | |
Optional: true, | |
}, | |
"graph": { | |
Type: schema.TypeList, | |
Optional: true, | |
Elem: &schema.Resource{ | |
Schema: map[string]*schema.Schema{ | |
"title": { | |
Type: schema.TypeString, | |
Required: true, | |
}, | |
"host": { | |
Type: schema.TypeList, | |
Optional: true, | |
MaxItems: 1, | |
Elem: &schema.Resource{ | |
Schema: map[string]*schema.Schema{ | |
"host_id": { | |
Type: schema.TypeString, | |
Required: true, | |
}, | |
"name": { | |
Type: schema.TypeString, | |
Required: true, | |
}, | |
}, | |
}, | |
}, | |
"role": { | |
Type: schema.TypeList, | |
Optional: true, | |
MaxItems: 1, | |
Elem: &schema.Resource{ | |
Schema: map[string]*schema.Schema{ | |
"role_fullname": { | |
Type: schema.TypeString, | |
Required: true, | |
}, | |
"name": { | |
Type: schema.TypeString, | |
Required: true, | |
}, | |
"is_stacked": { | |
Type: schema.TypeBool, | |
Optional: true, | |
Default: false, | |
}, | |
}, | |
}, | |
}, | |
"service": { | |
Type: schema.TypeList, | |
Optional: true, | |
MaxItems: 1, | |
Elem: &schema.Resource{ | |
Schema: map[string]*schema.Schema{ | |
"service_name": { | |
Type: schema.TypeString, | |
Required: true, | |
}, | |
"name": { | |
Type: schema.TypeString, | |
Required: true, | |
}, | |
}, | |
}, | |
}, | |
"expression": { | |
Type: schema.TypeList, | |
Optional: true, | |
MaxItems: 1, | |
Elem: &schema.Resource{ | |
Schema: map[string]*schema.Schema{ | |
"expression": { | |
Type: schema.TypeString, | |
Required: true, | |
}, | |
}, | |
}, | |
}, | |
"query": { | |
Type: schema.TypeList, | |
Optional: true, | |
MaxItems: 1, | |
Elem: &schema.Resource{ | |
Schema: map[string]*schema.Schema{ | |
"query": { | |
Type: schema.TypeString, | |
Required: true, | |
}, | |
"legend": { | |
Type: schema.TypeString, | |
Optional: true, | |
}, | |
}, | |
}, | |
}, | |
"range": { | |
Type: schema.TypeList, | |
Optional: true, | |
MaxItems: 1, | |
Elem: dashboardRangeResource, | |
}, | |
"layout": { | |
Type: schema.TypeList, | |
Required: true, | |
MaxItems: 1, | |
Elem: dashboardLayoutResource, | |
}, | |
}, | |
}, | |
}, | |
"value": { | |
Type: schema.TypeList, | |
Optional: true, | |
Elem: &schema.Resource{ | |
Schema: map[string]*schema.Schema{ | |
"title": { | |
Type: schema.TypeString, | |
Required: true, | |
}, | |
"metric": { | |
Type: schema.TypeList, | |
Required: true, | |
MaxItems: 1, | |
Elem: dashboardMetricResource, | |
}, | |
"fraction_size": { | |
Type: schema.TypeInt, | |
Optional: true, | |
}, | |
"suffix": { | |
Type: schema.TypeString, | |
Required: true, | |
}, | |
"layout": { | |
Type: schema.TypeList, | |
Required: true, | |
MaxItems: 1, | |
Elem: dashboardLayoutResource, | |
}, | |
}, | |
}, | |
}, | |
"markdown": { | |
Type: schema.TypeList, | |
Optional: true, | |
Elem: &schema.Resource{ | |
Schema: map[string]*schema.Schema{ | |
"title": { | |
Type: schema.TypeString, | |
Required: true, | |
}, | |
"markdown": { | |
Type: schema.TypeString, | |
Required: true, | |
}, | |
"layout": { | |
Type: schema.TypeList, | |
Required: true, | |
MaxItems: 1, | |
Elem: dashboardLayoutResource, | |
}, | |
}, | |
}, | |
}, | |
"alert_status": { | |
Type: schema.TypeList, | |
Optional: true, | |
Elem: &schema.Resource{ | |
Schema: map[string]*schema.Schema{ | |
"title": { | |
Type: schema.TypeString, | |
Required: true, | |
}, | |
"role_fullname": { | |
Type: schema.TypeString, | |
Required: true, | |
}, | |
"layout": { | |
Type: schema.TypeList, | |
Required: true, | |
MaxItems: 1, | |
Elem: dashboardLayoutResource, | |
}, | |
}, | |
}, | |
}, | |
}, |
return schema.Schema{ | ||
Description: "This data source allows access to details of a specific dashboard.", | ||
Attributes: map[string]schema.Attribute{ | ||
"id": schema.StringAttribute{ | ||
Description: schemaDashboardIDDesc, | ||
Required: true, | ||
}, | ||
"title": schema.StringAttribute{ | ||
Description: schemaDashboardTitleDesc, | ||
Computed: true, | ||
}, | ||
"memo": schema.StringAttribute{ | ||
Description: schemaDashboardMemoDesc, | ||
Computed: true, | ||
}, | ||
"url_path": schema.StringAttribute{ | ||
Description: schemaDashboardURLPathDesc, | ||
Computed: true, | ||
}, | ||
"created_at": schema.Int64Attribute{ | ||
Description: schemaDashboardCreatedAtDesc, | ||
Computed: true, | ||
}, | ||
"updated_at": schema.Int64Attribute{ | ||
Description: schemaDashboardUpdatedAtDesc, | ||
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_dashboard.go
Lines 137 to 336 in 2918d8d
Schema: map[string]*schema.Schema{ | |
"id": { | |
Type: schema.TypeString, | |
Required: true, | |
}, | |
"title": { | |
Type: schema.TypeString, | |
Computed: true, | |
}, | |
"memo": { | |
Type: schema.TypeString, | |
Computed: true, | |
}, | |
"url_path": { | |
Type: schema.TypeString, | |
Computed: true, | |
}, | |
"created_at": { | |
Type: schema.TypeInt, | |
Computed: true, | |
}, | |
"updated_at": { | |
Type: schema.TypeInt, | |
Computed: true, | |
}, | |
"graph": { | |
Type: schema.TypeList, | |
Computed: true, | |
Elem: &schema.Resource{ | |
Schema: map[string]*schema.Schema{ | |
"title": { | |
Type: schema.TypeString, | |
Computed: true, | |
}, | |
"host": { | |
Type: schema.TypeList, | |
Computed: true, | |
Elem: &schema.Resource{ | |
Schema: map[string]*schema.Schema{ | |
"host_id": { | |
Type: schema.TypeString, | |
Computed: true, | |
}, | |
"name": { | |
Type: schema.TypeString, | |
Computed: true, | |
}, | |
}, | |
}, | |
}, | |
"role": { | |
Type: schema.TypeList, | |
Computed: true, | |
Elem: &schema.Resource{ | |
Schema: map[string]*schema.Schema{ | |
"role_fullname": { | |
Type: schema.TypeString, | |
Computed: true, | |
}, | |
"name": { | |
Type: schema.TypeString, | |
Computed: true, | |
}, | |
"is_stacked": { | |
Type: schema.TypeBool, | |
Computed: true, | |
}, | |
}, | |
}, | |
}, | |
"service": { | |
Type: schema.TypeList, | |
Computed: true, | |
Elem: &schema.Resource{ | |
Schema: map[string]*schema.Schema{ | |
"service_name": { | |
Type: schema.TypeString, | |
Computed: true, | |
}, | |
"name": { | |
Type: schema.TypeString, | |
Computed: true, | |
}, | |
}, | |
}, | |
}, | |
"expression": { | |
Type: schema.TypeList, | |
Computed: true, | |
Elem: &schema.Resource{ | |
Schema: map[string]*schema.Schema{ | |
"expression": { | |
Type: schema.TypeString, | |
Computed: true, | |
}, | |
}, | |
}, | |
}, | |
"query": { | |
Type: schema.TypeList, | |
Computed: true, | |
Elem: &schema.Resource{ | |
Schema: map[string]*schema.Schema{ | |
"query": { | |
Type: schema.TypeString, | |
Computed: true, | |
}, | |
"legend": { | |
Type: schema.TypeString, | |
Computed: true, | |
}, | |
}, | |
}, | |
}, | |
"range": { | |
Type: schema.TypeList, | |
Computed: true, | |
Elem: dashboardRangeDataResource, | |
}, | |
"layout": { | |
Type: schema.TypeList, | |
Computed: true, | |
Elem: dashboardLayoutDataResource, | |
}, | |
}, | |
}, | |
}, | |
"value": { | |
Type: schema.TypeList, | |
Computed: true, | |
Elem: &schema.Resource{ | |
Schema: map[string]*schema.Schema{ | |
"title": { | |
Type: schema.TypeString, | |
Computed: true, | |
}, | |
"metric": { | |
Type: schema.TypeList, | |
Computed: true, | |
Elem: dashboardMetricDataResource, | |
}, | |
"fraction_size": { | |
Type: schema.TypeInt, | |
Computed: true, | |
}, | |
"suffix": { | |
Type: schema.TypeString, | |
Computed: true, | |
}, | |
"layout": { | |
Type: schema.TypeList, | |
Computed: true, | |
Elem: dashboardLayoutDataResource, | |
}, | |
}, | |
}, | |
}, | |
"markdown": { | |
Type: schema.TypeList, | |
Computed: true, | |
Elem: &schema.Resource{ | |
Schema: map[string]*schema.Schema{ | |
"title": { | |
Type: schema.TypeString, | |
Computed: true, | |
}, | |
"markdown": { | |
Type: schema.TypeString, | |
Computed: true, | |
}, | |
"layout": { | |
Type: schema.TypeList, | |
Computed: true, | |
Elem: dashboardLayoutDataResource, | |
}, | |
}, | |
}, | |
}, | |
"alert_status": { | |
Type: schema.TypeList, | |
Computed: true, | |
Elem: &schema.Resource{ | |
Schema: map[string]*schema.Schema{ | |
"title": { | |
Type: schema.TypeString, | |
Computed: true, | |
}, | |
"role_fullname": { | |
Type: schema.TypeString, | |
Computed: true, | |
}, | |
"layout": { | |
Type: schema.TypeList, | |
Computed: true, | |
Elem: dashboardLayoutDataResource, | |
}, | |
}, | |
}, | |
}, | |
}, |
github.com/hashicorp/terraform-plugin-framework v1.8.0 | ||
github.com/hashicorp/terraform-plugin-framework v1.11.0 |
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.
Embedded struct in a schema is supported from v1.11.0 (FYI: https://github.com/hashicorp/terraform-plugin-framework/releases/tag/v1.11.0).
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.
It seems almost ok, but just in case.
Since this is a migration, is it okay to leave the things that are not supported from the original as they are?
For example, there are valueRange
, formatRules
, referenceLines
and so on in help page.
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.
Thanks, LGTM 👍
Output from acceptance testing: