Skip to content

Commit 8726779

Browse files
committed
squashed
1 parent 64b1969 commit 8726779

39 files changed

+2547
-1405
lines changed

.github/workflows/test.yml

+28-6
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ jobs:
6363
xpack.security.enabled: true
6464
xpack.security.authc.api_key.enabled: true
6565
xpack.security.authc.token.enabled: true
66-
xpack.security.http.ssl.enabled: false
6766
xpack.watcher.enabled: true
6867
xpack.license.self_generated.type: trial
6968
repositories.url.allowed_urls: https://example.com/*
@@ -80,10 +79,28 @@ jobs:
8079
ELASTICSEARCH_USERNAME: ${{ env.KIBANA_SYSTEM_USERNAME }}
8180
ELASTICSEARCH_PASSWORD: ${{ env.KIBANA_SYSTEM_PASSWORD }}
8281
XPACK_ENCRYPTEDSAVEDOBJECTS_ENCRYPTIONKEY: a7a6311933d3503b89bc2dbc36572c33a6c10925682e591bffcab6911c06786d
83-
# LOGGING_ROOT_LEVEL: debug
82+
# LOGGING_ROOT_LEVEL: debug
8483
ports:
8584
- 5601:5601
8685
options: --health-cmd="curl http://localhost:5601/api/status" --health-interval=10s --health-timeout=5s --health-retries=10
86+
fleet:
87+
image: docker.elastic.co/beats/elastic-agent:${{ matrix.version }}
88+
env:
89+
SERVER_NAME: fleet
90+
FLEET_ENROLL: "1"
91+
FLEET_URL: https://fleet:8220
92+
FLEET_INSECURE: "true"
93+
FLEET_SERVER_ENABLE: "1"
94+
FLEET_SERVER_POLICY_ID: fleet-server
95+
FLEET_SERVER_ELASTICSEARCH_HOST: http://elasticsearch:9200
96+
FLEET_SERVER_ELASTICSEARCH_INSECURE: "true"
97+
FLEET_SERVER_INSECURE_HTTP: "true"
98+
KIBANA_HOST: http://kibana:5601
99+
KIBANA_FLEET_SETUP: "1"
100+
KIBANA_FLEET_PASSWORD: ${{ env.ELASTIC_PASSWORD }}
101+
ports:
102+
- 8220:8220
103+
options: --restart="unless-stopped"
87104

88105
timeout-minutes: 15
89106
strategy:
@@ -123,8 +140,6 @@ jobs:
123140
- name: Setup Kibana user
124141
run: make set-kibana-password
125142
env:
126-
ELASTICSEARCH_ENDPOINTS: "http://localhost:9200"
127-
ELASTICSEARCH_USERNAME: "elastic"
128143
ELASTICSEARCH_PASSWORD: ${{ env.ELASTIC_PASSWORD }}
129144
KIBANA_SYSTEM_USERNAME: ${{ env.KIBANA_SYSTEM_USERNAME }}
130145
KIBANA_SYSTEM_PASSWORD: ${{ env.KIBANA_SYSTEM_PASSWORD }}
@@ -134,10 +149,17 @@ jobs:
134149
run: |-
135150
echo "apikey=$(make create-es-api-key | jq -r .encoded)" >> "$GITHUB_OUTPUT"
136151
env:
137-
ELASTICSEARCH_ENDPOINTS: "http://localhost:9200"
138-
ELASTICSEARCH_USERNAME: "elastic"
139152
ELASTICSEARCH_PASSWORD: ${{ env.ELASTIC_PASSWORD }}
140153

