-
Notifications
You must be signed in to change notification settings - Fork 147
/
data_source_variable_set_test.go
112 lines (98 loc) · 3.07 KB
/
data_source_variable_set_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
package tfe
import (
"fmt"
"math/rand"
"testing"
"time"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
)
func TestAccTFEVariableSetsDataSource_basic(t *testing.T) {
rInt := rand.New(rand.NewSource(time.Now().UnixNano())).Int()
orgName := fmt.Sprintf("org-%d", rInt)
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: testAccTFEVariableSetsDataSourceConfig_basic(rInt),
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttrSet("data.tfe_variable_set.foobar", "id"),
resource.TestCheckResourceAttr(
"data.tfe_variable_set.foobar", "name", fmt.Sprintf("varset-foo-%d", rInt)),
resource.TestCheckResourceAttr(
"data.tfe_variable_set.foobar", "description", "a description"),
resource.TestCheckResourceAttr(
"data.tfe_variable_set.foobar", "global", "false"),
resource.TestCheckResourceAttr(
"data.tfe_variable_set.foobar", "organization", orgName),
),
},
},
},
)
}
func TestAccTFEVariableSetsDataSource_full(t *testing.T) {
rInt := rand.New(rand.NewSource(time.Now().UnixNano())).Int()
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: testAccTFEVariableSetsDataSourceConfig_full(rInt),
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttrSet("data.tfe_variable_set.foobar", "id"),
resource.TestCheckResourceAttr(
"data.tfe_variable_set.foobar", "name", fmt.Sprintf("varset-foo-%d", rInt)),
resource.TestCheckResourceAttr(
"data.tfe_variable_set.foobar", "workspace_ids.#", "1"),
resource.TestCheckResourceAttr(
"data.tfe_variable_set.foobar", "variable_ids.#", "1"),
),
},
},
},
)
}
func testAccTFEVariableSetsDataSourceConfig_basic(rInt int) string {
return fmt.Sprintf(`
resource "tfe_organization" "foobar" {
name = "org-%d"
email = "admin@company.com"
}
resource "tfe_variable_set" "foobar" {
name = "varset-foo-%d"
description = "a description"
organization = tfe_organization.foobar.id
}
data "tfe_variable_set" "foobar" {
name = tfe_variable_set.foobar.name
organization = tfe_variable_set.foobar.organization
}`, rInt, rInt)
}
func testAccTFEVariableSetsDataSourceConfig_full(rInt int) string {
return fmt.Sprintf(`
resource "tfe_organization" "foobar" {
name = "org-%d"
email = "admin@company.com"
}
resource "tfe_workspace" "foobar" {
name = "workspace-foo-%d"
organization = tfe_organization.foobar.id
}
resource "tfe_variable_set" "foobar" {
name = "varset-foo-%d"
description = "a description"
organization = tfe_organization.foobar.id
workspace_ids = [tfe_workspace.foobar.id]
}
resource "tfe_variable" "envfoo" {
key = "vfoo"
value = "bar"
category = "env"
variable_set_id = tfe_variable_set.foobar.id
}
data "tfe_variable_set" "foobar" {
name = tfe_variable_set.foobar.name
organization = tfe_variable_set.foobar.organization
}`, rInt, rInt, rInt)
}