Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ENG-56186 Added Sample test cases #65

Open
wants to merge 19 commits into
base: main
Choose a base branch
from
98 changes: 98 additions & 0 deletions .github/workflows/terratest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
name: Terraform Provider CI

on:
workflow_dispatch:
inputs:
url:
description: "Env of tests to run"
default: "https://app-dev.traceable.ai/graphql"
required: true
jwt:
description: "Enter the jwt"
required: true


env:
GO_VERSION: '1.22.2'
PYTHON_VERSION: '3.13.1'
TERRAFORM_VERSION: '1.9.8'


jobs:
build-and-test:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3

- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: ${{ env.GO_VERSION }}


- name: Set up Terraform
uses: hashicorp/setup-terraform@v3
with:
terraform_version: ${{ env.TERRAFORM_VERSION }}

- name: Install dependencies
run: |
go mod tidy
sudo apt-get update
sudo apt-get install -y python3-pip
pip3 install --upgrade pip
pip3 install junit2html

- name: Install dependencies
run: |
terraform --version
python3 --version
go version

- name: Install terratest_log_parser
run: |
go install github.com/gruntwork-io/terratest/cmd/terratest_log_parser@latest
export PATH=$PATH:$(go env GOPATH)/bin

- name: Build provider
run: |
set -x
go build -o terraform-provider-traceable
rm -rf .terraformrc terraform.tfstate terraform.tfstate.backup .terraform.lock.hcl .terraform
mkdir -p ~/.terraform.d/plugins/terraform.local/local/traceable/0.0.1/linux_amd64
mv terraform-provider-traceable ~/.terraform.d/plugins/terraform.local/local/traceable/0.0.1/linux_amd64

- name: Run tests
env:
JWT: ${{ github.event.inputs.jwt }}
URL: ${{ github.event.inputs.url}}

run: |
set -x
cd test
go clean -testcache
export PLATFORM_URL=${URL}
echo $PLATFORM_URL
export TRACEABLE_API_KEY=${JWT}
go test -v ./... | tee test_output.log
TEST_EXIT_CODE=${PIPESTATUS[0]}
terratest_log_parser -testlog test_output.log -outputdir test_results
exit $TEST_EXIT_CODE

- name: Convert test report
if: always()
run: |
set -x
cd test
junit2html test_results/report.xml test_results/report.html

- name: Archive test results
if: always()
uses: actions/upload-artifact@v4
with:
name: terrtest-test-results
path: |
set -x
test/test_results/report.html
test/test_output.log
25 changes: 25 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,3 +101,28 @@ resource "traceable_ip_range_rule" "my_ip_range" {
##### Optional:
- `expiration`: (string) expiration time of the rule (this attribute don't apply on `RULE_ACTION_ALERT`, don't pass this attribute if we need to block or allow indefinetly)
- `description`: (string) description of the rule





## Steps to Run a Terratest
```markdown
export PLATFORM_URL=""

export TRACEABLE_API_KEY=""

cd test

go test -v ./... | tee test_output.log

terratest_log_parser -testlog test_output.log -outputdir test_results

(By this commands a folder test_results is generated inside which report.xml is there)

junit2html test_results/report.xml /test_results/report.html

(By this command html report file is generated and junit2 is python package)

```

112 changes: 112 additions & 0 deletions examples/resources/traceable_custom_signature_allow/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
terraform {
required_providers {
traceable = {
source = "terraform.local/local/traceable"
version = "0.0.1"
}
}
}

variable "platform_url" {
type = string
description = "Traceable Platform URL"
}

variable "traceable_api_key" {
type = string
description = "Traceable API Key"
sensitive = true
}

variable "name" {
description = "Name of the dataset"
type = string
}

variable "description" {
description = "Description of the dataset"
type = string
}

variable "environments" {
description = "Name of Environemts on which to be enabled"
type = list(string)
}

variable "allow_expiry_duration" {
description = "Description of the dataset"
type = string
}

# variable "custom_sec_rule" {
# description = "Custom security rule"
# type = string
# }


variable "req_res_conditions" {
description = "Request response conditions"
type = list(object({
match_key = string
match_category = string
match_operator = string
match_value = string
}))
}



provider "traceable" {
platform_url = var.platform_url
api_token = var.traceable_api_key
}

resource "traceable_custom_signature_allow" "cs_allow" {
name = var.name
description = var.description
environments = var.environments
allow_expiry_duration = var.allow_expiry_duration
disabled = true

dynamic "req_res_conditions" {
for_each = var.req_res_conditions
content {
match_key = req_res_conditions.value.match_key
match_category = req_res_conditions.value.match_category
match_operator = req_res_conditions.value.match_operator
match_value = req_res_conditions.value.match_value
}
}

}



output "custom_id" {
value = traceable_custom_signature_allow.cs_allow.id
}


output "custom_name" {
value = traceable_custom_signature_allow.cs_allow.name
}

output "custom_description" {
value = traceable_custom_signature_allow.cs_allow.description
}

output "custom_environments" {
value = traceable_custom_signature_allow.cs_allow.environments
}

output "custom_allow_expiry_duration" {
value = traceable_custom_signature_allow.cs_allow.allow_expiry_duration
}

# output "custom_sec_rule" {
# value = traceable_custom_signature_allow.cs_allow.custom_sec_rule
# }




70 changes: 70 additions & 0 deletions examples/resources/traceable_data_set/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
terraform {
required_providers {
traceable = {
source ="terraform.local/local/traceable"
version = "0.0.1"
}
}

}

variable "platform_url" {
type = string
description = "Traceable Platform URL"
}


variable "traceable_api_key" {
type = string
description = "Traceable API Key"
sensitive = true
}


variable "name" {
description = "Name of the dataset"
type = string
}

variable "description" {
description = "Description of the dataset"
type = string
}

variable "icon_type" {
description = "Icon type for the dataset"
type = string
}





provider "traceable" {
platform_url =var.platform_url
api_token =var.traceable_api_key
}


resource "traceable_data_sets" "test_dataset" {
name = var.name
description = var.description
icon_type = var.icon_type
}

# Output values for testing
output "dataset_id" {
value = traceable_data_sets.test_dataset.id
}

output "dataset_name" {
value = traceable_data_sets.test_dataset.name
}

output "dataset_description" {
value = traceable_data_sets.test_dataset.description
}

output "dataset_icon_type" {
value = traceable_data_sets.test_dataset.icon_type
}
Loading
Loading