Skip to content

Commit ff252d9

Browse files
committed
refactor(aws-privatelink): unify examples on endpoint-vpc + sensor-host modules
Delete the monolithic privatelink-stack module (~700 lines) that duplicated logic already present in endpoint-vpc and sensor-host. Rewrite example 01 (per-VPC) to compose the same two modules used by examples 02 and 03, proving the single-account case is just a simpler wiring of the same building blocks. Additional cleanup: - Remove all .tfvars references; inputs come exclusively via TF_VAR_ env vars - Add explicit random provider declaration to all root modules - Fix variable descriptions (s/Prefer exporting/Export/) - Update architecture doc to show env var exports instead of HCL snippets
1 parent 33bf38d commit ff252d9

24 files changed

Lines changed: 68 additions & 734 deletions

aws-privatelink/.gitignore

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,9 @@ tfplan
1010
# Provider plugins + local module caches
1111
.terraform/
1212

13-
# Variable files (often hold secrets)
13+
# Variable files (safety net — all inputs come via TF_VAR_ env vars)
1414
*.tfvars
1515
*.tfvars.json
16-
!example.tfvars
17-
!*.example.tfvars
1816

1917
# Override files
2018
override.tf

aws-privatelink/docs/architecture-01-per-vpc.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ shared network infrastructure between VPCs.
1010
This Terraform example deploys in one consumer Region, `us-east-2` by
1111
default, with two Availability Zones. For a US-2 Falcon CID, the VPC endpoints
1212
are created in `us-east-2` and connect to the CrowdStrike endpoint service in
13-
`us-west-2` over cross-region PrivateLink.
13+
`us-west-2` over cross-region PrivateLink. The example composes the same
14+
`endpoint-vpc` and `sensor-host` modules used by the multi-account examples
15+
(02, 03), wired to a single AWS account.
1416

1517
## Table of contents
1618

@@ -137,8 +139,6 @@ export TF_VAR_falcon_client_secret='...' # CrowdStrike API secret
137139
export TF_VAR_owner_email='you@example.com' # required owner tag
138140
```
139141

140-
Using `TF_VAR_*` avoids writing secrets into a `.tfvars` file.
141-
142142
### Apply
143143

144144
```bash
@@ -169,10 +169,10 @@ connectivity without deploying the consumer VPC in a Falcon home Region.
169169

170170
To change the consumer Region, set:
171171

