Skip to content

Commit

Permalink
Add acceptance test for TF_VAR environment variable usage (#58)
Browse files Browse the repository at this point in the history
Reference: hashicorp/terraform-plugin-sdk#935

With github.com/hashicorp/terraform-plugin-sdk/[email protected]:

```console
$ TF_ACC=1 go test -count=1 -run='TestAccFrameworkResourceUser_TF_VAR_Environment_Variable' -v ./internal/frameworkprovider/
=== RUN   TestAccFrameworkResourceUser_TF_VAR_Environment_Variable
    resource_user_test.go:117: Step 1/1 error: Error running pre-apply refresh: variable "framework_user_name" was required but not supplied
--- FAIL: TestAccFrameworkResourceUser_TF_VAR_Environment_Variable (0.56s)
FAIL
FAIL    github.com/hashicorp/terraform-provider-corner/internal/frameworkprovider       1.324s
FAIL
```
  • Loading branch information
bflad authored Apr 15, 2022
1 parent 9adaccf commit 50c4eea
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions internal/frameworkprovider/resource_user_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,40 @@ func TestAccFrameworkResourceUser_interpolateLanguage(t *testing.T) {
})
}

// Reference: https://github.com/hashicorp/terraform-plugin-sdk/issues/935
func TestAccFrameworkResourceUser_TF_VAR_Environment_Variable(t *testing.T) {
expectedUserName := "Ford Prefect"
t.Setenv("TF_VAR_framework_user_name", expectedUserName)

resource.UnitTest(t, resource.TestCase{
ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){
"framework": func() (tfprotov6.ProviderServer, error) {
return tfsdk.NewProtocol6Server(New()), nil
},
},
Steps: []resource.TestStep{
{
Config: `
# Sourced via TF_VAR_framework_user_name environment variable
variable "framework_user_name" {
type = string
}
resource "framework_user" "test" {
email = "[email protected]"
name = var.framework_user_name
age = 200
id = "h"
}
`,
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttr("framework_user.test", "name", expectedUserName),
),
},
},
})
}

const configResourceUserBasic = `
resource "framework_user" "foo" {
email = "[email protected]"
Expand Down

0 comments on commit 50c4eea

Please sign in to comment.