diff --git a/newrelic/data_source_newrelic_key_transaction.go b/newrelic/data_source_newrelic_key_transaction.go index 50458742b..c604d09a5 100644 --- a/newrelic/data_source_newrelic_key_transaction.go +++ b/newrelic/data_source_newrelic_key_transaction.go @@ -34,13 +34,11 @@ func dataSourceNewRelicKeyTransaction() *schema.Resource { }, "domain": { Type: schema.TypeString, - Required: false, Computed: true, Description: "The Domain of the key transaction in New Relic.", }, "type": { Type: schema.TypeString, - Required: false, Computed: true, Description: "The Entity type of the key transaction in New Relic.", }, diff --git a/newrelic/resource_newrelic_entity_tags_test.go b/newrelic/resource_newrelic_entity_tags_test.go index a7f53b648..6119bc4b2 100644 --- a/newrelic/resource_newrelic_entity_tags_test.go +++ b/newrelic/resource_newrelic_entity_tags_test.go @@ -6,12 +6,13 @@ package newrelic import ( "context" "fmt" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" - "github.com/newrelic/newrelic-client-go/v2/pkg/common" "regexp" "testing" "time" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" + "github.com/newrelic/newrelic-client-go/v2/pkg/common" ) func TestAccNewRelicEntityTags_Basic(t *testing.T) { diff --git a/newrelic/resource_newrelic_group_management.go b/newrelic/resource_newrelic_group_management.go index f6acadae5..b4ff0706e 100644 --- a/newrelic/resource_newrelic_group_management.go +++ b/newrelic/resource_newrelic_group_management.go @@ -42,7 +42,6 @@ func resourceNewRelicGroup() *schema.Resource { Type: schema.TypeSet, Description: "IDs of users to be added to the group.", Optional: true, - Default: nil, Elem: &schema.Schema{Type: schema.TypeString}, }, }, diff --git a/newrelic/resource_newrelic_key_transaction.go b/newrelic/resource_newrelic_key_transaction.go index 4badbeb8a..e72552512 100644 --- a/newrelic/resource_newrelic_key_transaction.go +++ b/newrelic/resource_newrelic_key_transaction.go @@ -52,13 +52,11 @@ func resourceNewRelicKeyTransaction() *schema.Resource { "domain": { Type: schema.TypeString, Description: "Domain of the entity.", - Required: false, Computed: true, }, "type": { Type: schema.TypeString, Description: "Type of the entity.", - Required: false, Computed: true, }, }, diff --git a/newrelic/resource_newrelic_one_dashboard.go b/newrelic/resource_newrelic_one_dashboard.go index a78248e31..4d4bc710b 100644 --- a/newrelic/resource_newrelic_one_dashboard.go +++ b/newrelic/resource_newrelic_one_dashboard.go @@ -2,8 +2,9 @@ package newrelic import ( "context" - "log" + "fmt" + "github.com/hashicorp/terraform-plugin-log/tflog" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" @@ -136,7 +137,7 @@ func dashboardVariableSchemaElem() *schema.Resource { }, }, "nrql_query": { - Type: schema.TypeList, + Type: schema.TypeSet, Optional: true, Description: "Configuration for variables of type NRQL.", MaxItems: 1, @@ -186,6 +187,7 @@ func dashboardPageSchemaElem() *schema.Resource { "description": { Type: schema.TypeString, Optional: true, + Default: "", Description: "The dashboard page's description.", }, "name": { @@ -201,85 +203,85 @@ func dashboardPageSchemaElem() *schema.Resource { // All the widget types below "widget_area": { - Type: schema.TypeList, + Type: schema.TypeSet, Optional: true, Description: "An area widget.", Elem: dashboardWidgetAreaSchemaElem(), }, "widget_bar": { - Type: schema.TypeList, + Type: schema.TypeSet, Optional: true, Description: "A bar widget.", Elem: dashboardWidgetBarSchemaElem(), }, "widget_billboard": { - Type: schema.TypeList, + Type: schema.TypeSet, Optional: true, Description: "A billboard widget.", Elem: dashboardWidgetBillboardSchemaElem(), }, "widget_bullet": { - Type: schema.TypeList, + Type: schema.TypeSet, Optional: true, Description: "A bullet widget.", Elem: dashboardWidgetBulletSchemaElem(), }, "widget_funnel": { - Type: schema.TypeList, + Type: schema.TypeSet, Optional: true, Description: "A funnel widget.", Elem: dashboardWidgetFunnelSchemaElem(), }, "widget_heatmap": { - Type: schema.TypeList, + Type: schema.TypeSet, Optional: true, Description: "A heatmap widget.", Elem: dashboardWidgetHeatmapSchemaElem(), }, "widget_histogram": { - Type: schema.TypeList, + Type: schema.TypeSet, Optional: true, Description: "A histogram widget.", Elem: dashboardWidgetHistogramSchemaElem(), }, "widget_line": { - Type: schema.TypeList, + Type: schema.TypeSet, Optional: true, Description: "A line widget.", Elem: dashboardWidgetLineSchemaElem(), }, "widget_markdown": { - Type: schema.TypeList, + Type: schema.TypeSet, Optional: true, Description: "A markdown widget.", Elem: dashboardWidgetMarkdownSchemaElem(), }, "widget_pie": { - Type: schema.TypeList, + Type: schema.TypeSet, Optional: true, Description: "A pie widget.", Elem: dashboardWidgetPieSchemaElem(), }, "widget_log_table": { - Type: schema.TypeList, + Type: schema.TypeSet, Optional: true, Description: "A log table widget.", Elem: dashboardWidgetLogTableSchemaElem(), }, "widget_table": { - Type: schema.TypeList, + Type: schema.TypeSet, Optional: true, Description: "A table widget.", Elem: dashboardWidgetTableSchemaElem(), }, "widget_json": { - Type: schema.TypeList, + Type: schema.TypeSet, Optional: true, Description: "A JSON widget.", Elem: dashboardWidgetJSONSchemaElem(), }, "widget_stacked_bar": { - Type: schema.TypeList, + Type: schema.TypeSet, Optional: true, Description: "A stacked bar widget.", Elem: dashboardWidgetStackedBarSchemaElem(), @@ -345,10 +347,12 @@ func dashboardWidgetSchemaBase() map[string]*schema.Schema { "ignore_time_range": { Type: schema.TypeBool, Optional: true, + Default: false, }, "facet_show_other_series": { Type: schema.TypeBool, Optional: true, + Default: false, }, "legend_enabled": { Type: schema.TypeBool, @@ -358,10 +362,12 @@ func dashboardWidgetSchemaBase() map[string]*schema.Schema { "y_axis_left_min": { Type: schema.TypeFloat, Optional: true, + Default: 0, }, "y_axis_left_max": { Type: schema.TypeFloat, Optional: true, + Default: 0, }, "null_values": { Type: schema.TypeList, @@ -520,7 +526,6 @@ func dashboardWidgetNRQLQuerySchemaElem() *schema.Resource { Schema: map[string]*schema.Schema{ "account_id": { Type: schema.TypeInt, - Optional: true, Computed: true, Description: "The account id used for the NRQL query.", }, @@ -558,12 +563,14 @@ func dashboardWidgetBillboardSchemaElem() *schema.Resource { s["critical"] = &schema.Schema{ Type: schema.TypeString, Optional: true, + Default: "", Description: "The critical threshold value.", } s["warning"] = &schema.Schema{ Type: schema.TypeString, Optional: true, + Default: "", Description: "The warning threshold value.", } @@ -619,12 +626,14 @@ func dashboardWidgetLineSchemaElem() *schema.Resource { s["y_axis_left_zero"] = &schema.Schema{ Type: schema.TypeBool, Optional: true, + Default: false, Description: "Specifies if the values on the graph to be rendered need to be fit to scale, or printed within the specified range.", } s["is_label_visible"] = &schema.Schema{ Type: schema.TypeBool, Optional: true, + Default: false, Description: "Specified if the label should be visible in the graph created when specified with thresholds.", } @@ -805,7 +814,6 @@ func dashboardWidgetLinkedEntityGUIDsSchema() *schema.Schema { Elem: &schema.Schema{ Type: schema.TypeString, }, - Optional: true, Computed: true, Description: "Related entities. Currently only supports Dashboard entities, but may allow other cases in the future.", } @@ -815,6 +823,7 @@ func dashboardWidgetFilterCurrentDashboardSchema() *schema.Schema { return &schema.Schema{ Type: schema.TypeBool, Optional: true, + Default: false, Description: "Use this item to filter the current dashboard", } } @@ -837,7 +846,7 @@ func resourceNewRelicOneDashboardCreate(ctx context.Context, d *schema.ResourceD return diag.FromErr(err) } - log.Printf("[INFO] Creating New Relic One dashboard: %s", dashboard.Name) + tflog.Info(ctx, fmt.Sprintf("Creating New Relic One dashboard: %s", dashboard.Name)) created, err := client.Dashboards.DashboardCreateWithContext(ctx, accountID, *dashboard) if err != nil { @@ -853,7 +862,7 @@ func resourceNewRelicOneDashboardCreate(ctx context.Context, d *schema.ResourceD return diag.Errorf("err: newrelic_one_dashboard Create failed: %s", errMessages) } - log.Printf("[INFO] New Dashboard GUID: %s", guid) + tflog.Info(ctx, fmt.Sprintf("New Dashboard GUID: %s", guid)) d.SetId(string(guid)) @@ -862,7 +871,7 @@ func resourceNewRelicOneDashboardCreate(ctx context.Context, d *schema.ResourceD return diag.FromErr(err) } - log.Printf("[INFO] Number of widgets with filter_current_dashboard: %d", len(filterWidgets)) + tflog.Info(ctx, fmt.Sprintf("Number of widgets with filter_current_dashboard: %d", len(filterWidgets))) if len(filterWidgets) > 0 { err = setDashboardWidgetFilterCurrentDashboardLinkedEntity(d, filterWidgets) @@ -892,7 +901,7 @@ func resourceNewRelicOneDashboardRead(ctx context.Context, d *schema.ResourceDat providerConfig := meta.(*ProviderConfig) client := providerConfig.NewClient - log.Printf("[INFO] Reading New Relic One dashboard %s", d.Id()) + tflog.Info(ctx, fmt.Sprintf("Reading New Relic One dashboard %s", d.Id())) dashboard, err := client.Dashboards.GetDashboardEntityWithContext(ctx, common.EntityGUID(d.Id())) @@ -933,7 +942,7 @@ func resourceNewRelicOneDashboardUpdate(ctx context.Context, d *schema.ResourceD return diag.FromErr(err) } - log.Printf("[INFO] Updating New Relic One dashboard '%s' (%s)", dashboard.Name, d.Id()) + tflog.Info(ctx, fmt.Sprintf("Updating New Relic One dashboard '%s' (%s)", dashboard.Name, d.Id())) updated, err := client.Dashboards.DashboardUpdateWithContext(ctx, *dashboard, common.EntityGUID(d.Id())) if err != nil { @@ -955,7 +964,7 @@ func resourceNewRelicOneDashboardUpdate(ctx context.Context, d *schema.ResourceD return diagErr } - log.Printf("[INFO] Number of widgets with filter_current_dashboard: %d", len(filterWidgets)) + tflog.Info(ctx, fmt.Sprintf("Number of widgets with filter_current_dashboard: %d", len(filterWidgets))) // If there are widgets with filter_current_dashboard, we need to update the linked guid entities if len(filterWidgets) > 0 { err = setDashboardWidgetFilterCurrentDashboardLinkedEntity(d, filterWidgets) @@ -982,7 +991,7 @@ func resourceNewRelicOneDashboardUpdate(ctx context.Context, d *schema.ResourceD func resourceNewRelicOneDashboardDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { client := meta.(*ProviderConfig).NewClient - log.Printf("[INFO] Deleting New Relic One dashboard %v", d.Id()) + tflog.Info(ctx, fmt.Sprintf("Deleting New Relic One dashboard %v", d.Id())) if _, err := client.Dashboards.DashboardDeleteWithContext(ctx, common.EntityGUID(d.Id())); err != nil { if _, ok := err.(*errors.NotFound); ok { diff --git a/newrelic/structures_newrelic_one_dashboard.go b/newrelic/structures_newrelic_one_dashboard.go index f97c85e9d..c502a49ab 100644 --- a/newrelic/structures_newrelic_one_dashboard.go +++ b/newrelic/structures_newrelic_one_dashboard.go @@ -202,7 +202,7 @@ func expandDashboardPageInput(d *schema.ResourceData, pages []interface{}, meta page.Widgets = []dashboards.DashboardWidgetInput{} // For each of the widget type, we need to expand them as well if widgets, ok := p["widget_area"]; ok { - for _, v := range widgets.([]interface{}) { + for _, v := range widgets.(*schema.Set).List() { // Get generic properties set widget, rawConfiguration, err := expandDashboardWidgetInput(v.(map[string]interface{}), meta, "viz.area") if err != nil { @@ -218,7 +218,7 @@ func expandDashboardPageInput(d *schema.ResourceData, pages []interface{}, meta } } if widgets, ok := p["widget_bar"]; ok { - for _, v := range widgets.([]interface{}) { + for _, v := range widgets.(*schema.Set).List() { // Get generic properties set widget, rawConfiguration, err := expandDashboardWidgetInput(v.(map[string]interface{}), meta, "viz.bar") if err != nil { @@ -234,7 +234,7 @@ func expandDashboardPageInput(d *schema.ResourceData, pages []interface{}, meta } } if widgets, ok := p["widget_billboard"]; ok { - for widgetIndex, v := range widgets.([]interface{}) { + for widgetIndex, v := range widgets.(*schema.Set).List() { // Get generic properties set widget, rawConfiguration, err := expandDashboardWidgetInput(v.(map[string]interface{}), meta, "viz.billboard") if err != nil { @@ -255,7 +255,7 @@ func expandDashboardPageInput(d *schema.ResourceData, pages []interface{}, meta } } if widgets, ok := p["widget_bullet"]; ok { - for _, v := range widgets.([]interface{}) { + for _, v := range widgets.(*schema.Set).List() { // Get generic properties set widget, rawConfiguration, err := expandDashboardWidgetInput(v.(map[string]interface{}), meta, "viz.bullet") if err != nil { @@ -271,7 +271,7 @@ func expandDashboardPageInput(d *schema.ResourceData, pages []interface{}, meta } } if widgets, ok := p["widget_funnel"]; ok { - for _, v := range widgets.([]interface{}) { + for _, v := range widgets.(*schema.Set).List() { // Get generic properties set widget, rawConfiguration, err := expandDashboardWidgetInput(v.(map[string]interface{}), meta, "viz.funnel") if err != nil { @@ -287,7 +287,7 @@ func expandDashboardPageInput(d *schema.ResourceData, pages []interface{}, meta } } if widgets, ok := p["widget_heatmap"]; ok { - for _, v := range widgets.([]interface{}) { + for _, v := range widgets.(*schema.Set).List() { // Get generic properties set widget, rawConfiguration, err := expandDashboardWidgetInput(v.(map[string]interface{}), meta, "viz.heatmap") if err != nil { @@ -303,7 +303,7 @@ func expandDashboardPageInput(d *schema.ResourceData, pages []interface{}, meta } } if widgets, ok := p["widget_histogram"]; ok { - for _, v := range widgets.([]interface{}) { + for _, v := range widgets.(*schema.Set).List() { // Get generic properties set widget, rawConfiguration, err := expandDashboardWidgetInput(v.(map[string]interface{}), meta, "viz.histogram") if err != nil { @@ -319,7 +319,7 @@ func expandDashboardPageInput(d *schema.ResourceData, pages []interface{}, meta } } if widgets, ok := p["widget_line"]; ok { - for widgetIndex, v := range widgets.([]interface{}) { + for widgetIndex, v := range widgets.(*schema.Set).List() { // Get generic properties set widget, rawConfiguration, err := expandDashboardWidgetInput(v.(map[string]interface{}), meta, "viz.line") if err != nil { @@ -337,7 +337,7 @@ func expandDashboardPageInput(d *schema.ResourceData, pages []interface{}, meta } } if widgets, ok := p["widget_markdown"]; ok { - for _, v := range widgets.([]interface{}) { + for _, v := range widgets.(*schema.Set).List() { // Get generic properties set widget, rawConfiguration, err := expandDashboardWidgetInput(v.(map[string]interface{}), meta, "viz.markdown") if err != nil { @@ -353,7 +353,7 @@ func expandDashboardPageInput(d *schema.ResourceData, pages []interface{}, meta } } if widgets, ok := p["widget_pie"]; ok { - for _, v := range widgets.([]interface{}) { + for _, v := range widgets.(*schema.Set).List() { // Get generic properties set widget, rawConfiguration, err := expandDashboardWidgetInput(v.(map[string]interface{}), meta, "viz.pie") if err != nil { @@ -369,7 +369,7 @@ func expandDashboardPageInput(d *schema.ResourceData, pages []interface{}, meta } } if widgets, ok := p["widget_table"]; ok { - for widgetIndex, v := range widgets.([]interface{}) { + for widgetIndex, v := range widgets.(*schema.Set).List() { // Get generic properties set widget, rawConfiguration, err := expandDashboardWidgetInput(v.(map[string]interface{}), meta, "viz.table") if err != nil { @@ -392,7 +392,7 @@ func expandDashboardPageInput(d *schema.ResourceData, pages []interface{}, meta } } if widgets, ok := p["widget_log_table"]; ok { - for _, v := range widgets.([]interface{}) { + for _, v := range widgets.(*schema.Set).List() { // Get generic properties set widget, rawConfiguration, err := expandDashboardWidgetInput(v.(map[string]interface{}), meta, "logger.log-table-widget") if err != nil { @@ -408,7 +408,7 @@ func expandDashboardPageInput(d *schema.ResourceData, pages []interface{}, meta } } if widgets, ok := p["widget_json"]; ok { - for _, v := range widgets.([]interface{}) { + for _, v := range widgets.(*schema.Set).List() { // Get generic properties set widget, rawConfiguration, err := expandDashboardWidgetInput(v.(map[string]interface{}), meta, "viz.json") if err != nil { @@ -424,7 +424,7 @@ func expandDashboardPageInput(d *schema.ResourceData, pages []interface{}, meta } } if widgets, ok := p["widget_stacked_bar"]; ok { - for _, v := range widgets.([]interface{}) { + for _, v := range widgets.(*schema.Set).List() { // Get generic properties set widget, rawConfiguration, err := expandDashboardWidgetInput(v.(map[string]interface{}), meta, "viz.stacked-bar") if err != nil { @@ -1577,7 +1577,7 @@ func findDashboardWidgetFilterCurrentDashboard(d *schema.ResourceData) ([]interf // For each of the widget type, we need to expand them as well for _, widgetType := range selfLinkingWidgets { if widgets, ok := p[widgetType]; ok { - for _, widget := range widgets.([]interface{}) { + for _, widget := range widgets.(*schema.Set).List() { w := widget.(map[string]interface{}) if v, ok := w["filter_current_dashboard"]; ok && v.(bool) { @@ -1627,7 +1627,7 @@ func setDashboardWidgetFilterCurrentDashboardLinkedEntity(d *schema.ResourceData p := v.(map[string]interface{}) for _, widgetType := range selfLinkingWidgets { if widgets, ok := p[widgetType]; ok { - for _, k := range widgets.([]interface{}) { + for _, k := range widgets.(*schema.Set).List() { w := k.(map[string]interface{}) if l, ok := w["linked_entity_guids"]; ok && len(l.([]interface{})) == 1 { for _, le := range l.([]interface{}) {