154+
- id: setup-fleet
155+
name: Setup Fleet
156+
if: matrix.version == '8.10.3' || matrix.version == '8.11.4' || matrix.version == '8.12.2' || matrix.version == '8.13.4' || matrix.version == '8.14.3' || matrix.version == '8.15.0'
157+
run: |-
158+
make setup-kibana-fleet
159+
env:
160+
ELASTICSEARCH_PASSWORD: ${{ env.ELASTIC_PASSWORD }}
161+
FLEET_NAME: "fleet"
162+
141163
- id: force-install-synthetics
142164
name: Force install synthetics
143165
if: matrix.version == '8.14.3' || matrix.version == '8.15.0'

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
- Fix handling of `sys_monitoring` in `elasticstack_fleet_agent_policy` ([#792](https://github.com./elastic/terraform-provider-elasticstack/pull/792))
44
- Migrate `elasticstack_fleet_agent_policy`, `elasticstack_fleet_integration` (both), and `elasticstack_fleet_server_host` to terraform-plugin-framework ([#785](https://github.com./elastic/terraform-provider-elasticstack/pull/785))
5+
- Migrate `elasticstack_fleet_output` and `elasticstack_fleet_integration_policy` to terraform-plugin-framework. Fix drift in integration policy secrets. ([#TODO](https://github.com./elastic/terraform-provider-elasticstack/pull/TODO))
56

67
## [0.11.7] - 2024-09-20
78

Makefile

+40-6
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,11 @@ KIBANA_SYSTEM_USERNAME ?= kibana_system
3131
KIBANA_SYSTEM_PASSWORD ?= password
3232
KIBANA_API_KEY_NAME ?= kibana-api-key
3333

34+
FLEET_NAME ?= terraform-elasticstack-fleet
35+
FLEET_ENDPOINT ?= https://$(FLEET_NAME):8220
36+
3437
SOURCE_LOCATION ?= $(shell pwd)
38+
, := ,
3539

3640
export GOBIN = $(shell pwd)/bin
3741

@@ -72,7 +76,7 @@ retry = until [ $$(if [ -z "$$attempt" ]; then echo -n "0"; else echo -n "$$atte
7276
# To run specific test (e.g. TestAccResourceActionConnector) execute `make docker-testacc TESTARGS='-run ^TestAccResourceActionConnector$$'`
7377
# To enable tracing (or debugging), execute `make docker-testacc TF_LOG=TRACE`
7478
.PHONY: docker-testacc
75-
docker-testacc: docker-elasticsearch docker-kibana ## Run acceptance tests in the docker container
79+
docker-testacc: docker-elasticsearch docker-kibana docker-fleet ## Run acceptance tests in the docker container
7680
@ docker run --rm \
7781
-e ELASTICSEARCH_ENDPOINTS="$(ELASTICSEARCH_ENDPOINTS)" \
7882
-e KIBANA_ENDPOINT="$(KIBANA_ENDPOINT)" \
@@ -163,6 +167,30 @@ docker-kibana-with-tls: docker-network docker-elasticsearch set-kibana-password
163167
docker.elastic.co/kibana/kibana:$(STACK_VERSION); \
164168
fi)
165169

170+
.PHONY: docker-fleet
171+
docker-fleet: docker-network docker-elasticsearch docker-kibana setup-kibana-fleet ## Start Fleet node in docker container
172+
@ docker rm -f $(FLEET_NAME) &> /dev/null || true
173+
@ $(call retry, 5, if ! docker ps --format '{{.Names}}' | grep -w $(FLEET_NAME) > /dev/null 2>&1 ; then \
174+
docker run -d \
175+
-p 8220:8220 \
176+
-e SERVER_NAME=fleet \
177+
-e FLEET_ENROLL=1 \
178+
-e FLEET_URL=$(FLEET_ENDPOINT) \
179+
-e FLEET_INSECURE=true \
180+
-e FLEET_SERVER_ENABLE=1 \
181+
-e FLEET_SERVER_POLICY_ID=fleet-server \
182+
-e FLEET_SERVER_ELASTICSEARCH_HOST=$(ELASTICSEARCH_ENDPOINTS) \
183+
-e FLEET_SERVER_ELASTICSEARCH_INSECURE=true \
184+
-e FLEET_SERVER_INSECURE_HTTP=true \
185+
-e KIBANA_HOST=$(KIBANA_ENDPOINT) \
186+
-e KIBANA_FLEET_SETUP=1 \
187+
-e KIBANA_FLEET_USERNAME=$(ELASTICSEARCH_USERNAME) \
188+
-e KIBANA_FLEET_PASSWORD=$(ELASTICSEARCH_PASSWORD) \
189+
--name $(FLEET_NAME) \
190+
--network $(ELASTICSEARCH_NETWORK) \
191+
docker.elastic.co/beats/elastic-agent:$(STACK_VERSION); \
192+
fi)
193+
166194

167195
.PHONY: docker-network
168196
docker-network: ## Create a dedicated network for ES and test runs
@@ -172,19 +200,25 @@ docker-network: ## Create a dedicated network for ES and test runs
172200

173201
.PHONY: set-kibana-password
174202
set-kibana-password: ## Sets the ES KIBANA_SYSTEM_USERNAME's password to KIBANA_SYSTEM_PASSWORD. This expects Elasticsearch to be available at localhost:9200
175-
@ $(call retry, 10, curl -X POST -u $(ELASTICSEARCH_USERNAME):$(ELASTICSEARCH_PASSWORD) -H "Content-Type: application/json" http://localhost:9200/_security/user/$(KIBANA_SYSTEM_USERNAME)/_password -d "{\"password\":\"$(KIBANA_SYSTEM_PASSWORD)\"}" | grep -q "^{}")
203+
@ $(call retry, 10, curl -sS -X POST -u $(ELASTICSEARCH_USERNAME):$(ELASTICSEARCH_PASSWORD) -H "Content-Type: application/json" http://localhost:9200/_security/user/$(KIBANA_SYSTEM_USERNAME)/_password -d '{"password":"$(KIBANA_SYSTEM_PASSWORD)"}' | grep -q "^{}")
176204

177205
.PHONY: create-es-api-key
178206
create-es-api-key: ## Creates and outputs a new API Key. This expects Elasticsearch to be available at localhost:9200
179-
@ $(call retry, 10, curl -X POST -u $(ELASTICSEARCH_USERNAME):$(ELASTICSEARCH_PASSWORD) -H "Content-Type: application/json" http://localhost:9200/_security/api_key -d "{\"name\":\"$(KIBANA_API_KEY_NAME)\"}")
207+
@ $(call retry, 10, curl -sS -X POST -u $(ELASTICSEARCH_USERNAME):$(ELASTICSEARCH_PASSWORD) -H "Content-Type: application/json" http://localhost:9200/_security/api_key -d '{"name":"$(KIBANA_API_KEY_NAME)"}')
180208

181209
.PHONY: create-es-bearer-token
182-
create-es-bearer-token:
183-
@ $(call retry, 10, curl -X POST -u $(ELASTICSEARCH_USERNAME):$(ELASTICSEARCH_PASSWORD) -H "Content-Type: application/json" http://localhost:9200/_security/oauth2/token -d "{\"grant_type\": \"client_credentials\"}")
210+
create-es-bearer-token: ## Creates and outputs a new OAuth bearer token. This expects Elasticsearch to be available at localhost:9200
211+
@ $(call retry, 10, curl -sS -X POST -u $(ELASTICSEARCH_USERNAME):$(ELASTICSEARCH_PASSWORD) -H "Content-Type: application/json" http://localhost:9200/_security/oauth2/token -d '{"grant_type":"client_credentials"}')
212+
213+
.PHONY: setup-kibana-fleet
214+
setup-kibana-fleet: ## Creates the agent and integration policies required to run Fleet. This expects Kibana to be available at localhost:5601
215+
@ $(call retry, 10, curl -sS --fail-with-body -X POST -u $(ELASTICSEARCH_USERNAME):$(ELASTICSEARCH_PASSWORD) -H "Content-Type: application/json" -H "kbn-xsrf: true" http://localhost:5601/api/fleet/fleet_server_hosts -d '{"name":"default"$(,)"host_urls":["$(FLEET_ENDPOINT)"]$(,)"is_default":true}')
216+
@ $(call retry, 10, curl -sS --fail-with-body -X POST -u $(ELASTICSEARCH_USERNAME):$(ELASTICSEARCH_PASSWORD) -H "Content-Type: application/json" -H "kbn-xsrf: true" http://localhost:5601/api/fleet/agent_policies -d '{"id":"fleet-server"$(,)"name":"Fleet Server"$(,)"namespace":"default"$(,)"monitoring_enabled":["logs"$(,)"metrics"]}')
217+
@ $(call retry, 10, curl -sS --fail-with-body -X POST -u $(ELASTICSEARCH_USERNAME):$(ELASTICSEARCH_PASSWORD) -H "Content-Type: application/json" -H "kbn-xsrf: true" http://localhost:5601/api/fleet/package_policies -d '{"name":"fleet-server"$(,)"namespace":"default"$(,)"policy_id":"fleet-server"$(,)"enabled":true$(,)"inputs":[{"type":"fleet-server"$(,)"enabled":true$(,)"streams":[]$(,)"vars":{}}]$(,)"package":{"name":"fleet_server"$(,)"version":"1.5.0"}}')
184218

185219
.PHONY: docker-clean
186220
docker-clean: ## Try to remove provisioned nodes and assigned network
187-
@ docker rm -f $(ELASTICSEARCH_NAME) $(KIBANA_NAME) || true
221+
@ docker rm -f $(ELASTICSEARCH_NAME) $(KIBANA_NAME) $(FLEET_NAME) || true
188222
@ docker network rm $(ELASTICSEARCH_NETWORK) || true
189223

190224

docs/resources/fleet_integration_policy.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ resource "elasticstack_fleet_integration_policy" "sample" {
9393
- `description` (String) The description of the integration policy.
9494
- `enabled` (Boolean) Enable the integration policy.
9595
- `force` (Boolean) Force operations, such as creation and deletion, to occur.
96-
- `input` (Block List) (see [below for nested schema](#nestedblock--input))
96+
- `input` (Block List) Integration inputs. (see [below for nested schema](#nestedblock--input))
9797
- `policy_id` (String) Unique identifier of the integration policy.
9898
- `vars_json` (String, Sensitive) Integration-level variables as JSON.
9999

docs/resources/fleet_output.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ resource "elasticstack_fleet_output" "test_output" {
4848
- `default_monitoring` (Boolean) Make this output the default for agent monitoring.
4949
- `hosts` (List of String) A list of hosts.
5050
- `output_id` (String) Unique identifier of the output.
51-
- `ssl` (Block List, Max: 1) SSL configuration. (see [below for nested schema](#nestedblock--ssl))
51+
- `ssl` (Block List) SSL configuration. (see [below for nested schema](#nestedblock--ssl))
5252

5353
### Read-Only
5454

generated/fleet/fleet.gen.go

+16-10
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

generated/fleet/getschema.go

+25
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ var transformers = []TransformFunc{
7171
transformSchemasInputsType,
7272
transformInlinePackageDefinitions,
7373
transformAddPackagePolicyVars,
74+
transformAddPackagePolicySecretReferences,
7475
transformFixPackageSearchResult,
7576
}
7677

@@ -333,6 +334,30 @@ func transformAddPackagePolicyVars(schema *Schema) {
333334
}
334335
}
335336

337+
// transformAddPackagePolicySecretReferences adds the missing 'secretReferences'
338+
// field to the PackagePolicy schema struct.
339+
func transformAddPackagePolicySecretReferences(schema *Schema) {
340+
inputs, ok := schema.Components.GetFields("schemas.new_package_policy.properties")
341+
if !ok {
342+
panic("properties not found")
343+
}
344+
345+
// Only add it if it doesn't exist.
346+
if _, ok = inputs.Get("secret_references"); !ok {
347+
inputs.Set("secret_references", map[string]any{
348+
"type": "array",
349+
"items": map[string]any{
350+
"type": "object",
351+
"properties": map[string]any{
352+
"id": map[string]any{
353+
"type": "string",
354+
},
355+
},
356+
},
357+
})
358+
}
359+
}
360+
336361
// transformFixPackageSearchResult removes unneeded fields from the
337362
// SearchResult struct. These fields are also causing parsing errors.
338363
func transformFixPackageSearchResult(schema *Schema) {

0 commit comments

Comments
 (0)