-
Notifications
You must be signed in to change notification settings - Fork 148
/
data_source_workspace_run_task_test.go
67 lines (57 loc) · 2.1 KB
/
data_source_workspace_run_task_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
package tfe
import (
"fmt"
"math/rand"
"testing"
"time"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
)
func TestAccTFEWorkspaceRunTaskDataSource_basic(t *testing.T) {
skipUnlessRunTasksDefined(t)
skipIfFreeOnly(t) // Run Tasks requires TFE or a TFC paid/trial subscription
rInt := rand.New(rand.NewSource(time.Now().UnixNano())).Int()
orgName := fmt.Sprintf("tst-terraform-%d", rInt)
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
Steps: []resource.TestStep{
testCheckCreateOrgWithRunTasks(orgName),
{
Config: testAccTFEWorkspaceRunTaskDataSourceConfig(orgName, rInt, runTasksURL()),
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttr("data.tfe_workspace_run_task.foobar", "enforcement_level", "advisory"),
resource.TestCheckResourceAttrSet("data.tfe_workspace_run_task.foobar", "stage"),
resource.TestCheckResourceAttrSet("data.tfe_workspace_run_task.foobar", "id"),
resource.TestCheckResourceAttrSet("data.tfe_workspace_run_task.foobar", "task_id"),
resource.TestCheckResourceAttrSet("data.tfe_workspace_run_task.foobar", "workspace_id"),
),
},
},
})
}
func testAccTFEWorkspaceRunTaskDataSourceConfig(orgName string, rInt int, runTaskURL string) string {
return fmt.Sprintf(`
resource "tfe_organization" "foobar" {
name = "%s"
email = "admin@company.com"
}
resource "tfe_organization_run_task" "foobar" {
organization = tfe_organization.foobar.id
url = "%s"
name = "foobar-task-%d"
}
resource "tfe_workspace" "foobar" {
name = "workspace-test-%d"
organization = tfe_organization.foobar.id
}
resource "tfe_workspace_run_task" "foobar" {
workspace_id = resource.tfe_workspace.foobar.id
task_id = resource.tfe_organization_run_task.foobar.id
enforcement_level = "advisory"
}
data "tfe_workspace_run_task" "foobar" {
workspace_id = resource.tfe_workspace.foobar.id
task_id = resource.tfe_organization_run_task.foobar.id
depends_on = [tfe_workspace_run_task.foobar]
}`, orgName, runTaskURL, rInt, rInt)
}