diff --git a/.buildkite/scripts/update-kibana-client.sh b/.buildkite/scripts/update-kibana-client.sh new file mode 100644 index 000000000..a88d9c80e --- /dev/null +++ b/.buildkite/scripts/update-kibana-client.sh @@ -0,0 +1,29 @@ +#!/bin/bash + +set -euo pipefail + +source /etc/profile.d/go.sh + +echo "--- Regenerating the Kibana client" +make -C generated/kbapi all + +echo "--- Building the provider" +make build + +echo "--- Starting Stack containers" +make docker-fleet +docker ps +sleep 30 + +echo "--- Collecting docker info" +docker ps +docker logs terraform-elasticstack-kb 2>&1 > kibana.log +docker logs terraform-elasticstack-es 2>&1 > es.log +docker logs terraform-elasticstack-fleet 2>&1 > fleet.log + +buildkite-agent artifact upload kibana.log +buildkite-agent artifact upload es.log +buildkite-agent artifact upload fleet.log + +echo "--- Running acceptance tests" +ELASTICSEARCH_ENDPOINTS=http://localhost:9200 KIBANA_ENDPOINT=http://localhost:5601 ELASTICSEARCH_USERNAME=elastic ELASTICSEARCH_PASSWORD=password make testacc diff --git a/.buildkite/update-kibana-client.yml b/.buildkite/update-kibana-client.yml index 60e96bcc7..33b488b28 100644 --- a/.buildkite/update-kibana-client.yml +++ b/.buildkite/update-kibana-client.yml @@ -1,12 +1,8 @@ agents: provider: "gcp" machineType: "n1-standard-4" - image: family/managed-intake-service-ubuntu-2204 + image: family/terraform-provider-elasticstack-ubuntu-2204 steps: - label: Regenerate Kibana client and build provider command: - - "make -C generated/kbapi all" - - "make build" - - "make test" - - "make docker-fleet" - - "make testacc" \ No newline at end of file + - ".buildkite/scripts/update-kibana-client.sh" \ No newline at end of file diff --git a/Makefile b/Makefile index 2db9f32b2..345e8613a 100644 --- a/Makefile +++ b/Makefile @@ -54,7 +54,7 @@ build: lint build-ci ## build the terraform provider .PHONY: testacc testacc: ## Run acceptance tests - TF_ACC=1 go test -v ./... -count $(ACCTEST_COUNT) -parallel $(ACCTEST_PARALLELISM) $(TESTARGS) -timeout $(ACCTEST_TIMEOUT) + TF_ACC=1 go tool gotestsum --format testname --rerun-fails=3 --packages="-v ./..." -- -count $(ACCTEST_COUNT) -parallel $(ACCTEST_PARALLELISM) $(TESTARGS) -timeout $(ACCTEST_TIMEOUT) .PHONY: test test: ## Run unit tests diff --git a/go.mod b/go.mod index 387aee1dd..7cae924bf 100644 --- a/go.mod +++ b/go.mod @@ -106,6 +106,7 @@ require ( github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect github.com/bahlo/generic-list-go v0.2.0 // indirect github.com/bgentry/speakeasy v0.1.0 // indirect + github.com/bitfield/gotestdox v0.2.2 // indirect github.com/blacktop/go-dwarf v1.0.10 // indirect github.com/blacktop/go-macho v1.1.238 // indirect github.com/blakesmith/ar v0.0.0-20190502131153-809d4375e1fb // indirect @@ -145,6 +146,7 @@ require ( github.com/digitorus/timestamp v0.0.0-20231217203849-220c5c2851b7 // indirect github.com/dimchansky/utfbom v1.1.1 // indirect github.com/distribution/reference v0.6.0 // indirect + github.com/dnephin/pflag v1.0.7 // indirect github.com/docker/cli v28.1.1+incompatible // indirect github.com/docker/distribution v2.8.3+incompatible // indirect github.com/docker/docker v28.1.1+incompatible // indirect @@ -159,7 +161,7 @@ require ( github.com/envoyproxy/protoc-gen-validate v1.2.1 // indirect github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f // indirect github.com/evanphx/json-patch/v5 v5.9.11 // indirect - github.com/fatih/color v1.17.0 // indirect + github.com/fatih/color v1.18.0 // indirect github.com/felixge/httpsnoop v1.0.4 // indirect github.com/fsnotify/fsnotify v1.9.0 // indirect github.com/gabriel-vasile/mimetype v1.4.8 // indirect @@ -202,6 +204,7 @@ require ( github.com/google/rpmpack v0.7.0 // indirect github.com/google/s2a-go v0.1.9 // indirect github.com/google/safetext v0.0.0-20240722112252-5a72de7e7962 // indirect + github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 // indirect github.com/google/wire v0.6.0 // indirect github.com/googleapis/enterprise-certificate-proxy v0.3.6 // indirect github.com/googleapis/gax-go/v2 v2.14.1 // indirect @@ -398,6 +401,7 @@ require ( gopkg.in/warnings.v0 v0.1.2 // indirect gopkg.in/yaml.v2 v2.4.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect + gotest.tools/gotestsum v1.13.0 // indirect k8s.io/klog/v2 v2.130.1 // indirect lukechampine.com/blake3 v1.2.1 // indirect sigs.k8s.io/kind v0.27.0 // indirect @@ -412,4 +416,5 @@ tool ( github.com/hashicorp/terraform-plugin-docs/cmd/tfplugindocs github.com/oapi-codegen/oapi-codegen/v2/cmd/oapi-codegen go.uber.org/mock/mockgen + gotest.tools/gotestsum ) diff --git a/go.sum b/go.sum index d84977261..9428b20b0 100644 --- a/go.sum +++ b/go.sum @@ -217,6 +217,8 @@ github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM= github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw= github.com/bgentry/speakeasy v0.1.0 h1:ByYyxL9InA1OWqxJqqp2A5pYHUrCiAL6K3J+LKSsQkY= github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kBD4zp0CCIs= +github.com/bitfield/gotestdox v0.2.2 h1:x6RcPAbBbErKLnapz1QeAlf3ospg8efBsedU93CDsnE= +github.com/bitfield/gotestdox v0.2.2/go.mod h1:D+gwtS0urjBrzguAkTM2wodsTQYFHdpx8eqRJ3N+9pY= github.com/blacktop/go-dwarf v1.0.10 h1:i9zYgcIROETsNZ6V+zZn3uDH21FCG5BLLZ837GitxS0= github.com/blacktop/go-dwarf v1.0.10/go.mod h1:4W2FKgSFYcZLDwnR7k+apv5i3nrau4NGl9N6VQ9DSTo= github.com/blacktop/go-macho v1.1.238 h1:OFfT6NB/SWxkoky7L/ytuY8QekgFpa9pmz/GHUQLsmM= @@ -329,6 +331,8 @@ github.com/distribution/distribution/v3 v3.0.0 h1:q4R8wemdRQDClzoNNStftB2ZAfqOiN github.com/distribution/distribution/v3 v3.0.0/go.mod h1:tRNuFoZsUdyRVegq8xGNeds4KLjwLCRin/tTo6i1DhU= github.com/distribution/reference v0.6.0 h1:0IXCQ5g4/QMHHkarYzh5l+u8T3t73zM5QvfrDyIgxBk= github.com/distribution/reference v0.6.0/go.mod h1:BbU0aIcezP1/5jX/8MP0YiH4SdvB5Y4f/wlDRiLyi3E= +github.com/dnephin/pflag v1.0.7 h1:oxONGlWxhmUct0YzKTgrpQv9AUA1wtPBn7zuSjJqptk= +github.com/dnephin/pflag v1.0.7/go.mod h1:uxE91IoWURlOiTUIA8Mq5ZZkAv3dPUfZNaT80Zm7OQE= github.com/docker/cli v28.1.1+incompatible h1:eyUemzeI45DY7eDPuwUcmDyDj1pM98oD5MdSpiItp8k= github.com/docker/cli v28.1.1+incompatible/go.mod h1:JLrzqnKDaYBop7H2jaqPtU4hHvMKP+vjCwu2uszcLI8= github.com/docker/distribution v2.8.3+incompatible h1:AtKxIZ36LoNK51+Z6RpzLpddBirtxJnzDrHLEKxTAYk= @@ -377,6 +381,8 @@ github.com/evanphx/json-patch/v5 v5.9.11/go.mod h1:3j+LviiESTElxA4p3EMKAB9HXj3/X github.com/fatih/color v1.13.0/go.mod h1:kLAiJbzzSOZDVNGyDpeOxJ47H46qBXwg5ILebYFFOfk= github.com/fatih/color v1.17.0 h1:GlRw1BRJxkpqUCBKzKOw098ed57fEsKeNjpTe3cSjK4= github.com/fatih/color v1.17.0/go.mod h1:YZ7TlrGPkiz6ku9fK3TLD/pl3CpsiFyu8N92HLgmosI= +github.com/fatih/color v1.18.0 h1:S8gINlzdQ840/4pfAwic/ZE0djQEH3wM94VfqLTZcOM= +github.com/fatih/color v1.18.0/go.mod h1:4FelSpRwEGDpQ12mAdzqdOukCy4u8WUtOY6lkT/6HfU= github.com/fatih/set v0.2.1 h1:nn2CaJyknWE/6txyUDGwysr3G5QC6xWB/PtVjPBbeaA= github.com/fatih/set v0.2.1/go.mod h1:+RKtMCH+favT2+3YecHGxcc0b4KyVWA1QWWJUs4E0CI= github.com/felixge/httpsnoop v1.0.4 h1:NFTV2Zj1bL4mc9sqWACXbQFVBBg2W3GPvqp8/ESS2Wg= @@ -1369,8 +1375,11 @@ gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C gopkg.in/yaml.v3 v3.0.0/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gotest.tools/gotestsum v1.13.0 h1:+Lh454O9mu9AMG1APV4o0y7oDYKyik/3kBOiCqiEpRo= +gotest.tools/gotestsum v1.13.0/go.mod h1:7f0NS5hFb0dWr4NtcsAsF0y1kzjEFfAil0HiBQJE03Q= gotest.tools/v3 v3.0.3 h1:4AuOwCGf4lLR9u3YOe2awrHygurzhO/HeQ6laiA6Sx0= gotest.tools/v3 v3.0.3/go.mod h1:Z7Lb0S5l+klDB31fvDQX8ss/FlKDxtlFlw3Oa8Ymbl8= +gotest.tools/v3 v3.5.2 h1:7koQfIKdy+I8UTetycgUqXWSDwpgv193Ka+qRsmBY8Q= honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg= diff --git a/internal/kibana/synthetics/private_location/acc_test.go b/internal/kibana/synthetics/private_location/acc_test.go index a48e1d693..e2f9ca80a 100644 --- a/internal/kibana/synthetics/private_location/acc_test.go +++ b/internal/kibana/synthetics/private_location/acc_test.go @@ -10,6 +10,7 @@ import ( "github.com/elastic/terraform-provider-elasticstack/internal/acctest" "github.com/elastic/terraform-provider-elasticstack/internal/versionutils" "github.com/hashicorp/go-version" + sdkacctest "github.com/hashicorp/terraform-plugin-testing/helper/acctest" "github.com/hashicorp/terraform-plugin-testing/helper/resource" ) @@ -29,6 +30,7 @@ var ( func TestSyntheticPrivateLocationResource(t *testing.T) { resourceId := "elasticstack_kibana_synthetics_private_location.test" + randomSuffix := sdkacctest.RandStringFromCharSet(4, sdkacctest.CharSetAlphaNum) resource.Test(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(t) }, ProtoV6ProviderFactories: acctest.Providers, @@ -36,9 +38,9 @@ func TestSyntheticPrivateLocationResource(t *testing.T) { // Create and Read testing { SkipFunc: versionutils.CheckIfVersionIsUnsupported(minKibanaPrivateLocationAPIVersion), - Config: testConfig("testacc", "test_policy") + ` + Config: testConfig("testacc", "test_policy", randomSuffix) + fmt.Sprintf(` resource "elasticstack_kibana_synthetics_private_location" "test" { - label = "pl-test-label" + label = "pl-test-label-%s" agent_policy_id = elasticstack_fleet_agent_policy.test_policy.policy_id tags = ["a", "b"] geo = { @@ -46,9 +48,9 @@ resource "elasticstack_kibana_synthetics_private_location" "test" { lon = -42.42 } } -`, +`, randomSuffix), Check: resource.ComposeAggregateTestCheckFunc( - resource.TestCheckResourceAttr(resourceId, "label", "pl-test-label"), + resource.TestCheckResourceAttr(resourceId, "label", fmt.Sprintf("pl-test-label-%s", randomSuffix)), resource.TestCheckResourceAttrSet(resourceId, "agent_policy_id"), resource.TestCheckResourceAttr(resourceId, "tags.#", "2"), resource.TestCheckResourceAttr(resourceId, "tags.0", "a"), @@ -63,9 +65,9 @@ resource "elasticstack_kibana_synthetics_private_location" "test" { ResourceName: resourceId, ImportState: true, ImportStateVerify: true, - Config: testConfig("testacc", "test_policy") + ` + Config: testConfig("testacc", "test_policy", randomSuffix) + fmt.Sprintf(` resource "elasticstack_kibana_synthetics_private_location" "test" { - label = "pl-test-label" + label = "pl-test-label-%s" agent_policy_id = elasticstack_fleet_agent_policy.test_policy.policy_id tags = ["a", "b"] geo = { @@ -73,14 +75,14 @@ resource "elasticstack_kibana_synthetics_private_location" "test" { lon = -42.42 } } -`, +`, randomSuffix), }, // Update and Read testing { SkipFunc: versionutils.CheckIfVersionIsUnsupported(minKibanaPrivateLocationAPIVersion), - Config: testConfig("default", "test_policy_default") + ` + Config: testConfig("default", "test_policy_default", randomSuffix) + fmt.Sprintf(` resource "elasticstack_kibana_synthetics_private_location" "test" { - label = "pl-test-label-2" + label = "pl-test-label-2-%s" agent_policy_id = elasticstack_fleet_agent_policy.test_policy_default.policy_id tags = ["c", "d", "e"] geo = { @@ -88,9 +90,9 @@ resource "elasticstack_kibana_synthetics_private_location" "test" { lon = -33.21 } } -`, +`, randomSuffix), Check: resource.ComposeAggregateTestCheckFunc( - resource.TestCheckResourceAttr(resourceId, "label", "pl-test-label-2"), + resource.TestCheckResourceAttr(resourceId, "label", fmt.Sprintf("pl-test-label-2-%s", randomSuffix)), resource.TestCheckResourceAttrSet(resourceId, "agent_policy_id"), resource.TestCheckResourceAttr(resourceId, "tags.#", "3"), resource.TestCheckResourceAttr(resourceId, "tags.0", "c"), @@ -103,14 +105,14 @@ resource "elasticstack_kibana_synthetics_private_location" "test" { // Update and Read testing { SkipFunc: versionutils.CheckIfVersionIsUnsupported(minKibanaPrivateLocationAPIVersion), - Config: testConfig("default", "test_policy_default") + ` + Config: testConfig("default", "test_policy_default", randomSuffix) + fmt.Sprintf(` resource "elasticstack_kibana_synthetics_private_location" "test" { - label = "pl-test-label-2" + label = "pl-test-label-2-%s" agent_policy_id = elasticstack_fleet_agent_policy.test_policy_default.policy_id } -`, +`, randomSuffix), Check: resource.ComposeAggregateTestCheckFunc( - resource.TestCheckResourceAttr(resourceId, "label", "pl-test-label-2"), + resource.TestCheckResourceAttr(resourceId, "label", fmt.Sprintf("pl-test-label-2-%s", randomSuffix)), resource.TestCheckResourceAttrSet(resourceId, "agent_policy_id"), resource.TestCheckNoResourceAttr(resourceId, "tags"), resource.TestCheckNoResourceAttr(resourceId, "geo"), @@ -119,15 +121,15 @@ resource "elasticstack_kibana_synthetics_private_location" "test" { // Update and Read testing { SkipFunc: versionutils.CheckIfVersionIsUnsupported(minKibanaPrivateLocationAPIVersion), - Config: testConfig("default", "test_policy_default") + ` + Config: testConfig("default", "test_policy_default", randomSuffix) + fmt.Sprintf(` resource "elasticstack_kibana_synthetics_private_location" "test" { - label = "pl-test-label-2" + label = "pl-test-label-2-%s" agent_policy_id = elasticstack_fleet_agent_policy.test_policy_default.policy_id tags = ["c", "d", "e"] } -`, +`, randomSuffix), Check: resource.ComposeAggregateTestCheckFunc( - resource.TestCheckResourceAttr(resourceId, "label", "pl-test-label-2"), + resource.TestCheckResourceAttr(resourceId, "label", fmt.Sprintf("pl-test-label-2-%s", randomSuffix)), resource.TestCheckResourceAttrSet(resourceId, "agent_policy_id"), resource.TestCheckResourceAttr(resourceId, "tags.#", "3"), resource.TestCheckResourceAttr(resourceId, "tags.0", "c"), @@ -139,18 +141,18 @@ resource "elasticstack_kibana_synthetics_private_location" "test" { // Update and Read testing { SkipFunc: versionutils.CheckIfVersionIsUnsupported(minKibanaPrivateLocationAPIVersion), - Config: testConfig("default", "test_policy_default") + ` + Config: testConfig("default", "test_policy_default", randomSuffix) + fmt.Sprintf(` resource "elasticstack_kibana_synthetics_private_location" "test" { - label = "pl-test-label-2" + label = "pl-test-label-2-%s" agent_policy_id = elasticstack_fleet_agent_policy.test_policy_default.policy_id geo = { lat = -33.21 lon = -33.21 } } -`, +`, randomSuffix), Check: resource.ComposeAggregateTestCheckFunc( - resource.TestCheckResourceAttr(resourceId, "label", "pl-test-label-2"), + resource.TestCheckResourceAttr(resourceId, "label", fmt.Sprintf("pl-test-label-2-%s", randomSuffix)), resource.TestCheckResourceAttrSet(resourceId, "agent_policy_id"), resource.TestCheckNoResourceAttr(resourceId, "tags"), resource.TestCheckResourceAttr(resourceId, "geo.lat", "-33.21"), @@ -162,15 +164,15 @@ resource "elasticstack_kibana_synthetics_private_location" "test" { }) } -func testConfig(namespace, agentPolicy string) string { +func testConfig(namespace, agentPolicy, randomSuffix string) string { return providerConfig + fmt.Sprintf(` resource "elasticstack_fleet_agent_policy" "%s" { - name = "Private Location Agent Policy - %s" + name = "Private Location Agent Policy - %s - %s" namespace = "%s" description = "TestPrivateLocationResource Agent Policy" monitor_logs = true monitor_metrics = true skip_destroy = false } -`, agentPolicy, agentPolicy, namespace) +`, agentPolicy, agentPolicy, randomSuffix, namespace) }