diff --git a/pkg/recipes/driver/terraform.go b/pkg/recipes/driver/terraform.go index 788d270e14..c87c3c093c 100644 --- a/pkg/recipes/driver/terraform.go +++ b/pkg/recipes/driver/terraform.go @@ -146,6 +146,8 @@ func (d *terraformDriver) prepareRecipeResponse(tfState *tfjson.State) (*recipes } resources := []string{} resources = append(resources, recipeResponse.Resources...) + deployedResources := d.getDeployedOutputResources(tfState.Values.RootModule) + resources = append(resources, deployedResources...) res, err := getOutputResourcesFromTerraformRecipe(resources) if err != nil { return &recipes.RecipeOutputResponse{}, err @@ -157,6 +159,25 @@ func (d *terraformDriver) prepareRecipeResponse(tfState *tfjson.State) (*recipes return result, nil } +func (d *terraformDriver) getDeployedOutputResources(module *tfjson.StateModule) []string { + recipeResources := []string{} + if module == nil { + return recipeResources + } + for _, resource := range module.Resources { + if resource.AttributeValues != nil { + if id, ok := resource.AttributeValues["id"].(string); ok { + recipeResources = append(recipeResources, id) + } + } + } + for _, childModule := range module.ChildModules { + modResources := d.getDeployedOutputResources(childModule) + recipeResources = append(recipeResources, modResources...) + } + return recipeResources +} + // createExecutionDirectory creates a unique directory for each execution of terraform. func (d *terraformDriver) createExecutionDirectory(ctx context.Context, recipe recipes.ResourceMetadata, definition recipes.EnvironmentDefinition) (string, error) { logger := ucplog.FromContextOrDiscard(ctx) diff --git a/pkg/recipes/driver/terraform_test.go b/pkg/recipes/driver/terraform_test.go index 62a6208d06..61c6175243 100644 --- a/pkg/recipes/driver/terraform_test.go +++ b/pkg/recipes/driver/terraform_test.go @@ -481,7 +481,7 @@ func Test_Terraform_Delete_Failure(t *testing.T) { func Test_Terraform_PrepareRecipeResponse(t *testing.T) { d := &terraformDriver{} outputResources := []rpv1.OutputResource{} - for _, resource := range []string{"outputResourceId1"} { + for _, resource := range []string{"outputResourceId1", "outputResourceId2"} { id := ucp_resources.ParseTerraformResource(resource) result := rpv1.OutputResource{ ID: id,