Skip to content

Commit c9d1ee9

Browse files
committed
add cmd for terraform plan/show
1 parent eda0c5c commit c9d1ee9

File tree

9 files changed

+89
-1
lines changed

9 files changed

+89
-1
lines changed

cli/root.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ func (r *RootCmd) Root() *serpent.Command {
9696
return nil
9797
},
9898
}
99+
cmd.AddSubcommands(r.TerraformPlan())
99100
return cmd
100101
}
101102

preview.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ func Preview(ctx context.Context, input Input, dir fs.FS) (*Output, hcl.Diagnost
6969
},
7070
}
7171
}
72+
7273
var _ = outputs
7374

7475
diags := make(hcl.Diagnostics, 0)

preview_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,16 @@ func Test_Extract(t *testing.T) {
184184
expUnknowns: []string{},
185185
params: map[string]func(t *testing.T, parameter types.Parameter){},
186186
},
187+
{
188+
name: "dupemodparams",
189+
dir: "dupemodparams",
190+
expTags: map[string]string{},
191+
input: preview.Input{
192+
ParameterValues: map[string]types.ParameterValue{},
193+
},
194+
expUnknowns: []string{},
195+
params: map[string]func(t *testing.T, parameter types.Parameter){},
196+
},
187197
{
188198
name: "test",
189199
dir: "test",

previewe2e_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ import (
2020
// Test_VerifyE2E will fully evaluate with `terraform apply`
2121
// and verify the output of `preview` against the tfstate. This
2222
// is the e2e test for the preview package.
23+
// It uses the `terraform plan` output, meaning this mimics the
24+
// "Workspace Create" form of preview. Which is arguably the most
25+
// important part of the preview lifecycle.
2326
//
2427
// 1. Terraform versions listed from 'verify.TerraformTestVersions' are
2528
// installed into a temp directory. If multiple versions exist, a e2e test
@@ -44,6 +47,7 @@ import (
4447
// The goal of the test is to compare `tfstate` with the output of `preview`.
4548
// If `preview`'s implementation of terraform is incorrect, the test will fail.
4649
// TODO: Adding varied parameter inputs would be a good idea.
50+
// TODO: Add workspace tag comparisions.
4751
func Test_VerifyE2E(t *testing.T) {
4852
t.Parallel()
4953

testdata/.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
*/.terraform*
22
*/terraform.tfstate
33
*/terraform.tfstate.backup
4-
*/out.plan
4+
*/out.plan
5+
*/out.json
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
terraform {
2+
required_providers {
3+
coder = {
4+
source = "coder/coder"
5+
}
6+
}
7+
}
8+
9+
module "dupe" {
10+
source = "./nesteddupe"
11+
}
12+
13+
data "coder_parameter" "dupe" {
14+
name = "Dupe Question"
15+
description = "A question that will be duplicated"
16+
type = "string"
17+
default = "dupe"
18+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
terraform {
2+
required_providers {
3+
coder = {
4+
source = "coder/coder"
5+
}
6+
}
7+
}
8+
9+
data "coder_parameter" "dupe" {
10+
name = "Dupe Question"
11+
description = "A question that will be duplicated"
12+
type = "string"
13+
default = "dupe"
14+
}

testdata/dupemodparams/main.tf

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
terraform {
2+
required_providers {
3+
coder = {
4+
source = "coder/coder"
5+
}
6+
}
7+
}
8+
9+
module "dupe" {
10+
source = "./dupe"
11+
}
12+
13+
data "coder_parameter" "dupe" {
14+
name = "Dupe Question"
15+
description = "A question that will be duplicated"
16+
type = "string"
17+
default = "dupe"
18+
}

testdata/dupeparams/main.tf

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
terraform {
2+
required_providers {
3+
coder = {
4+
source = "coder/coder"
5+
}
6+
}
7+
}
8+
9+
data "coder_parameter" "dupe" {
10+
name = "Dupe Question"
11+
description = "A question that will be duplicated"
12+
type = "string"
13+
default = "dupe"
14+
}
15+
16+
data "coder_parameter" "dupe" {
17+
name = "Dupe Question"
18+
description = "A question that will be duplicated"
19+
type = "string"
20+
default = "dupe"
21+
}

0 commit comments

Comments
 (0)