├── .github └── workflows │ ├── build.yml │ ├── release.yml │ └── test.yml ├── .gitignore ├── .go-version ├── .goreleaser.yml ├── LICENSE ├── Makefile ├── README.md ├── docs ├── data-sources │ ├── metric.md │ └── source.md ├── index.md └── resources │ ├── metric.md │ └── source.md ├── examples ├── README.md ├── advanced │ ├── main.tf │ ├── outputs.tf │ ├── variables.tf │ └── versions.tf ├── basic │ ├── main.tf │ ├── outputs.tf │ ├── variables.tf │ └── versions.tf └── scrape │ ├── main.tf │ ├── outputs.tf │ ├── variables.tf │ └── versions.tf ├── go.mod ├── go.sum ├── internal └── provider │ ├── client.go │ ├── data_metric.go │ ├── data_source.go │ ├── data_source_test.go │ ├── provider.go │ ├── provider_test.go │ ├── ptr.go │ ├── resource.go │ ├── resource_metric.go │ ├── resource_metric_test.go │ ├── resource_source.go │ └── resource_source_test.go ├── main.go ├── templates └── index.md.tmpl └── tools └── tools.go /.github/workflows/build.yml: -------------------------------------------------------------------------------- 1 | name: build 2 | on: 3 | push: 4 | branches: 5 | - main 6 | pull_request: 7 | branches: 8 | - main 9 | jobs: 10 | lint: 11 | runs-on: ubuntu-20.04 12 | steps: 13 | - uses: actions/checkout@v3 14 | - uses: actions/setup-go@v4 15 | with: 16 | go-version: '1.23.x' 17 | - run: make lint 18 | check_docs: 19 | runs-on: ubuntu-20.04 20 | steps: 21 | - uses: actions/checkout@v3 22 | - uses: actions/setup-go@v4 23 | with: 24 | go-version: '1.23.x' 25 | - name: Generate docs automatically 26 | run: make gen 27 | - name: Check no versioned file has been updated 28 | uses: numtide/clean-git-action@v1 29 | -------------------------------------------------------------------------------- /.github/workflows/release.yml: -------------------------------------------------------------------------------- 1 | # This GitHub action can publish assets for release when a tag is created. 2 | # Currently its setup to run on any tag that matches the pattern "v*" (ie. v0.1.0). 3 | # 4 | # This uses an action (hashicorp/ghaction-import-gpg) that assumes you set your 5 | # private key in the `GPG_PRIVATE_KEY` secret and passphrase in the `PASSPHRASE` 6 | # secret. If you would rather own your own GPG handling, please fork this action 7 | # or use an alternative one for key handling. 8 | # 9 | # You will need to pass the `--batch` flag to `gpg` in your signing step 10 | # in `goreleaser` to indicate this is being used in a non-interactive mode. 11 | # 12 | name: release 13 | on: 14 | push: 15 | tags: 16 | - 'v*' 17 | workflow_dispatch: 18 | 19 | jobs: 20 | goreleaser: 21 | runs-on: ubuntu-latest 22 | steps: 23 | - 24 | name: Checkout 25 | uses: actions/checkout@v2.3.4 26 | - 27 | name: Unshallow 28 | run: git fetch --prune --unshallow 29 | - 30 | name: Set up Go 31 | uses: actions/setup-go@v2 32 | with: 33 | go-version: '1.23.x' 34 | - 35 | name: Import GPG key 36 | id: import_gpg 37 | uses: crazy-max/ghaction-import-gpg@v5 38 | with: 39 | # These secrets are configured for the repository: 40 | gpg_private_key: ${{ secrets.GPG_PRIVATE_KEY }} 41 | passphrase: ${{ secrets.PASSPHRASE }} 42 | - 43 | name: Run GoReleaser 44 | uses: goreleaser/goreleaser-action@v3.2.0 45 | with: 46 | version: '~> 1.26' 47 | args: release --clean 48 | env: 49 | GPG_FINGERPRINT: ${{ steps.import_gpg.outputs.fingerprint }} 50 | # GitHub sets this automatically 51 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 52 | -------------------------------------------------------------------------------- /.github/workflows/test.yml: -------------------------------------------------------------------------------- 1 | name: tests 2 | on: 3 | push: 4 | branches: 5 | - master 6 | pull_request: 7 | workflow_dispatch: 8 | schedule: 9 | - cron: '0 3 * * *' 10 | jobs: 11 | test: 12 | strategy: 13 | matrix: 14 | go-version: ['1.23.x'] 15 | os: [ubuntu-latest, macos-latest, windows-latest] 16 | fail-fast: false 17 | runs-on: ${{ matrix.os }} 18 | steps: 19 | - name: Install Go 20 | uses: actions/setup-go@v2 21 | with: 22 | go-version: ${{ matrix.go-version }} 23 | - name: Checkout code 24 | uses: actions/checkout@v2 25 | - name: Test 26 | run: go test ./... 27 | 28 | e2e_test: 29 | strategy: 30 | matrix: 31 | terraform-version: ["0.13", "1.0", "1.8", "latest"] 32 | config: [examples/basic, examples/advanced, examples/scrape] 33 | fail-fast: false 34 | runs-on: ubuntu-latest 35 | steps: 36 | - name: Install Go 37 | uses: actions/setup-go@v2 38 | with: 39 | go-version: '1.23.x' 40 | - name: Install Terraform 41 | uses: hashicorp/setup-terraform@v3 42 | with: 43 | terraform_version: ${{ matrix.terraform-version }} 44 | - name: Checkout code 45 | uses: actions/checkout@v2 46 | - name: Add resources via Terraform 47 | run: make terraform CONFIGURATION="${{ matrix.config }}" ARGS="apply --auto-approve --input=false" 48 | env: 49 | LOGTAIL_API_TOKEN: ${{ secrets.LOGS_E2E_TEAM_TOKEN }} 50 | - name: Plan resources via Terraform - must be empty 51 | run: | 52 | make terraform CONFIGURATION="${{ matrix.config }}" ARGS="plan --input=false --out=tfplan" 53 | make terraform CONFIGURATION="${{ matrix.config }}" ARGS="show --json tfplan > tfplan.json" 54 | CHANGES="$(jq "[.resource_changes[]? | select(.change.actions != [\"no-op\"])] | length" "${{ matrix.config }}/tfplan.json")" 55 | if [ "$CHANGES" == "0" ]; then 56 | echo "No planned changes detected after first apply. Success!" 57 | else 58 | echo "$CHANGES planned changes detected after first apply. Failure!" 59 | exit 1 60 | fi 61 | env: 62 | LOGTAIL_API_TOKEN: ${{ secrets.LOGS_E2E_TEAM_TOKEN }} 63 | - name: Destroy resources via Terraform 64 | if: always() 65 | run: make terraform CONFIGURATION="${{ matrix.config }}" ARGS="destroy --auto-approve --input=false" 66 | env: 67 | LOGTAIL_API_TOKEN: ${{ secrets.LOGS_E2E_TEAM_TOKEN }} 68 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Binaries for programs and plugins 2 | *.exe 3 | *.exe~ 4 | *.dll 5 | *.so 6 | *.dylib 7 | 8 | # Test binary, built with `go test -c` 9 | *.test 10 | 11 | # Output of the go coverage tool, specifically when used with LiteIDE 12 | *.out 13 | 14 | terraform-provider-logtail 15 | 16 | /release/ 17 | terraform.tfstate 18 | terraform.tfstate.backup 19 | terraform.tfvars 20 | .terraform 21 | .terraform.lock.hcl 22 | -------------------------------------------------------------------------------- /.go-version: -------------------------------------------------------------------------------- 1 | 1.23 2 | -------------------------------------------------------------------------------- /.goreleaser.yml: -------------------------------------------------------------------------------- 1 | # Visit https://goreleaser.com for documentation on how to customize this 2 | # behavior. 3 | before: 4 | hooks: 5 | # this is just an example and not a requirement for provider building/publishing 6 | - go mod tidy 7 | builds: 8 | - env: 9 | # goreleaser does not work with CGO, it could also complicate 10 | # usage by users in CI/CD systems like Terraform Cloud where 11 | # they are unable to install libraries. 12 | - CGO_ENABLED=0 13 | mod_timestamp: '{{ .CommitTimestamp }}' 14 | flags: 15 | - -trimpath 16 | ldflags: 17 | - '-s -w -X main.version={{.Version}} -X main.commit={{.Commit}}' 18 | goos: 19 | - freebsd 20 | - windows 21 | - linux 22 | - darwin 23 | goarch: 24 | - amd64 25 | - '386' 26 | - arm 27 | - arm64 28 | ignore: 29 | - goos: darwin 30 | goarch: '386' 31 | - goos: windows 32 | goarch: arm64 33 | binary: '{{ .ProjectName }}_v{{ .Version }}' 34 | archives: 35 | - format: zip 36 | name_template: '{{ .ProjectName }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}' 37 | checksum: 38 | name_template: '{{ .ProjectName }}_{{ .Version }}_SHA256SUMS' 39 | algorithm: sha256 40 | signs: 41 | - artifacts: checksum 42 | args: 43 | # if you are using this in a GitHub action or some other automated pipeline, you 44 | # need to pass the batch flag to indicate its not interactive. 45 | - "--batch" 46 | - "--local-user" 47 | - "{{ .Env.GPG_FINGERPRINT }}" # set this environment variable for your signing key 48 | - "--output" 49 | - "${signature}" 50 | - "--detach-sign" 51 | - "${artifact}" 52 | release: 53 | # If you want to manually examine the release before its live, uncomment this line: 54 | # draft: true 55 | changelog: 56 | skip: true 57 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | SHELL := /bin/bash 2 | GOLANGCI_LINT := golangci-lint run --disable-all \ 3 | -E errcheck \ 4 | -E goimports \ 5 | -E gosimple \ 6 | -E govet \ 7 | -E ineffassign \ 8 | -E staticcheck \ 9 | -E typecheck \ 10 | -E unused 11 | VERSION := 0.4 12 | .PHONY: test build 13 | 14 | help: 15 | @echo Usage: 16 | @echo 17 | @echo " make clean" 18 | @echo 19 | @echo " # Regenerate docs/." 20 | @echo " make gen" 21 | @echo 22 | @echo " make lint" 23 | @echo " make fmt" 24 | @echo 25 | @echo " make test" 26 | @echo " make test-coverage" 27 | @echo 28 | @echo " make terraform CONFIGURATION=examples/basic ARGS=apply" 29 | @echo 30 | @echo " # Run in \"Debug\" mode (connect debugger to port 2345)." 31 | @echo " make debug" 32 | @echo 33 | @echo " # Install terraform-provider-logtail locally." 34 | @echo " #" 35 | @echo " # terraform {" 36 | @echo " # required_providers {" 37 | @echo " # custom = {" 38 | @echo " # source = \"registry.terraform.io/BetterStackHQ/logtail\"" 39 | @echo " # version = \"0.0.0-0\"" 40 | @echo " # }" 41 | @echo " # }" 42 | @echo " # }" 43 | @echo " make install" 44 | @echo 45 | @echo " # Upload terraform-provider-logtail to GitHub." 46 | @echo " make VERSION=0.0.0-0 release" 47 | @echo 48 | 49 | clean: 50 | rm -f cover.out coverage.html terraform-provider-logtail 51 | rm -rf release/ 52 | 53 | lint-init: 54 | @test -n "$$(which golangci-lint)" || (curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $$(go env GOPATH)/bin v1.64.6) 55 | 56 | lint: lint-init 57 | $(GOLANGCI_LINT) 58 | terraform fmt -check -diff -recursive 59 | 60 | fmt: lint-init 61 | $(GOLANGCI_LINT) --fix 62 | terraform fmt -recursive 63 | 64 | gen: 65 | terraform fmt -check -diff -recursive 66 | go generate ./... 67 | @echo 68 | @echo "docs/ can be previewed at https://registry.terraform.io/tools/doc-preview" 69 | 70 | test: 71 | go test ./... 72 | 73 | test-race: 74 | go test -race ./... 75 | 76 | test-coverage: 77 | go test -coverprofile cover.out ./... 78 | go tool cover -html=cover.out -o coverage.html 79 | rm -f cover.out 80 | @echo 81 | @echo "open coverage.html to review the report" 82 | 83 | # https://www.terraform.io/docs/extend/testing/acceptance-tests/index.html 84 | testacc: 85 | TF_ACC=1 go test ./... -v $(TESTARGS) -timeout 120m 86 | 87 | terraform: install 88 | cd $(CONFIGURATION) && rm -f .terraform.lock.hcl && terraform init && \ 89 | TF_LOG=DEBUG TF_PROVIDER_LOGTAIL_LOG_INSECURE=1 terraform $(ARGS) 90 | 91 | build: 92 | # -gcflags "all=-N -l" is here for delve (`go tool compile -help` for more) 93 | go build -gcflags "all=-N -l" -ldflags "-X main.version=$(VERSION)" 94 | 95 | install: build 96 | PLUGIN_DIR="$$HOME/.terraform.d/plugins/registry.terraform.io/BetterStackHQ/logtail/$(VERSION)/$$(go env GOOS)_$$(go env GOARCH)" && \ 97 | mkdir -p "$$PLUGIN_DIR" && \ 98 | cp terraform-provider-logtail "$$PLUGIN_DIR/" 99 | 100 | uninstall: 101 | rm -rf "$$HOME/.terraform.d/plugins/registry.terraform.io/BetterStackHQ/logtail/$(VERSION)" 102 | 103 | debug: build 104 | # https://github.com/go-delve/delve/blob/master/Documentation/installation/README.md 105 | dlv --listen=:2345 --headless=true --api-version=2 --accept-multiclient exec ./terraform-provider-logtail -- --debug 106 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # terraform-provider-logtail 2 | [![build](https://github.com/BetterStackHQ/terraform-provider-logtail/actions/workflows/build.yml/badge.svg?branch=main)](https://github.com/BetterStackHQ/terraform-provider-logtail/actions/workflows/build.yml) 3 | [![tests](https://github.com/BetterStackHQ/terraform-provider-logtail/actions/workflows/test.yml/badge.svg?branch=main)](https://github.com/BetterStackHQ/terraform-provider-logtail/actions/workflows/test.yml) 4 | [![documentation](https://img.shields.io/badge/-documentation-blue)](https://registry.terraform.io/providers/BetterStackHQ/logtail/latest/docs) 5 | 6 | Terraform (0.13+) provider for [Better Stack Telemetry](https://betterstack.com/logs) (formerly *Logtail.com*). 7 | 8 | ## Installation 9 | 10 | ```terraform 11 | terraform { 12 | required_version = ">= 0.13" 13 | required_providers { 14 | logtail = { 15 | source = "BetterStackHQ/logtail" 16 | version = ">= 0.2.0" 17 | } 18 | } 19 | } 20 | ``` 21 | 22 | ## Example usage 23 | 24 | See [`/examples` directory](./examples) for multiple ready-to-use examples. 25 | Here's a simple one to get you started: 26 | 27 | ```terraform 28 | provider "logtail" { 29 | # `api_token` can be omitted if LOGTAIL_API_TOKEN env var is set. 30 | api_token = "XXXXXXXXXXXXXXXXXXXXXXXX" 31 | } 32 | 33 | resource "logtail_source" "this" { 34 | name = "Production Server" 35 | platform = "ubuntu" 36 | } 37 | 38 | output "logtail_source_token" { 39 | value = logtail_source.this.token 40 | } 41 | ``` 42 | 43 | ## Documentation 44 | 45 | See [Better Stack Telemetry API docs](https://betterstack.com/docs/logs/api/getting-started/) to obtain API token and get the complete list of parameter options. 46 | Or explore the [Terraform Registry provider documentation](https://registry.terraform.io/providers/BetterStackHQ/logtail/latest/docs). 47 | 48 | ## Development 49 | 50 | > PREREQUISITE: [go1.23+](https://golang.org/dl/). 51 | 52 | ```shell script 53 | git clone https://github.com/betterstackhq/terraform-provider-logtail && \ 54 | cd terraform-provider-logtail 55 | 56 | make help 57 | ``` 58 | 59 | ## Releasing New Versions 60 | 61 | Simply push a new tag `vX.Y.Z` to GitHub and a new version will be built and released automatically through a GitHub action. 62 | -------------------------------------------------------------------------------- /docs/data-sources/metric.md: -------------------------------------------------------------------------------- 1 | --- 2 | # generated by https://github.com/hashicorp/terraform-plugin-docs 3 | page_title: "logtail_metric Data Source - terraform-provider-logtail" 4 | subcategory: "" 5 | description: |- 6 | This Data Source allows you to look up existing Metrics using their name. You can list all your existing metrics via the Metrics API https://betterstack.com/docs/logs/api/list-all-existing-metrics/. 7 | --- 8 | 9 | # logtail_metric (Data Source) 10 | 11 | This Data Source allows you to look up existing Metrics using their name. You can list all your existing metrics via the [Metrics API](https://betterstack.com/docs/logs/api/list-all-existing-metrics/). 12 | 13 | 14 | 15 | 16 | ## Schema 17 | 18 | ### Required 19 | 20 | - `name` (String) The name of this metric. 21 | - `source_id` (String) The ID of the source this metric belongs to. 22 | 23 | ### Read-Only 24 | 25 | - `aggregations` (List of String) The list of aggregations to perform on the metric. 26 | - `id` (String) The ID of this metric. 27 | - `sql_expression` (String) The SQL expression used to extract the metric value. 28 | - `team_name` (String) Used to specify the team the resource should be created in when using global tokens. 29 | - `type` (String) The type of the metric. 30 | -------------------------------------------------------------------------------- /docs/data-sources/source.md: -------------------------------------------------------------------------------- 1 | --- 2 | # generated by https://github.com/hashicorp/terraform-plugin-docs 3 | page_title: "logtail_source Data Source - terraform-provider-logtail" 4 | subcategory: "" 5 | description: |- 6 | This Data Source allows you to look up existing Sources using their table name. The table name is shown on the Source settings page on logs.betterstack.com or you can list all your existing sources via the Sources API https://betterstack.com/docs/logs/api/list-all-existing-sources/. 7 | --- 8 | 9 | # logtail_source (Data Source) 10 | 11 | This Data Source allows you to look up existing Sources using their table name. The table name is shown on the Source settings page on logs.betterstack.com or you can list all your existing sources via the [Sources API](https://betterstack.com/docs/logs/api/list-all-existing-sources/). 12 | 13 | 14 | 15 | 16 | ## Schema 17 | 18 | ### Required 19 | 20 | - `table_name` (String) The table name generated for this source. 21 | 22 | ### Read-Only 23 | 24 | - `created_at` (String) The time when this monitor group was created. 25 | - `data_region` (String) Region where we store your data. 26 | - `id` (String) The ID of this source. 27 | - `ingesting_host` (String) The host where the logs or metrics should be sent. See [documentation](https://betterstack.com/docs/logs/start/) for your specific source platform for details. 28 | - `ingesting_paused` (Boolean) This property allows you to temporarily pause data ingesting for this source (e.g., when you are reaching your plan's usage quota and you want to prioritize some sources over others). 29 | - `live_tail_pattern` (String) Freeform text template for formatting Live tail output with columns wrapped in {column} brackets. Example: "PID: {message_json.pid} {level} {message}" 30 | - `logs_retention` (Number) Data retention for logs in days. There might be additional charges for longer retention. 31 | - `metrics_retention` (Number) Data retention for metrics in days. There might be additional charges for longer retention. 32 | - `name` (String) The name of this source. 33 | - `platform` (String) The platform of this source. This value can be set only when you're creating a new source. You can't update this value later. Valid values are: 34 | - `apache2` 35 | - `aws_cloudwatch` 36 | - `aws_ecs` 37 | - `aws_elb` 38 | - `aws_fargate` 39 | - `cloudflare_logpush` 40 | - `cloudflare_worker` 41 | - `datadog_agent` 42 | - `digitalocean` 43 | - `docker` 44 | - `dokku` 45 | - `dotnet` 46 | - `elasticsearch` 47 | - `erlang` 48 | - `filebeat` 49 | - `flights` 50 | - `fluentbit` 51 | - `fluentd` 52 | - `fly_io` 53 | - `go` 54 | - `google_cloud_pubsub` 55 | - `haproxy` 56 | - `heroku` 57 | - `http` 58 | - `java` 59 | - `javascript` 60 | - `kubernetes` 61 | - `logstash` 62 | - `minio` 63 | - `mongodb` 64 | - `mysql` 65 | - `nginx` 66 | - `open_telemetry` 67 | - `php` 68 | - `postgresql` 69 | - `prometheus` 70 | - `prometheus_scrape` 71 | - `python` 72 | - `rabbitmq` 73 | - `redis` 74 | - `render` 75 | - `rsyslog` 76 | - `ruby` 77 | - `syslog-ng` 78 | - `traefik` 79 | - `ubuntu` 80 | - `vector` 81 | - `vercel_integration` 82 | - `scrape_frequency_secs` (Number) For scrape platform types, how often to scrape the URLs. 83 | - `scrape_request_basic_auth_password` (String, Sensitive) Basic auth password for scraping. 84 | - `scrape_request_basic_auth_user` (String) Basic auth username for scraping. 85 | - `scrape_request_headers` (List of Map of String) An array of request headers, each containing `name` and `value` fields. 86 | - `scrape_urls` (List of String) For scrape platform types, the set of urls to scrape. 87 | - `team_name` (String) Used to specify the team the resource should be created in when using global tokens. 88 | - `token` (String) The token of this source. This token is used to identify and route the data you will send to Better Stack. 89 | - `updated_at` (String) The time when this monitor group was updated. 90 | -------------------------------------------------------------------------------- /docs/index.md: -------------------------------------------------------------------------------- 1 | --- 2 | layout: "" 3 | page_title: "Provider: logtail" 4 | description: |- 5 | The Better Stack Telemetry provider. 6 | --- 7 | 8 | # Better Stack Telemetry Provider 9 | 10 | [Better Stack Telemetry](https://logs.betterstack.com) provider provides resources to interact with the [Telemetry API](https://betterstack.com/docs/logs/api/getting-started/). 11 | 12 | ## Installation 13 | 14 | ```terraform 15 | terraform { 16 | required_version = ">= 0.13" 17 | required_providers { 18 | logtail = { 19 | source = "BetterStackHQ/logtail" 20 | version = ">= 0.2.0" 21 | } 22 | } 23 | } 24 | ``` 25 | 26 | ## Example usage 27 | 28 | In our GitHub repository, you can [see multiple executable examples](https://github.com/BetterStackHQ/terraform-provider-logtail/tree/master/examples). 29 | Here's a simple one to get you started: 30 | 31 | ```terraform 32 | provider "logtail" { 33 | # `api_token` can be omitted if LOGTAIL_API_TOKEN env var is set. 34 | api_token = "XXXXXXXXXXXXXXXXXXXXXXXX" 35 | } 36 | 37 | resource "logtail_source" "this" { 38 | name = "Production Server" 39 | platform = "ubuntu" 40 | } 41 | 42 | output "logtail_source_token" { 43 | value = logtail_source.this.token 44 | } 45 | ``` 46 | 47 | 48 | ## Schema 49 | 50 | ### Required 51 | 52 | - `api_token` (String, Sensitive) Better Stack Telemetry API token. The value can be omitted if `LOGTAIL_API_TOKEN` environment variable is set. See https://betterstack.com/docs/logs/api/getting-started/#get-an-logs-api-token on how to obtain the API token for your team. 53 | -------------------------------------------------------------------------------- /docs/resources/metric.md: -------------------------------------------------------------------------------- 1 | --- 2 | # generated by https://github.com/hashicorp/terraform-plugin-docs 3 | page_title: "logtail_metric Resource - terraform-provider-logtail" 4 | subcategory: "" 5 | description: |- 6 | This resource allows you to create and delete Metrics. 7 | --- 8 | 9 | # logtail_metric (Resource) 10 | 11 | This resource allows you to create and delete Metrics. 12 | 13 | 14 | 15 | 16 | ## Schema 17 | 18 | ### Required 19 | 20 | - `aggregations` (List of String) The list of aggregations to perform on the metric. 21 | - `name` (String) The name of this metric. 22 | - `source_id` (String) The ID of the source this metric belongs to. 23 | - `sql_expression` (String) The SQL expression used to extract the metric value. 24 | - `type` (String) The type of the metric. 25 | 26 | ### Optional 27 | 28 | - `team_name` (String) Used to specify the team the resource should be created in when using global tokens. 29 | 30 | ### Read-Only 31 | 32 | - `id` (String) The ID of this metric. 33 | -------------------------------------------------------------------------------- /docs/resources/source.md: -------------------------------------------------------------------------------- 1 | --- 2 | # generated by https://github.com/hashicorp/terraform-plugin-docs 3 | page_title: "logtail_source Resource - terraform-provider-logtail" 4 | subcategory: "" 5 | description: |- 6 | This resource allows you to create, modify, and delete your Sources. For more information about the Sources API check https://betterstack.com/docs/logs/api/list-all-existing-sources/ 7 | --- 8 | 9 | # logtail_source (Resource) 10 | 11 | This resource allows you to create, modify, and delete your Sources. For more information about the Sources API check https://betterstack.com/docs/logs/api/list-all-existing-sources/ 12 | 13 | 14 | 15 | 16 | ## Schema 17 | 18 | ### Required 19 | 20 | - `name` (String) The name of this source. 21 | - `platform` (String) The platform of this source. This value can be set only when you're creating a new source. You can't update this value later. Valid values are: 22 | - `apache2` 23 | - `aws_cloudwatch` 24 | - `aws_ecs` 25 | - `aws_elb` 26 | - `aws_fargate` 27 | - `cloudflare_logpush` 28 | - `cloudflare_worker` 29 | - `datadog_agent` 30 | - `digitalocean` 31 | - `docker` 32 | - `dokku` 33 | - `dotnet` 34 | - `elasticsearch` 35 | - `erlang` 36 | - `filebeat` 37 | - `flights` 38 | - `fluentbit` 39 | - `fluentd` 40 | - `fly_io` 41 | - `go` 42 | - `google_cloud_pubsub` 43 | - `haproxy` 44 | - `heroku` 45 | - `http` 46 | - `java` 47 | - `javascript` 48 | - `kubernetes` 49 | - `logstash` 50 | - `minio` 51 | - `mongodb` 52 | - `mysql` 53 | - `nginx` 54 | - `open_telemetry` 55 | - `php` 56 | - `postgresql` 57 | - `prometheus` 58 | - `prometheus_scrape` 59 | - `python` 60 | - `rabbitmq` 61 | - `redis` 62 | - `render` 63 | - `rsyslog` 64 | - `ruby` 65 | - `syslog-ng` 66 | - `traefik` 67 | - `ubuntu` 68 | - `vector` 69 | - `vercel_integration` 70 | 71 | ### Optional 72 | 73 | - `data_region` (String) Region where we store your data. 74 | - `ingesting_paused` (Boolean) This property allows you to temporarily pause data ingesting for this source (e.g., when you are reaching your plan's usage quota and you want to prioritize some sources over others). 75 | - `live_tail_pattern` (String) Freeform text template for formatting Live tail output with columns wrapped in {column} brackets. Example: "PID: {message_json.pid} {level} {message}" 76 | - `logs_retention` (Number) Data retention for logs in days. There might be additional charges for longer retention. 77 | - `metrics_retention` (Number) Data retention for metrics in days. There might be additional charges for longer retention. 78 | - `scrape_frequency_secs` (Number) For scrape platform types, how often to scrape the URLs. 79 | - `scrape_request_basic_auth_password` (String, Sensitive) Basic auth password for scraping. 80 | - `scrape_request_basic_auth_user` (String) Basic auth username for scraping. 81 | - `scrape_request_headers` (List of Map of String) An array of request headers, each containing `name` and `value` fields. 82 | - `scrape_urls` (List of String) For scrape platform types, the set of urls to scrape. 83 | - `team_name` (String) Used to specify the team the resource should be created in when using global tokens. 84 | 85 | ### Read-Only 86 | 87 | - `created_at` (String) The time when this monitor group was created. 88 | - `id` (String) The ID of this source. 89 | - `ingesting_host` (String) The host where the logs or metrics should be sent. See [documentation](https://betterstack.com/docs/logs/start/) for your specific source platform for details. 90 | - `table_name` (String) The table name generated for this source. 91 | - `token` (String) The token of this source. This token is used to identify and route the data you will send to Better Stack. 92 | - `updated_at` (String) The time when this monitor group was updated. 93 | -------------------------------------------------------------------------------- /examples/README.md: -------------------------------------------------------------------------------- 1 | # Example usage 2 | [![build](https://github.com/BetterStackHQ/terraform-provider-logtail/actions/workflows/build.yml/badge.svg?branch=main)](https://github.com/BetterStackHQ/terraform-provider-logtail/actions/workflows/build.yml) 3 | [![tests](https://github.com/BetterStackHQ/terraform-provider-logtail/actions/workflows/test.yml/badge.svg?branch=main)](https://github.com/BetterStackHQ/terraform-provider-logtail/actions/workflows/test.yml) 4 | [![documentation](https://img.shields.io/badge/-documentation-blue)](https://registry.terraform.io/providers/BetterStackHQ/logtail/latest/docs) 5 | 6 | These examples demonstrate how to provision and manage resources such as sources and metrics in Better Stack using Terraform. 7 | 8 | For instructions how to try the examples for yourself, see the subdirectories. 9 | You can start with the [basic example](./basic). 10 | 11 | ## Documentation 12 | 13 | See [Better Stack Telemetry API docs](https://betterstack.com/docs/logs/api/getting-started/) to obtain API token and get the complete list of parameter options. 14 | Or explore the [Terraform Registry provider documentation](https://registry.terraform.io/providers/BetterStackHQ/logtail/latest/docs). 15 | -------------------------------------------------------------------------------- /examples/advanced/main.tf: -------------------------------------------------------------------------------- 1 | provider "logtail" { 2 | api_token = var.logtail_api_token 3 | } 4 | 5 | resource "logtail_source" "this" { 6 | name = "Terraform Advanced Source" 7 | platform = "http" 8 | ingesting_paused = true 9 | live_tail_pattern = "{level} {message}" 10 | logs_retention = 60 11 | metrics_retention = 90 12 | } 13 | 14 | resource "logtail_metric" "duration_ms" { 15 | source_id = logtail_source.this.id 16 | name = "duration_ms" 17 | sql_expression = "getJSON(raw, 'duration_ms')" 18 | aggregations = ["avg", "max", "min"] 19 | type = "float64_delta" 20 | } 21 | 22 | resource "logtail_metric" "service_name" { 23 | source_id = logtail_source.this.id 24 | name = "service_name" 25 | sql_expression = "getJSON(raw, 'service_name')" 26 | aggregations = [] 27 | type = "string_low_cardinality" 28 | } 29 | 30 | data "logtail_metric" "level" { 31 | source_id = logtail_source.this.id 32 | name = "level" 33 | } 34 | -------------------------------------------------------------------------------- /examples/advanced/outputs.tf: -------------------------------------------------------------------------------- 1 | output "logtail_source_token" { 2 | value = logtail_source.this.token 3 | } 4 | output "logtail_ingesting_host" { 5 | value = logtail_source.this.ingesting_host 6 | } 7 | 8 | output "default_metric_expression" { 9 | value = data.logtail_metric.level.sql_expression 10 | } 11 | -------------------------------------------------------------------------------- /examples/advanced/variables.tf: -------------------------------------------------------------------------------- 1 | variable "logtail_api_token" { 2 | type = string 3 | description = <