|
| 1 | +package dashboard_test |
| 2 | + |
| 3 | +import ( |
| 4 | + "testing" |
| 5 | + |
| 6 | + "github.com/elastic/terraform-provider-elasticstack/internal/acctest" |
| 7 | + "github.com/elastic/terraform-provider-elasticstack/internal/versionutils" |
| 8 | + "github.com/hashicorp/go-version" |
| 9 | + "github.com/hashicorp/terraform-plugin-testing/config" |
| 10 | + sdkacctest "github.com/hashicorp/terraform-plugin-testing/helper/acctest" |
| 11 | + "github.com/hashicorp/terraform-plugin-testing/helper/resource" |
| 12 | +) |
| 13 | + |
| 14 | +// Dashboard API is in technical preview and available from 9.2.x onwards |
| 15 | +var minDashboardAPISupport = version.Must(version.NewVersion("9.2.0")) |
| 16 | + |
| 17 | +func TestAccResourceEmptyDashboard(t *testing.T) { |
| 18 | + dashboardTitle := "Test Dashboard " + sdkacctest.RandStringFromCharSet(4, sdkacctest.CharSetAlphaNum) |
| 19 | + |
| 20 | + resource.Test(t, resource.TestCase{ |
| 21 | + PreCheck: func() { acctest.PreCheck(t) }, |
| 22 | + Steps: []resource.TestStep{ |
| 23 | + { |
| 24 | + ProtoV6ProviderFactories: acctest.Providers, |
| 25 | + SkipFunc: versionutils.CheckIfVersionIsUnsupported(minDashboardAPISupport), |
| 26 | + ConfigDirectory: acctest.NamedTestCaseDirectory("basic"), |
| 27 | + ConfigVariables: config.Variables{ |
| 28 | + "dashboard_title": config.StringVariable(dashboardTitle), |
| 29 | + }, |
| 30 | + Check: resource.ComposeTestCheckFunc( |
| 31 | + resource.TestCheckResourceAttrSet("elasticstack_kibana_dashboard.test", "id"), |
| 32 | + resource.TestCheckResourceAttrSet("elasticstack_kibana_dashboard.test", "dashboard_id"), |
| 33 | + resource.TestCheckResourceAttr("elasticstack_kibana_dashboard.test", "title", dashboardTitle), |
| 34 | + resource.TestCheckResourceAttr("elasticstack_kibana_dashboard.test", "description", "Test dashboard description"), |
| 35 | + resource.TestCheckResourceAttr("elasticstack_kibana_dashboard.test", "time_from", "now-15m"), |
| 36 | + resource.TestCheckResourceAttr("elasticstack_kibana_dashboard.test", "time_to", "now"), |
| 37 | + resource.TestCheckResourceAttr("elasticstack_kibana_dashboard.test", "refresh_interval_pause", "true"), |
| 38 | + resource.TestCheckResourceAttr("elasticstack_kibana_dashboard.test", "refresh_interval_value", "90000"), |
| 39 | + resource.TestCheckResourceAttr("elasticstack_kibana_dashboard.test", "query_language", "kuery"), |
| 40 | + resource.TestCheckResourceAttr("elasticstack_kibana_dashboard.test", "query_text", ""), |
| 41 | + ), |
| 42 | + }, |
| 43 | + { |
| 44 | + ProtoV6ProviderFactories: acctest.Providers, |
| 45 | + SkipFunc: versionutils.CheckIfVersionIsUnsupported(minDashboardAPISupport), |
| 46 | + ConfigDirectory: acctest.NamedTestCaseDirectory("updated"), |
| 47 | + ConfigVariables: config.Variables{ |
| 48 | + "dashboard_title": config.StringVariable(dashboardTitle + " Updated"), |
| 49 | + }, |
| 50 | + Check: resource.ComposeTestCheckFunc( |
| 51 | + resource.TestCheckResourceAttrSet("elasticstack_kibana_dashboard.test", "id"), |
| 52 | + resource.TestCheckResourceAttr("elasticstack_kibana_dashboard.test", "title", dashboardTitle+" Updated"), |
| 53 | + resource.TestCheckResourceAttr("elasticstack_kibana_dashboard.test", "description", "Updated dashboard description"), |
| 54 | + resource.TestCheckResourceAttr("elasticstack_kibana_dashboard.test", "time_from", "now-30m"), |
| 55 | + resource.TestCheckResourceAttr("elasticstack_kibana_dashboard.test", "time_to", "now"), |
| 56 | + resource.TestCheckResourceAttr("elasticstack_kibana_dashboard.test", "refresh_interval_pause", "false"), |
| 57 | + resource.TestCheckResourceAttr("elasticstack_kibana_dashboard.test", "refresh_interval_value", "30000"), |
| 58 | + ), |
| 59 | + }, |
| 60 | + { |
| 61 | + ProtoV6ProviderFactories: acctest.Providers, |
| 62 | + SkipFunc: versionutils.CheckIfVersionIsUnsupported(minDashboardAPISupport), |
| 63 | + ConfigDirectory: acctest.NamedTestCaseDirectory("with_options"), |
| 64 | + ConfigVariables: config.Variables{ |
| 65 | + "dashboard_title": config.StringVariable(dashboardTitle + " with Options"), |
| 66 | + }, |
| 67 | + Check: resource.ComposeTestCheckFunc( |
| 68 | + resource.TestCheckResourceAttrSet("elasticstack_kibana_dashboard.test", "id"), |
| 69 | + resource.TestCheckResourceAttr("elasticstack_kibana_dashboard.test", "title", dashboardTitle+" with Options"), |
| 70 | + resource.TestCheckResourceAttr("elasticstack_kibana_dashboard.test", "time_from", "2024-01-01T00:00:00.000Z"), |
| 71 | + resource.TestCheckResourceAttr("elasticstack_kibana_dashboard.test", "time_to", "2024-01-01T01:00:00.000Z"), |
| 72 | + resource.TestCheckResourceAttr("elasticstack_kibana_dashboard.test", "time_range_mode", "absolute"), |
| 73 | + resource.TestCheckResourceAttr("elasticstack_kibana_dashboard.test", "options.hide_panel_titles", "true"), |
| 74 | + resource.TestCheckResourceAttr("elasticstack_kibana_dashboard.test", "options.use_margins", "false"), |
| 75 | + resource.TestCheckResourceAttr("elasticstack_kibana_dashboard.test", "options.sync_colors", "true"), |
| 76 | + resource.TestCheckResourceAttr("elasticstack_kibana_dashboard.test", "options.sync_tooltips", "true"), |
| 77 | + ), |
| 78 | + }, |
| 79 | + { |
| 80 | + ProtoV6ProviderFactories: acctest.Providers, |
| 81 | + SkipFunc: versionutils.CheckIfVersionIsUnsupported(minDashboardAPISupport), |
| 82 | + ConfigDirectory: acctest.NamedTestCaseDirectory("with_options"), |
| 83 | + ConfigVariables: config.Variables{ |
| 84 | + "dashboard_title": config.StringVariable(dashboardTitle + " with Options"), |
| 85 | + }, |
| 86 | + ResourceName: "elasticstack_kibana_dashboard.test", |
| 87 | + ImportState: true, |
| 88 | + ImportStateVerify: true, |
| 89 | + ImportStateVerifyIgnore: []string{"time_range_mode"}, |
| 90 | + }, |
| 91 | + }, |
| 92 | + }) |
| 93 | +} |
| 94 | + |
| 95 | +func TestAccResourceDashboardInSpace(t *testing.T) { |
| 96 | + spaceName := "test-space-" + sdkacctest.RandStringFromCharSet(4, sdkacctest.CharSetAlphaNum) |
| 97 | + dashboardTitle := "Test Dashboard in Space " + sdkacctest.RandStringFromCharSet(4, sdkacctest.CharSetAlphaNum) |
| 98 | + |
| 99 | + resource.Test(t, resource.TestCase{ |
| 100 | + PreCheck: func() { acctest.PreCheck(t) }, |
| 101 | + Steps: []resource.TestStep{ |
| 102 | + { |
| 103 | + ProtoV6ProviderFactories: acctest.Providers, |
| 104 | + SkipFunc: versionutils.CheckIfVersionIsUnsupported(minDashboardAPISupport), |
| 105 | + ConfigDirectory: acctest.NamedTestCaseDirectory("in_space"), |
| 106 | + ConfigVariables: config.Variables{ |
| 107 | + "space_name": config.StringVariable(spaceName), |
| 108 | + "dashboard_title": config.StringVariable(dashboardTitle), |
| 109 | + }, |
| 110 | + Check: resource.ComposeTestCheckFunc( |
| 111 | + resource.TestCheckResourceAttrSet("elasticstack_kibana_dashboard.test_space", "id"), |
| 112 | + resource.TestCheckResourceAttr("elasticstack_kibana_dashboard.test_space", "space_id", spaceName), |
| 113 | + resource.TestCheckResourceAttr("elasticstack_kibana_dashboard.test_space", "title", dashboardTitle), |
| 114 | + ), |
| 115 | + }, |
| 116 | + { |
| 117 | + ProtoV6ProviderFactories: acctest.Providers, |
| 118 | + SkipFunc: versionutils.CheckIfVersionIsUnsupported(minDashboardAPISupport), |
| 119 | + ConfigDirectory: acctest.NamedTestCaseDirectory("in_space"), |
| 120 | + ConfigVariables: config.Variables{ |
| 121 | + "space_name": config.StringVariable(spaceName), |
| 122 | + "dashboard_title": config.StringVariable(dashboardTitle), |
| 123 | + }, |
| 124 | + ResourceName: "elasticstack_kibana_dashboard.test_space", |
| 125 | + ImportState: true, |
| 126 | + ImportStateVerify: true, |
| 127 | + }, |
| 128 | + }, |
| 129 | + }) |
| 130 | +} |
0 commit comments