172-
```hcl
173-
region = "eu-west-1"
174-
availability_zones = ["eu-west-1a", "eu-west-1b"]
175-
subnet_cidrs = ["10.50.1.0/24", "10.50.2.0/24"]
172+
```bash
173+
export TF_VAR_region='eu-west-1'
174+
export TF_VAR_availability_zones='["eu-west-1a", "eu-west-1b"]'
175+
export TF_VAR_subnet_cidrs='["10.50.1.0/24", "10.50.2.0/24"]'
176176
```
177177

178178
Avoid the unsupported Regions listed in the root README.
Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
# Single-region stack. Creates one VPC with endpoints across two AZs, S3
2-
# bucket, PHZ, IAM, and sensor host. service_region on the CrowdStrike
3-
# endpoints is derived inside the module from var.falcon_cloud vs.
4-
# var.region, so the stack reaches the US-2 service from wherever it is
5-
# deployed without any customer-facing toggle.
1+
# Single-account, single-region stack. Creates one VPC with CrowdStrike
2+
# PrivateLink endpoints, S3 bucket, PHZ, and a private sensor host. Uses
3+
# the same endpoint-vpc + sensor-host modules as 02 and 03 — the only
4+
# difference is that both modules share one provider and no RAM / TGW is
5+
# needed.
66
#
77
# The RPM and CID come from fetch.tf (root-level), so the Falcon API is
88
# hit once per apply.
@@ -11,8 +11,8 @@ locals {
1111
name_prefix = "${var.environment}-${var.name_prefix}"
1212
}
1313

14-
module "privatelink" {
15-
source = "../../modules/privatelink-stack"
14+
module "endpoint_vpc" {
15+
source = "../../modules/endpoint-vpc"
1616

1717
region = var.region
1818
availability_zones = var.availability_zones
@@ -22,6 +22,32 @@ module "privatelink" {
2222
subnet_cidrs = var.subnet_cidrs
2323

2424
falcon_cloud = var.falcon_cloud
25-
falcon_cid = local.fetched_cid
2625
sensor_rpm_path = local.fetched_rpm_path
26+
27+
# Single-account: no RAM subnet sharing needed.
28+
ram_principals = []
29+
30+
# Wire instance SG into the endpoints SG ingress.
31+
consumer_sg_ids = {
32+
sensor-host = module.sensor_host.instance_sg_id
33+
}
34+
}
35+
36+
module "sensor_host" {
37+
source = "../../modules/sensor-host"
38+
39+
region = var.region
40+
name_prefix = local.name_prefix
41+
42+
vpc_id = module.endpoint_vpc.vpc_id
43+
subnet_ids = module.endpoint_vpc.subnet_ids_list
44+
45+
endpoints_sg_id = module.endpoint_vpc.endpoints_sg_id
46+
s3_prefix_list_id = module.endpoint_vpc.s3_prefix_list_id
47+
48+
sensor_bucket_name = module.endpoint_vpc.sensor_bucket_name
49+
sensor_bucket_rpm_key = module.endpoint_vpc.sensor_bucket_rpm_key
50+
51+
falcon_cloud = var.falcon_cloud
52+
falcon_cid = local.fetched_cid
2753
}

aws-privatelink/examples/01-per-vpc/outputs.tf

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@ output "deployment" {
22
description = "Everything you need to SSM into, verify, and operate the stack."
33
value = {
44
region = var.region
5-
instance_ids = module.privatelink.instance_ids
6-
ami_id = module.privatelink.ami_id
7-
sensor_bucket = module.privatelink.sensor_bucket
8-
ssm_start_session_commands = module.privatelink.ssm_start_session_commands
9-
verification_commands = module.privatelink.verification_commands
10-
crowdstrike_endpoint_dns = module.privatelink.crowdstrike_endpoint_dns
5+
instance_ids = module.sensor_host.instance_ids
6+
ami_id = module.sensor_host.ami_id
7+
sensor_bucket = module.endpoint_vpc.sensor_bucket_name
8+
ssm_start_session_commands = module.sensor_host.ssm_start_session_commands
9+
verification_commands = module.sensor_host.verification_commands
10+
crowdstrike_endpoint_dns = module.endpoint_vpc.crowdstrike_endpoint_dns
1111
}
1212
}
1313

aws-privatelink/examples/01-per-vpc/variables.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,13 @@ variable "owner_email" {
4545
}
4646

4747
variable "falcon_client_id" {
48-
description = "CrowdStrike Falcon API client ID with Sensor Download: Read scope. Prefer exporting as TF_VAR_falcon_client_id."
48+
description = "CrowdStrike Falcon API client ID with Sensor Download: Read scope. Export as TF_VAR_falcon_client_id."
4949
type = string
5050
sensitive = true
5151
}
5252

5353
variable "falcon_client_secret" {
54-
description = "CrowdStrike Falcon API client secret. Prefer exporting as TF_VAR_falcon_client_secret."
54+
description = "CrowdStrike Falcon API client secret. Export as TF_VAR_falcon_client_secret."
5555
type = string
5656
sensitive = true
5757
}

aws-privatelink/examples/01-per-vpc/versions.tf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,9 @@ terraform {
1414
source = "hashicorp/null"
1515
version = ">= 3.2"
1616
}
17+
random = {
18+
source = "hashicorp/random"
19+
version = ">= 3.6"
20+
}
1721
}
1822
}

aws-privatelink/examples/02-shared-vpc/variables.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,13 @@ variable "owner_email" {
6565
}
6666

6767
variable "falcon_client_id" {
68-
description = "CrowdStrike Falcon API client ID with Sensor Download: Read scope. Prefer exporting as TF_VAR_falcon_client_id."
68+
description = "CrowdStrike Falcon API client ID with Sensor Download: Read scope. Export as TF_VAR_falcon_client_id."
6969
type = string
7070
sensitive = true
7171
}
7272

7373
variable "falcon_client_secret" {
74-
description = "CrowdStrike Falcon API client secret. Prefer exporting as TF_VAR_falcon_client_secret."
74+
description = "CrowdStrike Falcon API client secret. Export as TF_VAR_falcon_client_secret."
7575
type = string
7676
sensitive = true
7777
}

aws-privatelink/examples/02-shared-vpc/versions.tf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,9 @@ terraform {
1515
source = "hashicorp/null"
1616
version = ">= 3.2"
1717
}
18+
random = {
19+
source = "hashicorp/random"
20+
version = ">= 3.6"
21+
}
1822
}
1923
}

aws-privatelink/examples/03-tgw-profiles/variables.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,13 +77,13 @@ variable "owner_email" {
7777
}
7878

7979
variable "falcon_client_id" {
80-
description = "CrowdStrike Falcon API client ID with Sensor Download: Read scope. Prefer exporting as TF_VAR_falcon_client_id."
80+
description = "CrowdStrike Falcon API client ID with Sensor Download: Read scope. Export as TF_VAR_falcon_client_id."
8181
type = string
8282
sensitive = true
8383
}
8484

8585
variable "falcon_client_secret" {
86-
description = "CrowdStrike Falcon API client secret. Prefer exporting as TF_VAR_falcon_client_secret."
86+
description = "CrowdStrike Falcon API client secret. Export as TF_VAR_falcon_client_secret."
8787
type = string
8888
sensitive = true
8989
}

aws-privatelink/examples/03-tgw-profiles/versions.tf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,9 @@ terraform {
1515
source = "hashicorp/null"
1616
version = ">= 3.2"
1717
}
18+
random = {
19+
source = "hashicorp/random"
20+
version = ">= 3.6"
21+
}
1822
}
1923
}

0 commit comments

Comments
 (0)