Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add data source for Fleet integration packages #469

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

### Added
- 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.
- Add 'elasticstack_fleet_package' data source ([#469](https://github.com/elastic/terraform-provider-elasticstack/pull/469))

## [0.10.0] - 2023-11-02

Expand Down
48 changes: 48 additions & 0 deletions docs/data-sources/fleet_package.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
---
subcategory: "Fleet"
layout: ""
page_title: "Elasticstack: elasticstack_fleet_package Data Source"
description: |-
Gets information about a Fleet integration package.
---

# Data Source: elasticstack_fleet_package

This data source provides information about a Fleet integration package. Currently,
the data source will retrieve the latest available version of the package. Version
selection is determined by the Fleet API, which is currently based on semantic
versioning.

By default, the highest GA release version will be selected. If a
package is not GA (the version is below 1.0.0) or if a new non-GA version of the
package is to be selected (i.e., the GA version of the package is 1.5.0, but there's
a new 1.5.1-beta version available), then the `prerelease` parameter in the plan
should be set to `true`.

## Example Usage

```terraform
provider "elasticstack" {
kibana {}
}

data "elasticstack_fleet_package" "test" {
name = "tcp"
}
```

<!-- schema generated by tfplugindocs -->
## Schema

### Required

- `name` (String) The package name.

### Optional

- `prerelease` (Boolean) Include prerelease packages.

### Read-Only

- `id` (String) The ID of this resource.
- `version` (String) The package version.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
provider "elasticstack" {
kibana {}
}

data "elasticstack_fleet_package" "test" {
name = "tcp"
}
212 changes: 212 additions & 0 deletions generated/fleet/fleet.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions generated/fleet/getschema.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ var transformers = []TransformFunc{
transformSchemasInputsType,
transformInlinePackageDefinitions,
transformAddPackagePolicyVars,
transformFixPackageSearchResult,
}

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

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

// transformFixPackageSearchResult removes unneeded fields from the
// SearchResult struct. These fields are also causing parsing errors.
func transformFixPackageSearchResult(schema *Schema) {
properties, ok := schema.Components.GetFields("schemas.search_result.properties")
if !ok {
panic("properties not found")
}
properties.Delete("icons")
properties.Delete("installationInfo")
}

// downloadFile will download a file from url and return the
// bytes. If the request fails, or a non 200 error code is
// observed in the response, an error is returned instead.
Expand Down
Loading