Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,12 @@ trap cleanup EXIT INT TERM

terraform init
terraform plan
terraform apply -auto-approve && touch /tmp/tf-applied
terraform apply -auto-approve

terraform output -json > /output/tfOutputValues.json

touch /tmp/tf-applied # This file is used as indicator (healthcheck) that the service is UP, and so it must be placed as the last statement in the script

echo "Terraform definitions applied."

set +x
Expand Down
12 changes: 3 additions & 9 deletions internal/testrunner/runners/system/servicedeployer/terraform.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,16 +62,10 @@ func addTerraformOutputs(outCtxt ServiceContext) error {
}

// Unmarshall the data into `terraformOutputs`
logger.Debug("Unmarshalling terraform output json")
logger.Debug("Unmarshalling terraform output JSON")
var terraformOutputs map[string]OutputMeta

if !json.Valid(content) {
logger.Debug("Invalid Json content in the terraform output file, skipped creating outputs")
return nil
}

if err = json.Unmarshal(content, &terraformOutputs); err != nil {
return fmt.Errorf("error during json Unmarshal %w", err)
return fmt.Errorf("error during JSON Unmarshal: %w", err)
}

if len(terraformOutputs) == 0 {
Expand Down Expand Up @@ -166,7 +160,7 @@ func (tsd TerraformServiceDeployer) SetUp(inCtxt ServiceContext) (DeployedServic

err = addTerraformOutputs(outCtxt)
if err != nil {
return nil, fmt.Errorf("could not handle terraform output %w", err)
return nil, fmt.Errorf("could not handle terraform output: %w", err)
}
service.ctxt = outCtxt
return &service, nil
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ func TestAddTerraformOutputs(t *testing.T) {
runId string
content []byte
expectedProps map[string]interface{}
expectedError bool
}{
{
testName: "invalid_json_output",
Expand All @@ -31,6 +32,7 @@ func TestAddTerraformOutputs(t *testing.T) {
``,
),
expectedProps: map[string]interface{}{},
expectedError: true,
},
{
testName: "empty_json_output",
Expand Down Expand Up @@ -145,6 +147,10 @@ func TestAddTerraformOutputs(t *testing.T) {

// Test that the terraform output values are generated correctly
err := addTerraformOutputs(tc.ctxt)
if tc.expectedError {
require.Error(t, err)
return
}
require.NoError(t, err)
assert.Equal(t, tc.expectedProps, tc.ctxt.CustomProperties)
})
Expand Down