SkollRyu / terraform-provider-opensearch

Home Page:https://registry.terraform.io/providers/opensearch-project/opensearch

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Terraform Provider OpenSearch

This is a terraform provider to provision OpenSearch resources.

Compatibility

This provider will target compatibility with major versions of Opensearch, each major version of this provider corresponding to the major version of Opensearch.

Opensearch version Supported
2.x

Supported Functionalities

Examples of resources can be found in the examples directory.

OpenSearch and OpenSearch Dashboards

Running tests locally

./script/install-tools
export OSS_IMAGE="opensearchproject/opensearch:2"
docker-compose up -d
docker-compose ps -a
export OPENSEARCH_URL=http://admin:admin@localhost:9200
export TF_LOG=INFO
cd ./provider
TF_ACC=1 go test ./... -v -parallel 20 -cover -short

Line by Line Explanation
Step 1: Install Tools

  • Purpose: Ensures that all the necessary tools and dependencies required for the testing environment are installed.
  • Command: ./script/install-tools

Step 2: Set Docker Image

  • Purpose: Sets the Docker image to be used for the OpenSearch instance. In this case, it's pulling the "opensearchproject/opensearch:2" image.
  • Command: export OSS_IMAGE="opensearchproject/opensearch:2"

Step 3: Start Docker Compose

  • Purpose: Launches the OpenSearch instance as a Docker container in the background using the specified image
  • Command: docker-compose up -d or docker compose up -d

Step 4: Check Docker Compose Status

  • Purpose: Displays the status of all containers managed by Docker Compose.
  • Command: docker-compose ps -a or docker compose ps -a

Step 5: Set OpenSearch URL

  • Purpose: Sets the environment variable OPENSEARCH_URL to the URL of the OpenSearch instance with the specified credentials (admin:admin) and port (9200).
  • Command: export OPENSEARCH_URL=http://admin:admin@localhost:9200

Step 6: Set Terraform Logging Level

  • Purpose: Sets the logging level for Terraform to INFO.
  • Command: export TF_LOG=INFO

Step 7: Change folder directory to provider

  • Purpose: Enable Go test to run within the provider directory.
  • Command: cd ./provider

Step 8: Enable Terraform Acceptance Tests

  • Purpose: Enables Terraform acceptance tests by setting the environment variable TF_ACC to 1. This allows running tests that interact with real resources.
  • Command: TF_ACC=1

Step 9: Run Terraform Tests

  • Purpose: Executes Terraform tests with specific configurations, verbosity, and parallelism.
  • Command: go test ./... -v -parallel 20 -cover -short

To Run Specific Test

cd provider/
TF_ACC=2 go test -run TestAccOpensearchOpenDistroDashboardTenant  -v -cover -short

Fix the go-lint errors

golangci-lint run --out-format=github-actions 

Debugging this provider

Build the executable, and start in debug mode:

$ go build
$ ./terraform-provider-opensearch -debuggable # or start in debug mode in your IDE
{"@level":"debug","@message":"plugin address","@timestamp":"2022-05-17T10:10:04.331668+01:00","address":"/var/folders/32/3mbbgs9x0r5bf991ltrl3p280010fs/T/plugin1346340234","network":"unix"}
Provider started, to attach Terraform set the TF_REATTACH_PROVIDERS env var:

        TF_REATTACH_PROVIDERS='{"registry.terraform.io/opensearch-project/opensearch":{"Protocol":"grpc","ProtocolVersion":5,"Pid":79075,"Test":true,"Addr":{"Network":"unix","String":"/var/folders/32/3mbbgs9x0r5bf991ltrl3p280010fs/T/plugin1346340234"}}}'

In another terminal, you can test your terraform code:

$ cd <my-project/terraform>
$ export TF_REATTACH_PROVIDERS=<env var above>
$ terraform apply

The local provider will be used instead, and you should see debug information printed to the terminal.

Version and Branching

As of now, this terraform-provider-opensearch repository maintains 2 branches:

  • main (2.x.x OpenSearch development)
  • 1.x (1.x.x OpenSearch development)

Contributors should choose the corresponding branch(es) when commiting their change(s):

  • If you have a change for a specific version, only open PR to specific branch
  • If you have a change for all available versions, first open a PR on main, then open a backport PR with [x] in the title, with label backport 1.x, etc.

Contributing

See developer guide and how to contribute to this project.

Getting Help

If you find a bug, or have a feature request, please don't hesitate to open an issue in this repository.

For more information, see project website and documentation. If you need help and are unsure where to open an issue, try forums.

Code of Conduct

This project has adopted the Amazon Open Source Code of Conduct. For more information see the Code of Conduct FAQ, or contact opensource-codeofconduct@amazon.com with any additional questions or comments.

Security

If you discover a potential security issue in this project we ask that you notify AWS/Amazon Security via our vulnerability reporting page. Please do not create a public GitHub issue.

License

This project is licensed under the Apache v2.0 License.

Copyright

Copyright OpenSearch Contributors. See NOTICE for details.

About

https://registry.terraform.io/providers/opensearch-project/opensearch

License:Apache License 2.0


Languages

Language:Go 98.3%Language:Shell 1.7%