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

Support sensitive output (fixes #107) #131

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions api/v1alpha1/workspace_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ type OutputSpec struct {
// Attribute name in module
// +optional
ModuleOutputName string `json:"moduleOutputName"`
// Sensitive value
// +optional
Sensitive bool `json:"sensitive,omitempty"`
}

// OutputStatus outputs the values of Terraform output
Expand Down
3 changes: 3 additions & 0 deletions config/crd/bases/app.terraform.io_workspaces.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,9 @@ spec:
moduleOutputName:
description: Attribute name in module
type: string
sensitive:
description: Sensitive value
type: boolean
type: object
type: array
runTriggers:
Expand Down
1 change: 1 addition & 0 deletions workspacehelper/terraform.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ func CreateTerraformTemplate(workspace *v1alpha1.Workspace) ([]byte, error) {
{{- range .Spec.Outputs}}
output "{{.Key}}" {
value = module.operator.{{.ModuleOutputName}}
sensitive = {{.Sensitive}}
}
{{- end}}
module "operator" {
Expand Down
11 changes: 11 additions & 0 deletions workspacehelper/terraform_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,15 @@ func TestShouldCreateTerraformWithOutputs(t *testing.T) {
}
output "module_output" {
value = module.operator.my_output
sensitive = false
}
output "ip" {
value = module.operator.ip_address
sensitive = false
}
output "password" {
value = module.operator.my_password
sensitive = true
}
module "operator" {
source = "my_source"
Expand All @@ -174,6 +180,11 @@ func TestShouldCreateTerraformWithOutputs(t *testing.T) {
Key: "ip",
ModuleOutputName: "ip_address",
},
{
Key: "password",
ModuleOutputName: "my_password",
Sensitive: true,
},
},
},
}
Expand Down
14 changes: 6 additions & 8 deletions workspacehelper/tfc_output.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,14 +151,12 @@ func (t *TerraformCloudClient) GetOutputsFromState(stateDownloadURL string) ([]*
outputValues := file.State.Modules[""].OutputValues
outputs := []*v1alpha1.OutputStatus{}
for key, value := range outputValues {
if !value.Sensitive {
if err != nil {
return outputs, fmt.Errorf("output value could not be converted to string, Error, %v", err)
}
statusValue := convertValueToString(value.Value)
if statusValue != "" {
outputs = append(outputs, &v1alpha1.OutputStatus{Key: key, Value: statusValue})
}
if err != nil {
return outputs, fmt.Errorf("output value could not be converted to string, Error, %v", err)
}
statusValue := convertValueToString(value.Value)
if statusValue != "" {
outputs = append(outputs, &v1alpha1.OutputStatus{Key: key, Value: statusValue})
}
}
return outputs, nil
Expand Down