|
| 1 | +--- |
| 2 | +subcategory: "Fleet" |
| 3 | +layout: "" |
| 4 | +page_title: "Elasticstack: elasticstack_fleet_package_policy Resource" |
| 5 | +description: |- |
| 6 | + Creates or updates a Fleet Package Policy. |
| 7 | +--- |
| 8 | + |
| 9 | +# Resource: elasticstack_fleet_package_policy |
| 10 | + |
| 11 | +Creates or updates a Fleet Package Policy. |
| 12 | + |
| 13 | +It is highly recommended that all inputs and streams are provided in the |
| 14 | +Terraform plan, even if some are disabled. Otherwise, differences may appear |
| 15 | +between what is in the plan versus what is returned by the Fleet API. |
| 16 | + |
| 17 | +The [Kibana Fleet UI](https://www.elastic.co/guide/en/fleet/current/add-integration-to-policy.html) |
| 18 | +can be used as a reference for what data needs to be provided. Instead of saving |
| 19 | +a new integration configuration, the API request can be previewed, showing what |
| 20 | +values need to be provided for inputs and their streams. |
| 21 | + |
| 22 | +## Example Usage |
| 23 | + |
| 24 | +```terraform |
| 25 | +provider "elasticstack" { |
| 26 | + fleet {} |
| 27 | +} |
| 28 | +
|
| 29 | +// The package to use. |
| 30 | +resource "elasticstack_fleet_package" "sample" { |
| 31 | + name = "tcp" |
| 32 | + version = "1.16.0" |
| 33 | + force = true |
| 34 | +} |
| 35 | +
|
| 36 | +// An agent policy to hold the package policy. |
| 37 | +resource "elasticstack_fleet_agent_policy" "sample" { |
| 38 | + name = "Sample Agent Policy" |
| 39 | + namespace = "default" |
| 40 | + description = "A sample agent policy" |
| 41 | + monitor_logs = true |
| 42 | + monitor_metrics = true |
| 43 | + skip_destroy = false |
| 44 | +} |
| 45 | +
|
| 46 | +// The associated enrollment token. |
| 47 | +data "elasticstack_fleet_enrollment_tokens" "sample" { |
| 48 | + policy_id = elasticstack_fleet_agent_policy.sample.policy_id |
| 49 | +} |
| 50 | +
|
| 51 | +// The package policy. |
| 52 | +resource "elasticstack_fleet_package_policy" "sample" { |
| 53 | + name = "Sample Package Policy" |
| 54 | + namespace = "default" |
| 55 | + description = "A sample package policy" |
| 56 | + agent_policy_id = elasticstack_fleet_agent_policy.sample.policy_id |
| 57 | + package_name = elasticstack_fleet_package.sample.name |
| 58 | + package_version = elasticstack_fleet_package.sample.version |
| 59 | +
|
| 60 | + input { |
| 61 | + input_id = "tcp-tcp" |
| 62 | + streams_json = jsonencode({ |
| 63 | + "tcp.generic" : { |
| 64 | + "enabled" : true, |
| 65 | + "vars" : { |
| 66 | + "listen_address" : "localhost", |
| 67 | + "listen_port" : 8080, |
| 68 | + "data_stream.dataset" : "tcp.generic", |
| 69 | + "tags" : [], |
| 70 | + "syslog_options" : "field: message\n#format: auto\n#timezone: Local\n", |
| 71 | + "ssl" : "#certificate: |\n# -----BEGIN CERTIFICATE-----\n# ...\n# -----END CERTIFICATE-----\n#key: |\n# -----BEGIN PRIVATE KEY-----\n# ...\n# -----END PRIVATE KEY-----\n", |
| 72 | + "custom" : "" |
| 73 | + } |
| 74 | + } |
| 75 | + }) |
| 76 | + } |
| 77 | +} |
| 78 | +``` |
| 79 | + |
| 80 | +<!-- schema generated by tfplugindocs --> |
| 81 | +## Schema |
| 82 | + |
| 83 | +### Required |
| 84 | + |
| 85 | +- `agent_policy_id` (String) ID of the agent policy. |
| 86 | +- `input` (Block List, Min: 1) (see [below for nested schema](#nestedblock--input)) |
| 87 | +- `name` (String) The name of the package policy. |
| 88 | +- `namespace` (String) The namespace of the package policy. |
| 89 | +- `package_name` (String) The name of the package. |
| 90 | +- `package_version` (String) The version of the package. |
| 91 | + |
| 92 | +### Optional |
| 93 | + |
| 94 | +- `description` (String) The description of the package policy. |
| 95 | +- `enabled` (Boolean) Enable the package policy. |
| 96 | +- `force` (Boolean) Force operations, such as creation and deletion, to occur. |
| 97 | +- `policy_id` (String) Unique identifier of the package policy. |
| 98 | +- `vars_json` (String, Sensitive) Package-level variables as JSON. |
| 99 | + |
| 100 | +### Read-Only |
| 101 | + |
| 102 | +- `id` (String) The ID of this resource. |
| 103 | + |
| 104 | +<a id="nestedblock--input"></a> |
| 105 | +### Nested Schema for `input` |
| 106 | + |
| 107 | +Required: |
| 108 | + |
| 109 | +- `input_id` (String) The identifier of the input. |
| 110 | + |
| 111 | +Optional: |
| 112 | + |
| 113 | +- `enabled` (Boolean) Enable the input. |
| 114 | +- `streams_json` (String, Sensitive) Input streams as JSON. |
| 115 | +- `vars_json` (String, Sensitive) Input variables as JSON. |
| 116 | + |
| 117 | +## Import |
| 118 | + |
| 119 | +Import is supported using the following syntax: |
| 120 | + |
| 121 | +```shell |
| 122 | +terraform import elasticstack_fleet_package_policy.my_policy <fleet_package_policy_id> |
| 123 | +``` |
0 commit comments