Skip to content
This repository was archived by the owner on Nov 20, 2024. It is now read-only.

Commit 6e2ac89

Browse files
committed
Support sensitive output
1 parent 0d17251 commit 6e2ac89

File tree

5 files changed

+24
-8
lines changed

5 files changed

+24
-8
lines changed

api/v1alpha1/workspace_types.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ type OutputSpec struct {
4040
// Attribute name in module
4141
// +optional
4242
ModuleOutputName string `json:"moduleOutputName"`
43+
// Sensitive value
44+
// +optional
45+
Sensitive bool `json:"sensitive,omitempty"`
4346
}
4447

4548
// OutputStatus outputs the values of Terraform output

config/crd/bases/app.terraform.io_workspaces.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,9 @@ spec:
125125
moduleOutputName:
126126
description: Attribute name in module
127127
type: string
128+
sensitive:
129+
description: Sensitive value
130+
type: boolean
128131
type: object
129132
type: array
130133
runTriggers:

workspacehelper/terraform.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ func CreateTerraformTemplate(workspace *v1alpha1.Workspace) ([]byte, error) {
3333
{{- range .Spec.Outputs}}
3434
output "{{.Key}}" {
3535
value = module.operator.{{.ModuleOutputName}}
36+
sensitive = {{.Sensitive}}
3637
}
3738
{{- end}}
3839
module "operator" {

workspacehelper/terraform_test.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,9 +145,15 @@ func TestShouldCreateTerraformWithOutputs(t *testing.T) {
145145
}
146146
output "module_output" {
147147
value = module.operator.my_output
148+
sensitive = false
148149
}
149150
output "ip" {
150151
value = module.operator.ip_address
152+
sensitive = false
153+
}
154+
output "password" {
155+
value = module.operator.my_password
156+
sensitive = true
151157
}
152158
module "operator" {
153159
source = "my_source"
@@ -174,6 +180,11 @@ func TestShouldCreateTerraformWithOutputs(t *testing.T) {
174180
Key: "ip",
175181
ModuleOutputName: "ip_address",
176182
},
183+
{
184+
Key: "password",
185+
ModuleOutputName: "my_password",
186+
Sensitive: true,
187+
},
177188
},
178189
},
179190
}

workspacehelper/tfc_output.go

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -151,14 +151,12 @@ func (t *TerraformCloudClient) GetOutputsFromState(stateDownloadURL string) ([]*
151151
outputValues := file.State.Modules[""].OutputValues
152152
outputs := []*v1alpha1.OutputStatus{}
153153
for key, value := range outputValues {
154-
if !value.Sensitive {
155-
if err != nil {
156-
return outputs, fmt.Errorf("output value could not be converted to string, Error, %v", err)
157-
}
158-
statusValue := convertValueToString(value.Value)
159-
if statusValue != "" {
160-
outputs = append(outputs, &v1alpha1.OutputStatus{Key: key, Value: statusValue})
161-
}
154+
if err != nil {
155+
return outputs, fmt.Errorf("output value could not be converted to string, Error, %v", err)
156+
}
157+
statusValue := convertValueToString(value.Value)
158+
if statusValue != "" {
159+
outputs = append(outputs, &v1alpha1.OutputStatus{Key: key, Value: statusValue})
162160
}
163161
}
164162
return outputs, nil

0 commit comments

Comments
 (0)