Skip to content

Commit

Permalink
chore: migrate tests to user keys
Browse files Browse the repository at this point in the history
  • Loading branch information
Ignacio Anaya committed Feb 7, 2022
1 parent e8e2719 commit b35d8a7
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 3 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ jobs:
- name: Test
run: go test -v ./...
env:
TF_VAR_checkly_api_key: ${{ secrets.CHECKLY_API_KEY }}
CHECKLY_API_KEY: ${{ secrets.CHECKLY_API_KEY }}
TF_VAR_checkly_api_key: ${{ secrets.CHECKLY_API_KEY }}
TF_VAR_checkly_account_id: ${{ secrets.CHECKLY_ACCOUNT_ID }}
CHECKLY_ACCOUNT_ID: ${{ secrets.CHECKLY_ACCOUNT_ID }}
CHECKLY_API_URL: ${{ secrets.CHECKLY_API_URL }}
TF_ACC: 1
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ Clone the repo, build the project and add it to your Terraform plugins directory
git clone git@github.com:checkly/terraform-provider-checkly.git
cd terraform-provider-checkly
go test
go build && CHECKLY_API_KEY=XXX go test -tags=integration
go build && CHECKLY_API_KEY=xxx CHECKLY_ACCOUNT_ID=xxx go test -tags=integration
```

<br>
Expand Down
12 changes: 11 additions & 1 deletion checkly/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,15 @@ func getAPIKey(t *testing.T) string {
if key == "" {
t.Fatal("'CHECKLY_API_KEY' must be set for integration tests")
}

return key
}

func getAccountId(t *testing.T) string {
key := os.Getenv("CHECKLY_ACCOUNT_ID")
if key == "" {
t.Fatal("'CHECKLY_ACCOUNT_ID' must be set for integration tests")
}
return key
}

Expand All @@ -22,7 +31,8 @@ func TestChecklyTerraformIntegration(t *testing.T) {
terraformOptions := &terraform.Options{
TerraformDir: "../",
Vars: map[string]interface{}{
"checkly_api_key": getAPIKey(t),
"checkly_api_key": getAPIKey(t),
"checkly_account_id": getAccountId(t),
},
}
defer terraform.Destroy(t, terraformOptions)
Expand Down
4 changes: 4 additions & 0 deletions checkly/test_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ func testAccPreCheck(t *testing.T) {
if os.Getenv("CHECKLY_API_KEY") == "" {
t.Fatal("CHECKLY_API_KEY must be set for acceptance tests")
}

if os.Getenv("CHECKLY_ACCOUNT_ID") == "" {
t.Fatal("CHECKLY_ACCOUNT_ID must be set for acceptance tests")
}
}

func accTestCase(t *testing.T, steps []resource.TestStep) {
Expand Down
5 changes: 5 additions & 0 deletions docs/guides/support-for-terraform-0.12.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ Now expose the API key as an environment variable in your shell:

```bash
export TF_VAR_checkly_api_key=<my_api_key>
export TF_VAR_checkly_account_id=<my_account_id>
```

### Usage
Expand All @@ -37,8 +38,12 @@ create a tf config file, for example, `example.tf`
variable "checkly_api_key" {
}
variable "checkly_account_id" {
}
provider "checkly" {
api_key = var.checkly_api_key
account_id = var.checkly_account_id
}
resource "checkly_group" "group1" {
Expand Down
4 changes: 4 additions & 0 deletions versions.tf
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ terraform {
variable "checkly_api_key" {
}

variable "checkly_account_id" {
}

provider "checkly" {
api_key = var.checkly_api_key
account_id = var.checkly_account_id
}

0 comments on commit b35d8a7

Please sign in to comment.