|
| 1 | +package parameter_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-sdk/v2/helper/resource" |
| 10 | +) |
| 11 | + |
| 12 | +const ( |
| 13 | + providerConfig = ` |
| 14 | +provider "elasticstack" { |
| 15 | + kibana {} |
| 16 | +} |
| 17 | +` |
| 18 | +) |
| 19 | + |
| 20 | +var ( |
| 21 | + minKibanaParameterAPIVersion = version.Must(version.NewVersion("8.12.0")) |
| 22 | +) |
| 23 | + |
| 24 | +func TestSyntheticParameterResource(t *testing.T) { |
| 25 | + resourceId := "elasticstack_kibana_synthetics_parameter.test" |
| 26 | + resource.Test(t, resource.TestCase{ |
| 27 | + PreCheck: func() { acctest.PreCheck(t) }, |
| 28 | + ProtoV6ProviderFactories: acctest.Providers, |
| 29 | + Steps: []resource.TestStep{ |
| 30 | + // Create and Read testing |
| 31 | + { |
| 32 | + SkipFunc: versionutils.CheckIfVersionIsUnsupported(minKibanaParameterAPIVersion), |
| 33 | + Config: providerConfig + ` |
| 34 | +resource "elasticstack_kibana_synthetics_parameter" "test" { |
| 35 | + key = "test-key" |
| 36 | + value = "test-value" |
| 37 | + description = "Test description" |
| 38 | + tags = ["a", "b"] |
| 39 | +} |
| 40 | +`, |
| 41 | + Check: resource.ComposeAggregateTestCheckFunc( |
| 42 | + resource.TestCheckResourceAttr(resourceId, "key", "test-key"), |
| 43 | + resource.TestCheckResourceAttr(resourceId, "value", "test-value"), |
| 44 | + resource.TestCheckResourceAttr(resourceId, "description", "Test description"), |
| 45 | + resource.TestCheckResourceAttr(resourceId, "tags.#", "2"), |
| 46 | + resource.TestCheckResourceAttr(resourceId, "tags.0", "a"), |
| 47 | + resource.TestCheckResourceAttr(resourceId, "tags.1", "b"), |
| 48 | + ), |
| 49 | + }, |
| 50 | + // ImportState testing |
| 51 | + { |
| 52 | + SkipFunc: versionutils.CheckIfVersionIsUnsupported(minKibanaParameterAPIVersion), |
| 53 | + ResourceName: resourceId, |
| 54 | + ImportState: true, |
| 55 | + ImportStateVerify: true, |
| 56 | + Config: providerConfig + ` |
| 57 | +resource "elasticstack_kibana_synthetics_parameter" "test" { |
| 58 | + key = "test-key" |
| 59 | + value = "test-value" |
| 60 | + description = "Test description" |
| 61 | + tags = ["a", "b"] |
| 62 | +} |
| 63 | +`, |
| 64 | + }, |
| 65 | + // Update and Read testing |
| 66 | + { |
| 67 | + SkipFunc: versionutils.CheckIfVersionIsUnsupported(minKibanaParameterAPIVersion), |
| 68 | + Config: providerConfig + ` |
| 69 | +resource "elasticstack_kibana_synthetics_parameter" "test" { |
| 70 | + key = "test-key-2" |
| 71 | + value = "test-value-2" |
| 72 | + description = "Test description 2" |
| 73 | + tags = ["c", "d", "e"] |
| 74 | +} |
| 75 | +`, |
| 76 | + Check: resource.ComposeAggregateTestCheckFunc( |
| 77 | + resource.TestCheckResourceAttr(resourceId, "key", "test-key-2"), |
| 78 | + resource.TestCheckResourceAttr(resourceId, "value", "test-value-2"), |
| 79 | + resource.TestCheckResourceAttr(resourceId, "description", "Test description 2"), |
| 80 | + resource.TestCheckResourceAttr(resourceId, "tags.#", "3"), |
| 81 | + resource.TestCheckResourceAttr(resourceId, "tags.0", "c"), |
| 82 | + resource.TestCheckResourceAttr(resourceId, "tags.1", "d"), |
| 83 | + resource.TestCheckResourceAttr(resourceId, "tags.2", "e"), |
| 84 | + ), |
| 85 | + }, |
| 86 | + // Delete testing automatically occurs in TestCase |
| 87 | + }, |
| 88 | + }) |
| 89 | +} |
0 commit comments