Skip to content

Commit

Permalink
command: Show data source reads differently in plans
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
apparentlymart committed May 10, 2016
1 parent a6c414d commit 7cdcef3
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
11 changes: 11 additions & 0 deletions command/format_plan.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "-"
Expand Down
4 changes: 2 additions & 2 deletions command/plan.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
Expand Down

0 comments on commit 7cdcef3

Please sign in to comment.