diff --git a/command/taint.go b/command/taint.go index 54aa00146..399f0e330 100644 --- a/command/taint.go +++ b/command/taint.go @@ -4,6 +4,8 @@ import ( "fmt" "log" "strings" + + "github.com/hashicorp/terraform/terraform" ) // TaintCommand is a cli.Command implementation that manually taints @@ -43,6 +45,17 @@ func (c *TaintCommand) Run(args []string) int { module = "root." + module } + rsk, err := terraform.ParseResourceStateKey(name) + if err != nil { + c.Ui.Error(fmt.Sprintf("Failed to parse resource name: %s", err)) + return 1 + } + + if !rsk.Mode.Taintable() { + c.Ui.Error(fmt.Sprintf("Resource '%s' cannot be tainted", name)) + return 1 + } + // Get the state that we'll be modifying state, err := c.State() if err != nil { diff --git a/config/config.go b/config/config.go index 6ad568a7e..848552aac 100644 --- a/config/config.go +++ b/config/config.go @@ -938,3 +938,14 @@ func (v *Variable) inferTypeFromDefault() VariableType { return VariableTypeUnknown } + +func (m ResourceMode) Taintable() bool { + switch m { + case ManagedResourceMode: + return true + case DataResourceMode: + return false + default: + panic(fmt.Errorf("unsupported ResourceMode value %s", m)) + } +}