Skip to content

Commit cded411

Browse files
Add data source for Fleet integration packages (#469)
* Add data source for Fleet integration packages - Used for getting the latest version of an integration package - Add acceptance test - Add docs * changelog * Fix test
1 parent e4e1d06 commit cded411

File tree

10 files changed

+470
-0
lines changed

10 files changed

+470
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
### Added
44
- Switch to Terraform [protocol version 6](https://developer.hashicorp.com/terraform/plugin/terraform-plugin-protocol#protocol-version-6) that is compatible with Terraform CLI version 1.0 and later.
5+
- Add 'elasticstack_fleet_package' data source ([#469](https://github.com/elastic/terraform-provider-elasticstack/pull/469))
56

67
## [0.10.0] - 2023-11-02
78

docs/data-sources/fleet_package.md

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
---
2+
subcategory: "Fleet"
3+
layout: ""
4+
page_title: "Elasticstack: elasticstack_fleet_package Data Source"
5+
description: |-
6+
Gets information about a Fleet integration package.
7+
---
8+
9+
# Data Source: elasticstack_fleet_package
10+
11+
This data source provides information about a Fleet integration package. Currently,
12+
the data source will retrieve the latest available version of the package. Version
13+
selection is determined by the Fleet API, which is currently based on semantic
14+
versioning.
15+
16+
By default, the highest GA release version will be selected. If a
17+
package is not GA (the version is below 1.0.0) or if a new non-GA version of the
18+
package is to be selected (i.e., the GA version of the package is 1.5.0, but there's
19+
a new 1.5.1-beta version available), then the `prerelease` parameter in the plan
20+
should be set to `true`.
21+
22+
## Example Usage
23+
24+
```terraform
25+
provider "elasticstack" {
26+
kibana {}
27+
}
28+
29+
data "elasticstack_fleet_package" "test" {
30+
name = "tcp"
31+
}
32+
```
33+
34+
<!-- schema generated by tfplugindocs -->
35+
## Schema
36+
37+
### Required
38+
39+
- `name` (String) The package name.
40+
41+
### Optional
42+
43+
- `prerelease` (Boolean) Include prerelease packages.
44+
45+
### Read-Only
46+
47+
- `id` (String) The ID of this resource.
48+
- `version` (String) The package version.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
provider "elasticstack" {
2+
kibana {}
3+
}
4+
5+
data "elasticstack_fleet_package" "test" {
6+
name = "tcp"
7+
}

generated/fleet/fleet.gen.go

Lines changed: 212 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

generated/fleet/getschema.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ var transformers = []TransformFunc{
7171
transformSchemasInputsType,
7272
transformInlinePackageDefinitions,
7373
transformAddPackagePolicyVars,
74+
transformFixPackageSearchResult,
7475
}
7576

7677
// transformFilterPaths filters the paths in a schema down to
@@ -88,6 +89,7 @@ func transformFilterPaths(schema *Schema) {
8889
"/package_policies": {"post"},
8990
"/package_policies/{packagePolicyId}": {"get", "put", "delete"},
9091
"/epm/packages/{pkgName}/{pkgVersion}": {"get", "put", "post", "delete"},
92+
"/epm/packages": {"get"},
9193
}
9294

9395
// filterKbnXsrfParameter filters out an entry if it is a kbn_xsrf parameter.
@@ -331,6 +333,17 @@ func transformAddPackagePolicyVars(schema *Schema) {
331333
}
332334
}
333335

336+
// transformFixPackageSearchResult removes unneeded fields from the
337+
// SearchResult struct. These fields are also causing parsing errors.
338+
func transformFixPackageSearchResult(schema *Schema) {
339+
properties, ok := schema.Components.GetFields("schemas.search_result.properties")
340+
if !ok {
341+
panic("properties not found")
342+
}
343+
properties.Delete("icons")
344+
properties.Delete("installationInfo")
345+
}
346+
334347
// downloadFile will download a file from url and return the
335348
// bytes. If the request fails, or a non 200 error code is
336349
// observed in the response, an error is returned instead.

0 commit comments

Comments
 (0)