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

Feature/resources-onboarding-team #9

Merged
merged 33 commits into from
Apr 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
d42f474
Add resource workflow_group
piroux-sg Mar 8, 2024
917f370
Add resource role
piroux-sg Mar 8, 2024
195e0e9
Add resource connector_cloud (WIP)
piroux-sg Mar 8, 2024
3822174
Fix connector_cloud: without integrationgroups
piroux-sg Mar 8, 2024
2141655
Add resource connector_vcs
piroux-sg Mar 8, 2024
d483d2f
Add resource secret
piroux-sg Mar 11, 2024
3add87a
Add examples for new resources
piroux-sg Mar 11, 2024
ab5bd47
Add instructions for running examples
piroux-sg Mar 11, 2024
d063d27
Add debug mode to provider
piroux-sg Mar 11, 2024
adfdf67
Fix & Clean comments
piroux-sg Mar 11, 2024
ac362f0
Fix Import method for newly added resources
piroux-sg Mar 21, 2024
0512a61
Add API_URI as parameter to Provider
piroux-sg Mar 27, 2024
c8a1040
Fix quickstart Example with WF template on STG & PRD
piroux-sg Mar 27, 2024
2d30c0b
Add WF-Group to Quickstart example
piroux-sg Mar 27, 2024
392e62a
Fix unit Tests for prd/stg envs
piroux-sg Mar 28, 2024
e2b7654
Improve and Fix quickstart Example
piroux-sg Mar 28, 2024
9ccf3f2
Update GH Workflows
piroux-sg Mar 28, 2024
40722bd
Fix WF-Outputs datasource name
piroux-sg Mar 29, 2024
a582d97
Fix Provider parameters docs
piroux-sg Mar 29, 2024
b9a2efe
Add link to API docs for documented resources
piroux-sg Mar 29, 2024
3368347
Transition docs towards templates based generation
piroux-sg Mar 29, 2024
7c6e988
Add newly generated docs
piroux-sg Mar 29, 2024
8c15f4e
Fix commands for Examples Tests
piroux-sg Mar 29, 2024
1021109
Fix TODOs for Release
piroux-sg Mar 29, 2024
17931b3
Clean GH Workflows
piroux-sg Mar 29, 2024
2bcd64e
Change gitref for test-api-prd GH Workflow
piroux-sg Mar 29, 2024
ca4e1bf
Mock PRD with STG for tentative release before pre BE-release in PRD
piroux-sg Mar 29, 2024
16d419d
Fix elease_post-test job with API_URI env
piroux-sg Mar 30, 2024
c2cf546
Revert "Mock PRD with STG for tentative release before pre BE-release…
piroux-sg Apr 2, 2024
7e8d66f
Remove push event for test-api GH Workflows
piroux-sg Apr 2, 2024
134ce78
Update Makefile
piroux-sg Apr 2, 2024
d794332
Fix titles for docs guides
piroux-sg Apr 2, 2024
d789ed5
Activate periodic API tests
piroux-sg Apr 2, 2024
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
11 changes: 6 additions & 5 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,17 @@ jobs:
uses: hashicorp/setup-terraform@v3
with:
terraform_wrapper: false
terraform_version: '1.5.7' # TODO: matrix of terraform & tofu versions
terraform_version: '1.5.7'

