Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
aaabdelgany committed Mar 12, 2024
1 parent eec5424 commit 7fe6499
Showing 1 changed file with 41 additions and 8 deletions.
49 changes: 41 additions & 8 deletions internal/provider/resource_tfe_test_variable_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (

tfe "github.com/hashicorp/go-tfe"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
)

func TestAccTFEVariable_testingvariables(t *testing.T) {
Expand All @@ -25,27 +26,59 @@ func TestAccTFEVariable_testingvariables(t *testing.T) {
{
Config: testAccTFETestVariable_test_variable(rInt),
Check: resource.ComposeTestCheckFunc(
testAccCheckTFEVariableExists(
"tfe_variable.foobar", variable),
testAccCheckTFETestVariableExists(
"tfe_test_variable.foobar", variable),
testAccCheckTFEVariableAttributes(variable),
resource.TestCheckResourceAttr(
"tfe_variable.foobar", "key", "key_test"),
"tfe_test_variable.foobar", "key", "key_test"),
resource.TestCheckResourceAttr(
"tfe_variable.foobar", "value", "value_test"),
"tfe_test_variable.foobar", "value", "value_test"),
resource.TestCheckResourceAttr(
"tfe_variable.foobar", "description", "some description"),
"tfe_test_variable.foobar", "description", "some description"),
resource.TestCheckResourceAttr(
"tfe_variable.foobar", "category", "env"),
"tfe_test_variable.foobar", "category", "env"),
resource.TestCheckResourceAttr(
"tfe_variable.foobar", "hcl", "false"),
"tfe_test_variable.foobar", "hcl", "false"),
resource.TestCheckResourceAttr(
"tfe_variable.foobar", "sensitive", "false"),
"tfe_test_variable.foobar", "sensitive", "false"),
),
},
},
})
}

func testAccCheckTFETestVariableExists(
n string, variable *tfe.Variable) resource.TestCheckFunc {
return func(s *terraform.State) error {
config := testAccProvider.Meta().(ConfiguredClient)

rs, ok := s.RootModule().Resources[n]
if !ok {
return fmt.Errorf("Not found: %s", n)
}

if rs.Primary.ID == "" {
return fmt.Errorf("No instance ID is set")
}
moduleID := tfe.RegistryModuleID{
Organization: rs.Primary.Attributes["organization"],
Name: rs.Primary.Attributes["module_name"],
Provider: rs.Primary.Attributes["module_provider"],
Namespace: rs.Primary.Attributes["module_namespace"],
RegistryName: "private",
}

v, err := config.Client.TestVariables.Read(ctx, moduleID, rs.Primary.ID)
if err != nil {
return err
}

*variable = *v

return nil
}
}

func testAccTFETestVariable_test_variable(rInt int) string {
return fmt.Sprintf(`
resource "tfe_organization" "foobar" {
Expand Down

0 comments on commit 7fe6499

Please sign in to comment.