Skip to content

Add Fleet package policies and epm support #454

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

Merged
merged 6 commits into from
Nov 2, 2023
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 @@ -6,6 +6,7 @@
- Add support for Terraform Plugin Framework ([#343](https://github.com/elastic/terraform-provider-elasticstack/pull/343)).
- Fix fleet resources not having ID set on import ([#447](https://github.com/elastic/terraform-provider-elasticstack/pull/447))
- Fix Fleet Agent Policy monitoring settings ([#448](https://github.com/elastic/terraform-provider-elasticstack/pull/448))
- Add `elasticstack_fleet_package` and `elasticstack_fleet_package_policy` resources ([#454](https://github.com/elastic/terraform-provider-elasticstack/pull/454))

## [0.9.0] - 2023-10-09

Expand Down
2 changes: 1 addition & 1 deletion docs/resources/fleet_agent_policy.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,5 +57,5 @@ resource "elasticstack_fleet_agent_policy" "test_policy" {
Import is supported using the following syntax:

```shell
terraform import elasticstack_kibana_fleet_agent_policy.my_policy <fleet_agent_policy_id>
terraform import elasticstack_fleet_agent_policy.my_policy <fleet_agent_policy_id>
```
47 changes: 47 additions & 0 deletions docs/resources/fleet_package.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
---
subcategory: "Fleet"
layout: ""
page_title: "Elasticstack: elasticstack_fleet_package Resource"
description: |-
Installs or uninstalls a Fleet integration package.
---

# Resource: elasticstack_fleet_package

Installs or uninstalls a Fleet integration package. The Kibana Fleet UI can be
used to view available packages. Additional information for managing integration
packages can be found [here](https://www.elastic.co/guide/en/fleet/current/install-uninstall-integration-assets.html).

To prevent the package from being uninstalled when the resource is destroyed,
set `skip_destroy` to `true`.

## Example Usage

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

resource "elasticstack_fleet_package" "test_package" {
name = "tcp"
version = "1.16.0"
force = true
}
```

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

### Required

- `name` (String) The package name.
- `version` (String) The package version.

### Optional

- `force` (Boolean) Set to true to force the requested action.
- `skip_destroy` (Boolean) Set to true if you do not wish the package to be uninstalled at destroy time, and instead just remove the package from the Terraform state.

### Read-Only

- `id` (String) The ID of this resource.
123 changes: 123 additions & 0 deletions docs/resources/fleet_package_policy.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
---
subcategory: "Fleet"
layout: ""
page_title: "Elasticstack: elasticstack_fleet_package_policy Resource"
description: |-
Creates or updates a Fleet Package Policy.
---

# Resource: elasticstack_fleet_package_policy

Creates or updates a Fleet Package Policy.

It is highly recommended that all inputs and streams are provided in the
Terraform plan, even if some are disabled. Otherwise, differences may appear
between what is in the plan versus what is returned by the Fleet API.

The [Kibana Fleet UI](https://www.elastic.co/guide/en/fleet/current/add-integration-to-policy.html)
can be used as a reference for what data needs to be provided. Instead of saving
a new integration configuration, the API request can be previewed, showing what
values need to be provided for inputs and their streams.

## Example Usage

```terraform
provider "elasticstack" {
fleet {}
}

// The package to use.
resource "elasticstack_fleet_package" "sample" {
name = "tcp"
version = "1.16.0"
force = true
}

// An agent policy to hold the package policy.
resource "elasticstack_fleet_agent_policy" "sample" {
name = "Sample Agent Policy"
namespace = "default"
description = "A sample agent policy"
monitor_logs = true
monitor_metrics = true
skip_destroy = false
}

// The associated enrollment token.
data "elasticstack_fleet_enrollment_tokens" "sample" {
policy_id = elasticstack_fleet_agent_policy.sample.policy_id
}

// The package policy.
resource "elasticstack_fleet_package_policy" "sample" {
name = "Sample Package Policy"
namespace = "default"
description = "A sample package policy"
agent_policy_id = elasticstack_fleet_agent_policy.sample.policy_id
package_name = elasticstack_fleet_package.sample.name
package_version = elasticstack_fleet_package.sample.version

input {
input_id = "tcp-tcp"
streams_json = jsonencode({
"tcp.generic" : {
"enabled" : true,
"vars" : {
"listen_address" : "localhost",
"listen_port" : 8080,
"data_stream.dataset" : "tcp.generic",
"tags" : [],
"syslog_options" : "field: message\n#format: auto\n#timezone: Local\n",
"ssl" : "#certificate: |\n# -----BEGIN CERTIFICATE-----\n# ...\n# -----END CERTIFICATE-----\n#key: |\n# -----BEGIN PRIVATE KEY-----\n# ...\n# -----END PRIVATE KEY-----\n",
"custom" : ""
}
}
})
}
}
```

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

### Required

- `agent_policy_id` (String) ID of the agent policy.
- `input` (Block List, Min: 1) (see [below for nested schema](#nestedblock--input))
- `name` (String) The name of the package policy.
- `namespace` (String) The namespace of the package policy.
- `package_name` (String) The name of the package.
- `package_version` (String) The version of the package.

### Optional

- `description` (String) The description of the package policy.
- `enabled` (Boolean) Enable the package policy.
- `force` (Boolean) Force operations, such as creation and deletion, to occur.
- `policy_id` (String) Unique identifier of the package policy.
- `vars_json` (String, Sensitive) Package-level variables as JSON.

### Read-Only

- `id` (String) The ID of this resource.

<a id="nestedblock--input"></a>
### Nested Schema for `input`

Required:

- `input_id` (String) The identifier of the input.

Optional:

- `enabled` (Boolean) Enable the input.
- `streams_json` (String, Sensitive) Input streams as JSON.
- `vars_json` (String, Sensitive) Input variables as JSON.

## Import

Import is supported using the following syntax:

```shell
terraform import elasticstack_fleet_package_policy.my_policy <fleet_package_policy_id>
```
Original file line number Diff line number Diff line change
@@ -1 +1 @@
terraform import elasticstack_kibana_fleet_agent_policy.my_policy <fleet_agent_policy_id>
terraform import elasticstack_fleet_agent_policy.my_policy <fleet_agent_policy_id>
9 changes: 9 additions & 0 deletions examples/resources/elasticstack_fleet_package/resource.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
provider "elasticstack" {
kibana {}
}

resource "elasticstack_fleet_package" "test_package" {
name = "tcp"
version = "1.16.0"
force = true
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
terraform import elasticstack_fleet_package_policy.my_policy <fleet_package_policy_id>
53 changes: 53 additions & 0 deletions examples/resources/elasticstack_fleet_package_policy/resource.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
provider "elasticstack" {
fleet {}
}

// The package to use.
resource "elasticstack_fleet_package" "sample" {
name = "tcp"
version = "1.16.0"
force = true
}

// An agent policy to hold the package policy.
resource "elasticstack_fleet_agent_policy" "sample" {
name = "Sample Agent Policy"
namespace = "default"
description = "A sample agent policy"
monitor_logs = true
monitor_metrics = true
skip_destroy = false
}

// The associated enrollment token.
data "elasticstack_fleet_enrollment_tokens" "sample" {
policy_id = elasticstack_fleet_agent_policy.sample.policy_id
}

// The package policy.
resource "elasticstack_fleet_package_policy" "sample" {
name = "Sample Package Policy"
namespace = "default"
description = "A sample package policy"
agent_policy_id = elasticstack_fleet_agent_policy.sample.policy_id
package_name = elasticstack_fleet_package.sample.name
package_version = elasticstack_fleet_package.sample.version

input {
input_id = "tcp-tcp"
streams_json = jsonencode({
"tcp.generic" : {
"enabled" : true,
"vars" : {
"listen_address" : "localhost",
"listen_port" : 8080,
"data_stream.dataset" : "tcp.generic",
"tags" : [],
"syslog_options" : "field: message\n#format: auto\n#timezone: Local\n",
"ssl" : "#certificate: |\n# -----BEGIN CERTIFICATE-----\n# ...\n# -----END CERTIFICATE-----\n#key: |\n# -----BEGIN PRIVATE KEY-----\n# ...\n# -----END PRIVATE KEY-----\n",
"custom" : ""
}
}
})
}
}
Loading