Skip to content

Commit

Permalink
Add acceptance test for TF_VAR environment variable usage
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
```

Passes with hashicorp/terraform-plugin-sdk#937.
  • Loading branch information
bflad committed Apr 15, 2022
1 parent 9adaccf commit 0592d86
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 0592d86

Please sign in to comment.