Skip to content

Commit 850b209

Browse files
(internal) Add validation test coverage (#16)
1 parent a982d1d commit 850b209

File tree

8 files changed

+301
-1
lines changed

8 files changed

+301
-1
lines changed

.github/workflows/ci-pull-request.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,13 @@ jobs:
3333
build-and-test:
3434
name: Build and Test
3535
runs-on: ubuntu-latest
36+
strategy:
37+
matrix:
38+
example:
39+
- "secure_config_posture_identity_access/single/main.tf"
40+
- "secure_config_posture_identity_access/organization/main.tf"
41+
- "secure_threat_detection/single/main.tf"
42+
- "secure_threat_detection/organization/main.tf"
3643
steps:
3744
- name: Set up Go
3845
uses: actions/setup-go@v2
@@ -54,4 +61,6 @@ jobs:
5461
# - name: Build
5562
# run: go build ./...
5663
- name: Test
64+
env:
65+
EXAMPLES: examples/${{ matrix.example }}
5766
run: make test

.gitignore

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
.idea
2+
3+
# Local .terraform directories
4+
**/.terraform/*
5+
6+
# .tfstate files
7+
*.tfstate
8+
*.tfstate.*
9+
10+
# Crash log files
11+
crash.log
12+
13+
# Ignore any .tfvars files that are generated automatically for each Terraform run. Most
14+
# .tfvars files are managed as part of configuration and so should be included in
15+
# version control.
16+
#
17+
# example.tfvars
18+
terraform.tfvars
19+
*.tfvars
20+
21+
# Ignore override files as they are usually used to override resources locally and so
22+
# are not checked in
23+
override.tf
24+
override.tf.json
25+
*_override.tf
26+
*_override.tf.json
27+
28+
.terraform.lock.hcl
29+
.envrc
30+
**/.envrc
31+
32+
*.patch
33+
34+
# MacOS
35+
.DS_Store

test/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
test:
2-
@echo "Functional Tests to be added here."
2+
./functional.sh
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
provider "google" {
2+
project = "mytestproject"
3+
region = "us-west1"
4+
}
5+
6+
module "organization-posture" {
7+
source = "../../../..//modules/services/service-principal"
8+
project_id = "mytestproject"
9+
service_account_name = "sysdig-secure"
10+
is_organizational = true
11+
organization_domain = "mytestorg.com"
12+
}
13+
14+
terraform {
15+
16+
required_providers {
17+
sysdig = {
18+
source = "sysdiglabs/sysdig"
19+
version = "~> 1.18.2"
20+
}
21+
}
22+
}
23+
24+
provider "sysdig" {
25+
sysdig_secure_url = "test_sysdig_secure_endpoint"
26+
sysdig_secure_api_token = "test_sysdig_secure_api_token"
27+
}
28+
29+
resource "sysdig_secure_cloud_auth_account" "gcp_project_mytestproject" {
30+
enabled = true
31+
provider_id = "mytestproject"
32+
provider_type = "PROVIDER_GCP"
33+
34+
feature {
35+
36+
secure_identity_entitlement {
37+
enabled = true
38+
components = ["COMPONENT_SERVICE_PRINCIPAL/secure-posture"]
39+
}
40+
41+
secure_config_posture {
42+
enabled = true
43+
components = ["COMPONENT_SERVICE_PRINCIPAL/secure-posture"]
44+
}
45+
}
46+
component {
47+
type = "COMPONENT_SERVICE_PRINCIPAL"
48+
instance = "secure-posture"
49+
service_principal_metadata = jsonencode({
50+
gcp = {
51+
key = module.organization-posture.service_account_key
52+
}
53+
})
54+
}
55+
component {
56+
type = "COMPONENT_SERVICE_PRINCIPAL"
57+
instance = "secure-onboarding"
58+
service_principal_metadata = jsonencode({
59+
gcp = {
60+
key = module.organization-posture.service_account_key
61+
}
62+
})
63+
}
64+
depends_on = [module.organization-posture]
65+
}
66+
67+
resource "sysdig_secure_organization" "gcp_organization_mytestproject" {
68+
management_account_id = sysdig_secure_cloud_auth_account.gcp_project_mytestproject.id
69+
depends_on = [module.organization-posture]
70+
}
71+
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
provider "google" {
2+
project = "mytestproject"
3+
region = "us-west1"
4+
}
5+
6+
module "project-posture" {
7+
source = "../../../..//modules/services/service-principal"
8+
project_id = "mytestproject"
9+
service_account_name = "sysdig-secure"
10+
}
11+
12+
terraform {
13+
14+
required_providers {
15+
sysdig = {
16+
source = "sysdiglabs/sysdig"
17+
version = "~> 1.18.2"
18+
}
19+
}
20+
}
21+
22+
provider "sysdig" {
23+
sysdig_secure_url = "test_sysdig_secure_endpoint"
24+
sysdig_secure_api_token = "test_sysdig_secure_api_token"
25+
}
26+
27+
resource "sysdig_secure_cloud_auth_account" "gcp_project_mytestproject" {
28+
enabled = true
29+
provider_id = "mytestproject"
30+
provider_type = "PROVIDER_GCP"
31+
32+
feature {
33+
34+
secure_identity_entitlement {
35+
enabled = true
36+
components = ["COMPONENT_SERVICE_PRINCIPAL/secure-posture"]
37+
}
38+
39+
secure_config_posture {
40+
enabled = true
41+
components = ["COMPONENT_SERVICE_PRINCIPAL/secure-posture"]
42+
}
43+
}
44+
component {
45+
type = "COMPONENT_SERVICE_PRINCIPAL"
46+
instance = "secure-posture"
47+
service_principal_metadata = jsonencode({
48+
gcp = {
49+
key = module.project-posture.service_account_key
50+
}
51+
})
52+
}
53+
depends_on = [module.project-posture]
54+
}
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
provider "google" {
2+
project = "mytestproject"
3+
region = "us-west1"
4+
}
5+
6+
module "organization-threat-detection" {
7+
source = "../../../..//modules/services/webhook-datasource"
8+
project_id = "mytestproject"
9+
push_endpoint = "test_sysdig_secure_cloudingestion_endpoint"
10+
is_organizational = true
11+
organization_domain = "mytestorg.com"
12+
}
13+
14+
module "organization-posture" {
15+
source = "../../../..//modules/services/service-principal"
16+
project_id = "mytestproject"
17+
service_account_name = "sysdig-secure"
18+
is_organizational = true
19+
organization_domain = "mytestorg.com"
20+
}
21+
22+
terraform {
23+
24+
required_providers {
25+
sysdig = {
26+
source = "sysdiglabs/sysdig"
27+
version = "~> 1.18.2"
28+
}
29+
}
30+
}
31+
32+
provider "sysdig" {
33+
sysdig_secure_url = "test_sysdig_secure_endpoint"
34+
sysdig_secure_api_token = "test_sysdig_secure_api_token"
35+
}
36+
37+
resource "sysdig_secure_cloud_auth_account" "gcp_project_mytestproject" {
38+
enabled = true
39+
provider_id = "mytestproject"
40+
provider_type = "PROVIDER_GCP"
41+
42+
feature {
43+
44+
secure_threat_detection {
45+
enabled = true
46+
components = ["COMPONENT_WEBHOOK_DATASOURCE/secure-runtime"]
47+
}
48+
}
49+
component {
50+
type = "COMPONENT_WEBHOOK_DATASOURCE"
51+
instance = "secure-runtime"
52+
}
53+
component {
54+
type = "COMPONENT_SERVICE_PRINCIPAL"
55+
instance = "secure-onboarding"
56+
service_principal_metadata = jsonencode({
57+
gcp = {
58+
key = module.organization-posture.service_account_key
59+
}
60+
})
61+
}
62+
}
63+
64+
resource "sysdig_secure_organization" "gcp_organization_mytestproject" {
65+
management_account_id = sysdig_secure_cloud_auth_account.gcp_project_mytestproject.id
66+
depends_on = [module.organization-posture]
67+
}
68+
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
provider "google" {
2+
project = "mytestproject"
3+
region = "us-west1"
4+
}
5+
6+
module "single-project-threat-detection" {
7+
source = "../../../..//modules/services/webhook-datasource"
8+
project_id = "mytestproject"
9+
push_endpoint = "test_sysdig_secure_cloudingestion_endpoint"
10+
}
11+
12+
terraform {
13+
14+
required_providers {
15+
sysdig = {
16+
source = "sysdiglabs/sysdig"
17+
version = "~> 1.18.2"
18+
}
19+
}
20+
}
21+
22+
provider "sysdig" {
23+
sysdig_secure_url = "test_sysdig_secure_endpoint"
24+
sysdig_secure_api_token = "test_sysdig_secure_api_token"
25+
}
26+
27+
resource "sysdig_secure_cloud_auth_account" "gcp_project_mytestproject" {
28+
enabled = true
29+
provider_id = "mytestproject"
30+
provider_type = "PROVIDER_GCP"
31+
32+
feature {
33+
34+
secure_threat_detection {
35+
enabled = true
36+
components = ["COMPONENT_WEBHOOK_DATASOURCE/secure-runtime"]
37+
}
38+
}
39+
component {
40+
type = "COMPONENT_WEBHOOK_DATASOURCE"
41+
instance = "secure-runtime"
42+
}
43+
}
44+

test/functional.sh

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/usr/bin/env bash
2+
3+
set -e
4+
5+
test -n "${EXAMPLES}" || EXAMPLES=$(find examples -type f -name main.tf)
6+
7+
for example in ${EXAMPLES} ; do
8+
printf "Functional testing - ${example}\n"
9+
example_dir="$(dirname ${example})"
10+
test -d "${example_dir}" || (printf "not an example directory: ${example_dir}\n" ; exit 1)
11+
pushd "${example_dir}"
12+
# run
13+
terraform init
14+
terraform validate
15+
16+
# cleanup (except configuration file)
17+
git clean -fxde main.tf
18+
popd
19+
done

0 commit comments

Comments
 (0)