- name: "Test Provider with quickstart example"
run: |
set -eu -x;
TAG=${{ github.ref_name }};
VERSION=${TAG#v};
make test-example ARGS="-v ${VERSION} -f github-release-draft";
make test-examples-quickstart ARGS="-v ${VERSION} -f github-release-draft";
shell: bash
env:
STACKGUARDIAN_API_KEY: ${{ secrets.STACKGUARDIAN_API_KEY }}
STACKGUARDIAN_ORG_NAME: ${{ secrets.STACKGUARDIAN_ORG_NAME }}
GH_TOKEN: ${{ github.token }}
STACKGUARDIAN_API_KEY: '${{ secrets.SG_PRD_API_KEY }}'
STACKGUARDIAN_API_URI: '${{ secrets.SG_PRD_API_URI }}'
STACKGUARDIAN_ORG_NAME: '${{ secrets.SG_PRD_ORG_NAME }}'
GH_TOKEN: '${{ github.token }}'
16 changes: 16 additions & 0 deletions .github/workflows/test-api-prd.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: "Test API-PRD with TF-Provider" # for API High-Load with examples on API-PRD

on:
schedule:
- cron: '*/10 * 1-10 4 *'
workflow_dispatch:

jobs:

api_test:
name: "Test API-PRD with TF-Provider"
uses: ./.github/workflows/test-api.yaml
secrets: inherit
with:
gitref: main
testenv: PRD
16 changes: 16 additions & 0 deletions .github/workflows/test-api-stg.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: "Test API-STG with TF-Provider" # for API High-Load with examples on API-STG

on:
schedule:
- cron: '*/10 * 1-10 4 *'
workflow_dispatch:

jobs:

api_test:
name: "Test API-STG with TF-Provider"
uses: ./.github/workflows/test-api.yaml
secrets: inherit
with:
gitref: devel
testenv: STG
121 changes: 121 additions & 0 deletions .github/workflows/test-api.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
name: "Test API with TF-Provider" # with examples on one API env

on:
workflow_call:
inputs:
gitref:
type: string
default: 'devel'
required: true
testenv:
type: string
default: PRD
required: true
description: "STG|PRD"

jobs:

api_examples-test:
name: "Test API with Provider examples"
runs-on: ubuntu-latest
steps:

- name: "Checkout code"
if: ${{ !env.ACT }}
uses: actions/checkout@v4
with:
ref: '${{ inputs.gitref }}'

- name: "Checkout code (local)"
if: env.ACT
uses: actions/checkout@v4

- name: "Verify checked-out code (local)"
if: ${{ env.ACT }}
run: |
git --no-pager show --stat;
git --no-pager status;

- name: "Install Go"
uses: actions/setup-go@v5
with:
go-version-file: 'go.mod'

- name: "Install Terraform"
uses: hashicorp/setup-terraform@v3
with:
terraform_wrapper: false
terraform_version: '1.5.7'

- name: "Build Provider"
run: make build


### --- testenv: STG ----------------------------------------------------

- name: "Test API-STG with Provider acceptance tests"
if: inputs.testenv=='STG'
run: make test-acc
env:
STACKGUARDIAN_API_URI: '${{ secrets.SG_STG_API_URI }}'
STACKGUARDIAN_API_KEY: '${{ secrets.SG_STG_API_KEY }}'
STACKGUARDIAN_ORG_NAME: '${{ secrets.SG_STG_ORG_NAME }}'

- name: "Test API-STG with Provider quickstart example"
if: inputs.testenv=='STG'
run: |
set -eu -x;
make install;
make test-examples-quickstart ARGS="-f local-build";
shell: bash
env:
STACKGUARDIAN_API_URI: '${{ secrets.SG_STG_API_URI }}'
STACKGUARDIAN_API_KEY: '${{ secrets.SG_STG_API_KEY }}'
STACKGUARDIAN_ORG_NAME: '${{ secrets.SG_STG_ORG_NAME }}'

- name: "Test API-STG with Provider onboarding example"
if: inputs.testenv=='STG'
run: |
set -eu -x;
make install;
make test-examples-onboarding ARGS="-f local-build";
shell: bash
env:
STACKGUARDIAN_API_URI: '${{ secrets.SG_STG_API_URI }}'
STACKGUARDIAN_API_KEY: '${{ secrets.SG_STG_API_KEY }}'
STACKGUARDIAN_ORG_NAME: '${{ secrets.SG_STG_ORG_NAME }}'


### --- testenv: PRD ----------------------------------------------------

- name: "Test API-PRD with Provider acceptance tests"
if: inputs.testenv=='PRD'
run: make test-acc
env:
STACKGUARDIAN_API_URI: '${{ secrets.SG_PRD_API_URI }}'
STACKGUARDIAN_API_KEY: '${{ secrets.SG_PRD_API_KEY }}'
STACKGUARDIAN_ORG_NAME: '${{ secrets.SG_PRD_ORG_NAME }}'

- name: "Test API-PRD with Provider quickstart example"
if: inputs.testenv=='PRD'
run: |
set -eu -x;
make install;
make test-examples-quickstart ARGS="-f local-build";
shell: bash
env:
STACKGUARDIAN_API_URI: '${{ secrets.SG_PRD_API_URI }}'
STACKGUARDIAN_API_KEY: '${{ secrets.SG_PRD_API_KEY }}'
STACKGUARDIAN_ORG_NAME: '${{ secrets.SG_PRD_ORG_NAME }}'

- name: "Test API-PRD with Provider onboarding example"
if: inputs.testenv=='PRD'
run: |
set -eu -x;
make install;
make test-examples-onboarding ARGS="-f local-build";
shell: bash
env:
STACKGUARDIAN_API_URI: '${{ secrets.SG_PRD_API_URI }}'
STACKGUARDIAN_API_KEY: '${{ secrets.SG_PRD_API_KEY }}'
STACKGUARDIAN_ORG_NAME: '${{ secrets.SG_PRD_ORG_NAME }}'
31 changes: 21 additions & 10 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
name: "Test TF-Provider on SG-Prod"
name: "Test TF-Provider on API-PROD"

on:
push:
branches:
- main
- devel
# https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#pull_request
pull_request:
branches:
- 'main'
Expand All @@ -28,32 +26,45 @@ jobs:
- name: "Install Go"
uses: actions/setup-go@v5
with:
go-version: '1.21'
go-version-file: 'go.mod'

- name: "Install Terraform"
uses: hashicorp/setup-terraform@v3
with:
terraform_wrapper: false
terraform_version: '1.5.7' # TODO: matrix of terraform & tofu versions
terraform_version: '1.5.7'

- name: "Build Provider"
run: make build

- name: "Test Provider with acceptance tests"
run: make test-acc
env:
STACKGUARDIAN_API_KEY: ${{ secrets.STACKGUARDIAN_API_KEY }}
STACKGUARDIAN_ORG_NAME: ${{ secrets.STACKGUARDIAN_ORG_NAME }}
STACKGUARDIAN_API_URI: '${{ secrets.SG_PRD_API_URI }}'
STACKGUARDIAN_API_KEY: '${{ secrets.SG_PRD_API_KEY }}'
STACKGUARDIAN_ORG_NAME: '${{ secrets.SG_PRD_ORG_NAME }}'

- name: "Test Provider with quickstart example"
run: |
set -eu -x;
make install;
make test-example ARGS="-f local-build";
make test-examples-quickstart ARGS="-f local-build";
shell: bash
env:
STACKGUARDIAN_API_KEY: ${{ secrets.STACKGUARDIAN_API_KEY }}
STACKGUARDIAN_ORG_NAME: ${{ secrets.STACKGUARDIAN_ORG_NAME }}
STACKGUARDIAN_API_KEY: '${{ secrets.SG_PRD_API_KEY }}'
STACKGUARDIAN_API_URI: '${{ secrets.SG_PRD_API_URI }}'
STACKGUARDIAN_ORG_NAME: '${{ secrets.SG_PRD_ORG_NAME }}'

- name: "Test Provider with onboarding example"
run: |
set -eu -x;
make install;
make test-examples-onboarding ARGS="-f local-build";
shell: bash
env:
STACKGUARDIAN_API_KEY: '${{ secrets.SG_PRD_API_KEY }}'
STACKGUARDIAN_API_URI: '${{ secrets.SG_PRD_API_URI }}'
STACKGUARDIAN_ORG_NAME: '${{ secrets.SG_PRD_ORG_NAME }}'

- name: "Check Provider docs"
run: |
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ override.tf.json
# Ignore CLI configuration files
.terraformrc
terraform.rc
examples/**.png
examples/**.dot

# Terraform provider build files
terraform-provider-stackguardian
Expand Down
12 changes: 12 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,18 @@
"mode": "local",
"processId": 0,
//"preLaunchTask": "Exec sg-tf-provider",
},
{
"name": "Debug Terraform Provider",
"type": "go",
"request": "launch",
"mode": "debug",
// this assumes your workspace is the root of the repo
"program": "${workspaceFolder}",
"env": {},
"args": [
"-debug",
]
}
]
}
61 changes: 50 additions & 11 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@ OS_ARCH=linux_amd64

default: install

clean: clean-examples

clean-examples:
find examples/ -type d -name '.terraform' -exec rm -rv {} \+
find examples/ -type f -name '.terraform.lock.hcl' -exec rm -v {} \+
find examples/ -type f -regextype posix-extended -regex '.+.tfstate(.[[:digit:]]+)?(.backup)?' -exec rm -v {} \+

build:
go build -o ${BINARY}

Expand All @@ -23,29 +30,61 @@ test:
echo $(TEST) | xargs -t -n4 go test $(TESTARGS) -timeout=30s -parallel=4

test-acc:
TF_ACC=1 STACKGUARDIAN_ORG_NAME=wicked-hop go test -parallel=1 $(TEST) -v $(TESTARGS) -timeout=15m
TF_ACC=1 go test -parallel=1 $(TEST) -v $(TESTARGS) -timeout=15m

test-example:
bash docs/guides/quickstart/test-quickstart.sh $(ARGS)
test-examples-quickstart:
bash docs-guides-assets/quickstart/test-quickstart.sh $(ARGS)

# bash docs-guides-assets/onboarding/project-test/test-onboarding.sh $(ARGS)
test-examples-onboarding:
echo "Implemented in next PR - Dummy Test"

docs-generate:
mv docs/guides docs_guides
tfplugindocs generate
mv docs_guides docs/guides
tfplugindocs generate \
--website-source-dir docs-templates

docs-validate:
mv docs/guides docs_guides
tfplugindocs validate
mv docs_guides docs/guides

tools-install:
cd tools; go install github.com/hashicorp/terraform-plugin-docs/cmd/tfplugindocs

gh-workflow:
gh-workflow-test-provider:
act \
--workflows ${PWD}/.github/workflows/test.yaml \
--job provider-project_test \
--secret STACKGUARDIAN_ORG_NAME=${STACKGUARDIAN_ORG_NAME} \
--secret STACKGUARDIAN_API_KEY=${STACKGUARDIAN_API_KEY} \
--secret SG_PRD_API_URI=${SG_PRD_API_URI} \
--secret SG_PRD_API_KEY=${SG_PRD_API_KEY} \
--secret SG_PRD_ORG_NAME=${SG_PRD_ORG_NAME} \
push \
;

gh-workflow-test-provider-mock-stg-as-prd:
act \
--workflows ${PWD}/.github/workflows/test.yaml \
--job provider-project_test \
--secret SG_PRD_API_URI=${SG_STG_API_URI} \
--secret SG_PRD_API_KEY=${SG_STG_API_KEY} \
--secret SG_PRD_ORG_NAME=${SG_STG_ORG_NAME} \
push \
;

# --local-repository StackGuardian/terraform-provider-stackguardian@devel=${PWD} \#
gh-workflow-test-api-stg:
act \
--workflows ${PWD}/.github/workflows/test-api-stg.yaml \
--secret SG_STG_API_URI=${SG_STG_API_URI} \
--secret SG_STG_API_KEY=${SG_STG_API_KEY} \
--secret SG_STG_ORG_NAME=${SG_STG_ORG_NAME} \
workflow_dispatch \
;

# --local-repository StackGuardian/terraform-provider-stackguardian@devel=${PWD} \#
gh-workflow-test-api-prd:
act \
--workflows ${PWD}/.github/workflows/test-api-prd.yaml \
--secret SG_PRD_API_URI=${SG_PRD_API_URI} \
--secret SG_PRD_API_KEY=${SG_PRD_API_KEY} \
--secret SG_PRD_ORG_NAME=${SG_PRD_ORG_NAME} \
workflow_dispatch \
;
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
data "stackguardian_workflow_outputs" "TPS-Example-WorkflowOutputs" {
wfgrp = "aws-dev-environments"
wf = "wf-musical-coral"
// stack = "test-stack-1" // optionally
}

output "website_url_from_mapstr" {
value = data.stackguardian_workflow_outputs.TPS-Example-WorkflowOutputs.outputs_str.sample_website_url
}

output "website_url_from_json" {
value = jsondecode(data.stackguardian_workflow_outputs.TPS-Example-WorkflowOutputs.outputs_json).sample_website_url.value
}

output "outputs_full_json" {
value = jsondecode(data.stackguardian_workflow_outputs.TPS-Example-WorkflowOutputs.outputs_json)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
resource "stackguardian_connector_cloud" "TPS-Example-ConnectorCloud" {
// integrationgroup = "TPS-Example"
data = jsonencode({
"ResourceName" : "TPS-Example-ConnectorCloud",
"Tags" : ["tf-provider-example"]
"Description" : "Example of terraform-provider-stackguardian for ConnectorCloud",
"Settings" : {
"kind" : "AWS_STATIC",
"config" : [
{
"awsAccessKeyId" : "example-aws-key",
"awsSecretAccessKey" : "example-aws-key",
"awsDefaultRegion" : "us-west-2"
}
]
}
})
}
Loading