diff --git a/internal/testrunner/runners/system/servicedeployer/_static/terraform_deployer_run.sh b/internal/testrunner/runners/system/servicedeployer/_static/terraform_deployer_run.sh index b50cd53196..80054b46c2 100644 --- a/internal/testrunner/runners/system/servicedeployer/_static/terraform_deployer_run.sh +++ b/internal/testrunner/runners/system/servicedeployer/_static/terraform_deployer_run.sh @@ -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 diff --git a/internal/testrunner/runners/system/servicedeployer/terraform.go b/internal/testrunner/runners/system/servicedeployer/terraform.go index 67b79e6fca..d64d40e45d 100644 --- a/internal/testrunner/runners/system/servicedeployer/terraform.go +++ b/internal/testrunner/runners/system/servicedeployer/terraform.go @@ -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 { @@ -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 diff --git a/internal/testrunner/runners/system/servicedeployer/terraform_test.go b/internal/testrunner/runners/system/servicedeployer/terraform_test.go index ce19808beb..c8ee673b0f 100644 --- a/internal/testrunner/runners/system/servicedeployer/terraform_test.go +++ b/internal/testrunner/runners/system/servicedeployer/terraform_test.go @@ -20,6 +20,7 @@ func TestAddTerraformOutputs(t *testing.T) { runId string content []byte expectedProps map[string]interface{} + expectedError bool }{ { testName: "invalid_json_output", @@ -31,6 +32,7 @@ func TestAddTerraformOutputs(t *testing.T) { ``, ), expectedProps: map[string]interface{}{}, + expectedError: true, }, { testName: "empty_json_output", @@ -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) })