Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 0 additions & 70 deletions .github/workflows/exporter-ci.yml

This file was deleted.

112 changes: 112 additions & 0 deletions .github/workflows/integration-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
name: Integration Test

on:
workflow_dispatch:
workflow_call:

permissions:
contents: read

env:
TF_VERSION: 1.10.5

jobs:
test-json-inventory:
name: Integration Test JSON Inventory
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Setup Go
uses: actions/setup-go@v5
with:
go-version-file: 'go.mod'
cache: true

- name: Download dependencies
run: go mod download

- name: Install Terraform exporter CLI
run: make install

- name: Setup Terraform CLI
uses: hashicorp/setup-terraform@v3.1
with:
terraform_version: ${{ env.TF_VERSION }}
terraform_wrapper: false

# Execute the JSON inventory setup for directory
# Execute Diff against reference file
# Execute the JSON inventory setup for subaccount
# Execute Diff against reference file
# Execute the JSON inventory setup for organization
# Execute Diff against reference file

# test-export-by-json:
# name: Integration Test Export by JSON
# runs-on: ubuntu-latest
# timeout-minutes: 5
# steps:
# - name: Checkout repository
# uses: actions/checkout@v4
#
# - name: Setup Go
# uses: actions/setup-go@v5
# with:
# go-version-file: 'go.mod'
# cache: true
#
# - name: Download dependencies
# run: go mod download
#
# - name: Install Terraform exporter CLI
# run: make install
#
# - name: Setup Terraform CLI
# uses: hashicorp/setup-terraform@v3.1
# with:
# terraform_version: ${{ env.TF_VERSION }}
# terraform_wrapper: false

# Execute the export by JSON for directory with curated inventory
# Execute Diff against reference file
# Execute the export by JSON for subaccount with curated inventory
# Execute Diff against reference file
# Execute the export by JSON for CF org with curated inventory
# Execute Diff against reference file

# test-export-by-resource:
# name: Integration Test Export by JSON
# runs-on: ubuntu-latest
# timeout-minutes: 5
# steps:
# - name: Checkout repository
# uses: actions/checkout@v4
#
# - name: Setup Go
# uses: actions/setup-go@v5
# with:
# go-version-file: 'go.mod'
# cache: true
#
# - name: Download dependencies
# run: go mod download
#
# - name: Install Terraform exporter CLI
# run: make install
#
# - name: Setup Terraform CLI
# uses: hashicorp/setup-terraform@v3.1
# with:
# terraform_version: ${{ env.TF_VERSION }}
# terraform_wrapper: false


# Execute the export by resource for directory with curated inventory
# Execute Diff against reference file
# Execute the export by resource for subaccount with curated inventory
# Execute Diff against reference file
# Execute the export by resource for CF org with curated inventory
# Execute Diff against reference file
3 changes: 3 additions & 0 deletions .wordlist.txt
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,15 @@ Terraform
Terraform's
terraform
Terraform's
Terramate
tf
TLS
toolchain
UIs
UI
VS
workspace
workspaces
YAML
yaml
yml
Expand Down
187 changes: 187 additions & 0 deletions integration-test/INTEGRATIONTEST.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,187 @@
# Terraform Setup of BTP Exporter Integration test

## Setup of infrastructure

The setup comprises:

- A managed directory on SAP BTP
- A subaccount including a Cloud Foundry runtime
- A Cloud Foundry organization with two spaces

The setup of the infrastructure is handled via Terramate. The following steps are needed to execute the setup of the sample used for integration testing:

1. Initialize the workspaces via

```bash
terramate run -X --tags dev --parallel 2 terraform init
```

2. Export variables for setup e.g., via `export $(xargs <.env)`

3. Execute the deployment

```bash
terramate script run --tags dev -X deploy
```

In case of a local storage of the state you can use the `teardown` script via

```bash
terramate script run --tags dev -X --reverse teardown
```

## Integration test

The integration test for the exporter is based on the reference setup described in the previous section

The test comprises the different flows and compares the results with a reference file:

- JSON inventory: reference file for the resulting JSON
- Export: reference state file


The check if the export is working at the point in time of the creation of the reference file is done by comparing a newly created file with the reference files using `diff`.

For the JSON inventory this is achieved via the the following statement

```
diff <(jq -S . btpResources_new.json) <(jq -S . btpResources_reference.json)
```

In case of the exports we must compare the resulting Terraform states after executing the import. As the state contains sensitive data, the reference state is stored as a GitHub secret. As it is JSON format, we transfer it into a string using base64 encoding.

The resulting comparison is then done in analogy to the JSON inventory file after decoding the string from the secret

### Flows and levels to check

The following matrix needs to be checked:

Supported levels:

- Directory level
- Subaccount level
- CF Organization level

Supported flows

- Creation of JSON inventory
- Export by JSON
- Export by resource

The export by JSON will be executed based on a curated JSON file to reduce the number of entitlements and roles.
The export by resource will be restricted so some resources as the basic export logic is already covered in the export by JSON flow using the same function for the export under the hood


## Terraform exporter commands

### JSON inventory

#### Directory

For reference data:

```bash
btptf create-json -d <directoryID> -p integrationTestDirectoryReference.json
```

For integration test data:

```bash
btptf create-json -d <directoryID> -p integrationTestDirectory.json
```

#### Subaccount

For reference data:

```bash
btptf create-json -s <subaccountID> -p integrationTestSubaccountReference.json
```

For integration test data:

```bash
btptf create-json -s <subaccountID> -p integrationTestSubaccount.json
```

#### Cloud Foundry Organization

For reference data:

```bash
btptf create-json -o <organizationID> -p integrationTestCfOrgReference.json
```

For integration test data:

```bash
btptf create-json -o <organizationID> -p integrationTestCfOrg.json
```

### Export by Resource

#### Directory

For integration test:

```bash
btptf export -d <directoryID> -c directory-export-by-resource -r=directory
terraform -chdir=directory-export-by-resource init
terraform -chdir=directory-export-by-resource apply -auto-approve
```

#### Subaccount

For integration test:

```bash
btptf export -s <subaccountID> -c subaccount-export-by-resource -r='subaccount,subscriptions'
terraform -chdir=subaccount-export-by-resource init
terraform -chdir=subaccount-export-by-resource apply -auto-approve
```

#### Cloud Foundry Organization

For integration test:

```bash
btptf export -o <organizationID> -c cforg-export-by-resource -r='spaces'
terraform -chdir=cforg-export-by-resource init
terraform -chdir=cforg-export-by-resource apply -auto-approve
```

### Export by JSON

#### Directory

For integration test:

```bash
btptf export-by-json -d <directoryID> -p integrationTestDirectoryCurated.json -c directory-export-by-json
terraform -chdir=directory-export-by-json init
terraform -chdir=directory-export-by-json apply -auto-approve
```

#### Subaccount

For integration test:

```bash
btptf export-by-json -s <subaccountID> -p integrationTestSubaccountCurated.json -c subaccount-export-by-json
terraform -chdir=subaccount-export-by-json init
terraform -chdir=subaccount-export-by-json apply -auto-approve
```

#### Cloud Foundry Organization

For integration test:

```bash
btptf export-by-json -o <organizationID> -p integrationTestCfOrgCurated.json -c cforg-export-by-json
terraform -chdir=cforg-export-by-json init
terraform -chdir=cforg-export-by-json apply -auto-approve
```

### Terraform metadata

As the Terraform state contains some metadata e.g., around the used Terraform CLI version, we must make sure that the setup in the GitHub Action comprises the same Terraform version as the one used to record the reference data
Loading
Loading