Skip to content

Commit 3215801

Browse files
committed
address comments
Signed-off-by: kaituo <kaituo@amazon.com>
1 parent 22c3f1d commit 3215801

File tree

3 files changed

+42
-4
lines changed

3 files changed

+42
-4
lines changed

.gitignore

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,9 @@ out/
1515
.vscode
1616
bin/
1717
._.DS_Store
18-
src/test/resources/job-scheduler/
18+
src/test/resources/job-scheduler/
19+
20+
# Terraform local artifacts and secrets
21+
.terraform/
22+
*.tfstate*
23+
*.tfvars

scripts/terraform/README.md

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,40 @@ Defaults in [`main.tf`](main.tf) target local development:
3737

3838
You can change `opensearch_url` to your remote OpenSearch endpoint, for example `https://your-cluster.example.com:9200`.
3939

40-
If your cluster has security enabled, set username/password via `terraform.tfvars` or CLI flags.
40+
If your cluster has security enabled, prefer environment variables for credentials in production. `terraform.tfvars` and CLI flags also work, but they are less suitable for secrets.
41+
42+
Preferred example: environment variables
43+
44+
```bash
45+
export TF_VAR_opensearch_url='https://your-cluster.example.com:9200'
46+
export TF_VAR_opensearch_username='admin'
47+
export TF_VAR_opensearch_password='myStrongPassword123!'
48+
49+
terraform plan
50+
```
51+
52+
Example `terraform.tfvars`:
53+
54+
```hcl
55+
opensearch_url = "https://your-cluster.example.com:9200"
56+
opensearch_username = "admin"
57+
opensearch_password = "myStrongPassword123!"
58+
```
59+
60+
Example CLI flags:
61+
62+
```bash
63+
terraform plan \
64+
-var='opensearch_url=https://your-cluster.example.com:9200' \
65+
-var='opensearch_username=admin' \
66+
-var='opensearch_password=myStrongPassword123!'
67+
```
68+
69+
Avoid `-var` for passwords in production when possible, since command-line arguments can leak into shell history or CI logs.
70+
71+
If you use `terraform.tfvars`, make sure it is excluded from version control.
72+
73+
Important: this configuration currently stores connection settings in `null_resource` triggers so the destroy-time provisioner can stop the detector job. That means credentials may still be written to Terraform state even when provided via `TF_VAR_...` environment variables.
4174

4275
Common detector variables:
4376

scripts/terraform/main.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,14 +152,14 @@ if [ -n "$OPENSEARCH_USERNAME" ] || [ -n "$OPENSEARCH_PASSWORD" ]; then
152152
-H 'Content-Type: application/json' \
153153
--user "$OPENSEARCH_USERNAME:$OPENSEARCH_PASSWORD" >/dev/null || true
154154
155-
curl -sS -XPOST "$OPENSEARCH_URL/_plugins/_anomaly_detection/detectors/$DETECTOR_ID/_start" \
155+
curl -sSf -XPOST "$OPENSEARCH_URL/_plugins/_anomaly_detection/detectors/$DETECTOR_ID/_start" \
156156
-H 'Content-Type: application/json' \
157157
--user "$OPENSEARCH_USERNAME:$OPENSEARCH_PASSWORD" >/dev/null
158158
else
159159
curl -sS -XPOST "$OPENSEARCH_URL/_plugins/_anomaly_detection/detectors/$DETECTOR_ID/_stop" \
160160
-H 'Content-Type: application/json' >/dev/null || true
161161
162-
curl -sS -XPOST "$OPENSEARCH_URL/_plugins/_anomaly_detection/detectors/$DETECTOR_ID/_start" \
162+
curl -sSf -XPOST "$OPENSEARCH_URL/_plugins/_anomaly_detection/detectors/$DETECTOR_ID/_start" \
163163
-H 'Content-Type: application/json' >/dev/null
164164
fi
165165
EOT

0 commit comments

Comments
 (0)