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

DRAFT: Adds setup scripts for running and debugging locally. #2202

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,6 @@ terraform-provider-github
# Test exclusions
!command/test-fixtures/**/*.tfstate
!command/test-fixtures/**/.terraform/

examples/testing/**
# do not commit secrets
.env
95 changes: 95 additions & 0 deletions scripts/setup_env.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
#!/bin/bash

# Check for '-include-optional-env' parameter
INCLUDE_OPTIONAL=false
if [ "$1" == "-include-optional-env" ]; then
INCLUDE_OPTIONAL=true
fi

# Check if launch.json already exists
if [ -f ".vscode/launch.json" ]; then
read -p "launch.json already exists. Overwrite? (y/n): " overwrite
if [[ $overwrite != "y" ]]; then
echo "Exiting without creating launch.json."
exit 1
fi
fi

# Prompt for required environment variables

read -p "Enter GITHUB_TOKEN: " GITHUB_TOKEN
read -p "Enter GITHUB_OWNER: " GITHUB_OWNER
read -p "Enter GITHUB_ORGANIZATION (ex. octokit): " GITHUB_ORGANIZATION
read -p "Enter TF_TEST_FILE (ex. resource_github_team_members_test.go): " TF_TEST_FILE
read -p "Enter TF_TEST_FUNCTION (ex. TestAccGitHubRepositoryTopics): " TF_TEST_FUNCTION

export GITHUB_TOKEN="$GITHUB_TOKEN"
export GITHUB_OWNER="$GITHUB_OWNER"
export GITHUB_ORGANIZATION="$GITHUB_ORGANIZATION"
export TF_TEST_FILE="$TF_TEST_FILE"
export TF_TEST_FUNCTION="$TF_TEST_FUNCTION"

# Prompt for optional environment variables
if [ "$INCLUDE_OPTIONAL" = true ]; then
read -p "Enter GITHUB_TEST_USER: " GITHUB_TEST_USER
read -p "Enter GITHUB_TEST_COLLABORATOR: " GITHUB_TEST_COLLABORATOR
read -p "Enter GITHUB_TEST_COLLABORATOR_TOKEN: " GITHUB_TEST_COLLABORATOR_TOKEN
read -p "Enter GITHUB_TEMPLATE_REPOSITORY: " GITHUB_TEMPLATE_REPOSITORY
read -p "Enter GITHUB_TEMPLATE_REPOSITORY_RELEASE_ID: " GITHUB_TEMPLATE_REPOSITORY_RELEASE_ID
read -p "Enter TF_ACC: " TF_ACC
read -p "Enter APP_INSTALLATION_ID: " APP_INSTALLATION_ID

# Export environment variables
export GITHUB_TEST_USER="$GITHUB_TEST_USER"
export GITHUB_TEST_COLLABORATOR="$GITHUB_TEST_COLLABORATOR"
export GITHUB_TEST_COLLABORATOR_TOKEN="$GITHUB_TEST_COLLABORATOR_TOKEN"
export GITHUB_TEMPLATE_REPOSITORY="$GITHUB_TEMPLATE_REPOSITORY"
export GITHUB_TEMPLATE_REPOSITORY_RELEASE_ID="$GITHUB_TEMPLATE_REPOSITORY_RELEASE_ID"
export GITHUB_ORGANIZATION="$GITHUB_ORGANIZATION"
export TF_ACC="$TF_ACC"
export TF_LOG="DEBUG"
export APP_INSTALLATION_ID="$APP_INSTALLATION_ID"
fi

# Create the launch.json file
cat << EOF > .vscode/launch.json
{
"version": "0.2.0",
"configurations": [
{
"name": "Launch test function",
"type": "go",
"request": "launch",
"mode": "test",
"program": "\${workspaceFolder}/github/\${env:TF_TEST_FILE}",
"args": [
"-test.v",
"-test.run",
"^\${env:TF_TEST_FUNCTION}$"
],
"env": {
"GITHUB_TEST_COLLABORATOR": "\${env:GITHUB_TEST_COLLABORATOR}",
"GITHUB_TEST_COLLABORATOR_TOKEN": "\${env:GITHUB_TEST_COLLABORATOR_TOKEN}",
"GITHUB_TEST_USER": "\${env:GITHUB_TEST_USER}",
"GITHUB_TOKEN": "\${env:GITHUB_TOKEN}",
"GITHUB_TEMPLATE_REPOSITORY": "\${env:GITHUB_TEMPLATE_REPOSITORY}",
"GITHUB_TEMPLATE_REPOSITORY_RELEASE_ID": "\${env:GITHUB_TEMPLATE_REPOSITORY_RELEASE_ID}",
"GITHUB_ORGANIZATION": "\${env:GITHUB_ORGANIZATION}",
"TF_CLI_CONFIG_FILE": "\${workspaceFolder}/examples/dev.tfrc",
"TF_ACC": "\${env:TF_ACC}",
"TF_LOG": "\${env:TF_LOG}",
"APP_INSTALLATION_ID": "\${env:APP_INSTALLATION_ID}"
}
},
{
"name": "Attach to Process",
"type": "go",
"request": "attach",
"mode": "local",
"processId": "\${command:AskForProcessId}"
}
]
}
EOF

echo "launch.json has been created."
37 changes: 37 additions & 0 deletions scripts/setup_testing.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/bin/bash

# Ask for the resource name
read -p "Enter the resource name to use in the test(i.e. issue_label for resource_github_issue_label): " resourceName

# Define the directory and file path
DIR="examples/testing/${resourceName}"
FILE="${DIR}/main.tf"

# Create the directory, if it doesn't already exist
mkdir -p "$DIR"

# Create (or overwrite) the file and add the contents with the provided resource name
cat <<EOF >"$FILE"
// Empty configuration
provider "github" {
//owner = "octokit"
//token = "ABC123"
}

// Terraform global config for providers
terraform {
required_providers {
github = {
source = "integrations/github"
}
}

// Example resource placeholder using provided resource name
// Documentation: https://registry.terraform.io/providers/integrations/github/latest/docs/resources/${resourceName}
resource "${resourceName}" "test" {

}
}
EOF

echo "File ${FILE} has been created with the specified contents."