From 2ca10ad9627b0fcb0522d915a2e3f330121314ca Mon Sep 17 00:00:00 2001 From: Martin Atkins Date: Sun, 8 May 2016 00:16:35 -0700 Subject: [PATCH] command: Show data source reads differently in plans Internally a data source read is represented as a creation diff for the resource, but in the UI we'll show it as a distinct icon and color so that the user can more easily understand that these operations won't affect any real infrastructure. Unfortunately by the time we get to formatting the plan in the UI we only have the resource names to work with, and can't get at the original resource mode. Thus we're forced to infer the resource mode by exploiting knowledge of the naming scheme. --- command/format_plan.go | 11 +++++++++++ command/plan.go | 4 ++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/command/format_plan.go b/command/format_plan.go index 84f7d89e75..7846f0e8ce 100644 --- a/command/format_plan.go +++ b/command/format_plan.go @@ -96,6 +96,17 @@ func formatPlanModuleExpand( color = "green" symbol = "+" oldValues = false + + // If we're "creating" a data resource then we'll present it + // to the user as a "read" operation, so it's clear that this + // operation won't change anything outside of the Terraform state. + // Unfortunately by the time we get here we only have the name + // to work with, so we need to cheat and exploit knowledge of the + // naming scheme for data resources. + if strings.HasPrefix(name, "data.") { + symbol = "<=" + color = "cyan" + } case terraform.DiffDestroy: color = "red" symbol = "-" diff --git a/command/plan.go b/command/plan.go index 5582ddf4f4..f1294b05f6 100644 --- a/command/plan.go +++ b/command/plan.go @@ -219,7 +219,7 @@ The Terraform execution plan has been generated and is shown below. Resources are shown in alphabetical order for quick scanning. Green resources will be created (or destroyed and then created if an existing resource exists), yellow resources are being changed in-place, and red resources -will be destroyed. +will be destroyed. Cyan entries are data sources to be read. Note: You didn't specify an "-out" parameter to save this plan, so when "apply" is called, Terraform can't guarantee this is what will execute. @@ -230,7 +230,7 @@ The Terraform execution plan has been generated and is shown below. Resources are shown in alphabetical order for quick scanning. Green resources will be created (or destroyed and then created if an existing resource exists), yellow resources are being changed in-place, and red resources -will be destroyed. +will be destroyed. Cyan entries are data sources to be read. Your plan was also saved to the path below. Call the "apply" subcommand with this plan file and Terraform will exactly execute this execution