@@ -31,6 +31,48 @@ describe("full integration test", () => {
31
31
let workspaceName : string ;
32
32
const orgName = "cdktf" ;
33
33
34
+ async function createWorkspace ( token : string , name : string ) {
35
+ const response = await fetch (
36
+ `https://app.terraform.io/api/v2/organizations/${ orgName } /workspaces` ,
37
+ {
38
+ method : "POST" ,
39
+ headers : {
40
+ "Content-Type" : "application/vnd.api+json" ,
41
+ Authorization : `Bearer ${ token } ` ,
42
+ } ,
43
+ body : JSON . stringify ( {
44
+ data : {
45
+ attributes : {
46
+ name,
47
+ executionMode : "remote" ,
48
+ terraformVersion : TERRAFORM_VERSION ,
49
+ } ,
50
+ } ,
51
+ type : "workspaces" ,
52
+ } ) ,
53
+ } ,
54
+ ) ;
55
+ const res = await response . json ( ) ;
56
+
57
+ return res . data . id ;
58
+ }
59
+
60
+ async function deleteWorkspace ( token : string , name : string ) {
61
+ const response = await fetch (
62
+ `https://app.terraform.io/api/v2/organizations/${ orgName } /workspaces/${ name } ` ,
63
+ {
64
+ method : "DELETE" ,
65
+ headers : {
66
+ "Content-Type" : "application/vnd.api+json" ,
67
+ Authorization : `Bearer ${ token } ` ,
68
+ } ,
69
+ } ,
70
+ ) ;
71
+ const res = await response . json ( ) ;
72
+
73
+ return res . data . id ;
74
+ }
75
+
34
76
beforeEach ( async ( ) => {
35
77
workspaceName = `${ GITHUB_RUN_NUMBER } -${ crypto
36
78
. randomBytes ( 10 )
@@ -45,36 +87,15 @@ describe("full integration test", () => {
45
87
} ) ;
46
88
47
89
withAuth ( "deploy in Terraform Cloud" , async ( ) => {
48
- const client = new TerraformCloud ( TERRAFORM_CLOUD_TOKEN ) ;
49
-
50
- await client . Workspaces . create ( orgName , {
51
- data : {
52
- attributes : {
53
- name : workspaceName ,
54
- executionMode : "remote" ,
55
- terraformVersion : TERRAFORM_VERSION ,
56
- } ,
57
- type : "workspaces" ,
58
- } ,
59
- } ) ;
90
+ await createWorkspace ( TERRAFORM_CLOUD_TOKEN , workspaceName ) ;
60
91
61
92
expect ( await driver . deploy ( [ "source-stack" ] ) ) . toContain ( "Apply complete!" ) ;
62
- await client . Workspaces . deleteByName ( orgName , workspaceName ) ;
93
+
94
+ await deleteWorkspace ( TERRAFORM_CLOUD_TOKEN , workspaceName ) ;
63
95
} ) ;
64
96
65
97
withAuth ( "deploy locally and then in Terraform Cloud" , async ( ) => {
66
- const client = new TerraformCloud ( TERRAFORM_CLOUD_TOKEN ) ;
67
-
68
- await client . Workspaces . create ( orgName , {
69
- data : {
70
- attributes : {
71
- name : workspaceName ,
72
- executionMode : "remote" ,
73
- terraformVersion : TERRAFORM_VERSION ,
74
- } ,
75
- type : "workspaces" ,
76
- } ,
77
- } ) ;
98
+ await createWorkspace ( TERRAFORM_CLOUD_TOKEN , workspaceName ) ;
78
99
79
100
process . env . TF_EXECUTE_LOCAL = "true" ;
80
101
await driver . deploy ( [ "source-stack" ] , "before-migration.json" ) ;
@@ -87,31 +108,20 @@ describe("full integration test", () => {
87
108
readFileSync ( "after-migration.json" ) ,
88
109
) ;
89
110
90
- await client . Workspaces . deleteByName ( orgName , workspaceName ) ;
111
+ await deleteWorkspace ( TERRAFORM_CLOUD_TOKEN , workspaceName ) ;
91
112
} ) ;
92
113
93
114
// Only the origin stack is in TFC, the consumer stack is local
94
115
withAuth (
95
116
"deploy with cross stack reference origin in Terraform Cloud" ,
96
117
async ( ) => {
97
- const client = new TerraformCloud ( TERRAFORM_CLOUD_TOKEN ) ;
98
-
99
- await client . Workspaces . create ( orgName , {
100
- data : {
101
- attributes : {
102
- name : workspaceName ,
103
- executionMode : "remote" ,
104
- terraformVersion : TERRAFORM_VERSION ,
105
- } ,
106
- type : "workspaces" ,
107
- } ,
108
- } ) ;
118
+ await createWorkspace ( TERRAFORM_CLOUD_TOKEN , workspaceName ) ;
109
119
110
120
await driver . deploy ( [ "source-stack" , "consumer-stack" ] ) ;
111
121
driver . output ( "source-stack" , "outputs.tmp.json" , true ) ;
112
122
const outputs = JSON . parse ( readFileSync ( "outputs.tmp.json" ) . toString ( ) ) ;
113
123
114
- await client . Workspaces . deleteByName ( orgName , workspaceName ) ;
124
+ await deleteWorkspace ( TERRAFORM_CLOUD_TOKEN , workspaceName ) ;
115
125
116
126
expect ( driver . readLocalFile ( "consumer-file.txt" ) ) . toEqual (
117
127
outputs [ "source-stack" ] . password_output ,
0 commit comments