Repository: aws-cloudformation/rain
Pull request #147 (2023-06-02 16:56:27)

Add --ignore-unknown-params to the rain deploy command
*Issue #, if available:*
https://github.com/aws-cloudformation/rain/issues/144

*Description of changes:*


By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.



Patch:
diff --git a/docs/bash_completion.sh b/docs/bash_completion.sh
index 4e9fae11..abc3a201 100644
--- a/docs/bash_completion.sh
+++ b/docs/bash_completion.sh
@@ -567,6 +567,8 @@ _rain_deploy()
     flags+=("-h")
     local_nonpersistent_flags+=("--help")
     local_nonpersistent_flags+=("-h")
+    flags+=("--ignore-unknown-params")
+    local_nonpersistent_flags+=("--ignore-unknown-params")
     flags+=("--keep")
     flags+=("-k")
     local_nonpersistent_flags+=("--keep")
diff --git a/docs/index.md b/docs/index.md
index d7feba3f..4041fde6 100644
--- a/docs/index.md
+++ b/docs/index.md
@@ -34,4 +34,4 @@ Rain is a command line tool for working with AWS CloudFormation templates and st
 * [rain tree](rain_tree.md)	 - Find dependencies of Resources and Outputs in a local template
 * [rain watch](rain_watch.md)	 - Display an updating view of a CloudFormation stack
 
-###### Auto generated by spf13/cobra on 28-May-2023
+###### Auto generated by spf13/cobra on 3-Jun-2023
diff --git a/docs/rain_bootstrap.md b/docs/rain_bootstrap.md
index 73ec2555..2663707e 100644
--- a/docs/rain_bootstrap.md
+++ b/docs/rain_bootstrap.md
@@ -30,4 +30,4 @@ rain bootstrap
 
 * [rain](index.md)	 - 
 
-###### Auto generated by spf13/cobra on 28-May-2023
+###### Auto generated by spf13/cobra on 3-Jun-2023
diff --git a/docs/rain_build.md b/docs/rain_build.md
index 39c5a445..169eb83f 100644
--- a/docs/rain_build.md
+++ b/docs/rain_build.md
@@ -30,4 +30,4 @@ rain build [<resource type>...]
 
 * [rain](index.md)	 - 
 
-###### Auto generated by spf13/cobra on 28-May-2023
+###### Auto generated by spf13/cobra on 3-Jun-2023
diff --git a/docs/rain_cat.md b/docs/rain_cat.md
index 5d9b4465..12ee9ae6 100644
--- a/docs/rain_cat.md
+++ b/docs/rain_cat.md
@@ -31,4 +31,4 @@ rain cat <stack>
 
 * [rain](index.md)	 - 
 
-###### Auto generated by spf13/cobra on 28-May-2023
+###### Auto generated by spf13/cobra on 3-Jun-2023
diff --git a/docs/rain_console.md b/docs/rain_console.md
index c20cb371..9e3723a3 100644
--- a/docs/rain_console.md
+++ b/docs/rain_console.md
@@ -38,4 +38,4 @@ rain console [stack]
 
 * [rain](index.md)	 - 
 
-###### Auto generated by spf13/cobra on 28-May-2023
+###### Auto generated by spf13/cobra on 3-Jun-2023
diff --git a/docs/rain_deploy.md b/docs/rain_deploy.md
index 42b9a62a..f1f5a4a3 100644
--- a/docs/rain_deploy.md
+++ b/docs/rain_deploy.md
@@ -46,6 +46,7 @@ rain deploy <template> [stack]
   -c, --config string            YAML or JSON file to set tags and parameters
   -d, --detach                   once deployment has started, don't wait around for it to finish
   -h, --help                     help for deploy
+      --ignore-unknown-params    Ignore unknown parameters
   -k, --keep                     keep deployed resources after a failure by disabling rollbacks
       --params strings           set parameter values; use the format key1=value1,key2=value2
   -p, --profile string           AWS profile name; read from the AWS CLI configuration file
@@ -69,4 +70,4 @@ rain deploy <template> [stack]
 
 * [rain](index.md)	 - 
 
-###### Auto generated by spf13/cobra on 28-May-2023
+###### Auto generated by spf13/cobra on 3-Jun-2023
diff --git a/docs/rain_diff.md b/docs/rain_diff.md
index 6e2e223f..4bded935 100644
--- a/docs/rain_diff.md
+++ b/docs/rain_diff.md
@@ -28,4 +28,4 @@ rain diff <from> <to>
 
 * [rain](index.md)	 - 
 
-###### Auto generated by spf13/cobra on 28-May-2023
+###### Auto generated by spf13/cobra on 3-Jun-2023
diff --git a/docs/rain_fmt.md b/docs/rain_fmt.md
index a8633df6..78fe3586 100644
--- a/docs/rain_fmt.md
+++ b/docs/rain_fmt.md
@@ -32,4 +32,4 @@ rain fmt <filename>...
 
 * [rain](index.md)	 - 
 
-###### Auto generated by spf13/cobra on 28-May-2023
+###### Auto generated by spf13/cobra on 3-Jun-2023
diff --git a/docs/rain_forecast.md b/docs/rain_forecast.md
index 1092520d..87916cbe 100644
--- a/docs/rain_forecast.md
+++ b/docs/rain_forecast.md
@@ -59,4 +59,4 @@ rain forecast --experimental <template> [stackName]
 
 * [rain](index.md)	 - 
 
-###### Auto generated by spf13/cobra on 28-May-2023
+###### Auto generated by spf13/cobra on 3-Jun-2023
diff --git a/docs/rain_info.md b/docs/rain_info.md
index d3fe83b5..a31b54e2 100644
--- a/docs/rain_info.md
+++ b/docs/rain_info.md
@@ -30,4 +30,4 @@ rain info
 
 * [rain](index.md)	 - 
 
-###### Auto generated by spf13/cobra on 28-May-2023
+###### Auto generated by spf13/cobra on 3-Jun-2023
diff --git a/docs/rain_logs.md b/docs/rain_logs.md
index 48fe0f50..a30ce941 100644
--- a/docs/rain_logs.md
+++ b/docs/rain_logs.md
@@ -33,4 +33,4 @@ rain logs <stack> (<resource>)
 
 * [rain](index.md)	 - 
 
-###### Auto generated by spf13/cobra on 28-May-2023
+###### Auto generated by spf13/cobra on 3-Jun-2023
diff --git a/docs/rain_ls.md b/docs/rain_ls.md
index 09f7cf17..5adc9a81 100644
--- a/docs/rain_ls.md
+++ b/docs/rain_ls.md
@@ -30,4 +30,4 @@ rain ls <stack>
 
 * [rain](index.md)	 - 
 
-###### Auto generated by spf13/cobra on 28-May-2023
+###### Auto generated by spf13/cobra on 3-Jun-2023
diff --git a/docs/rain_merge.md b/docs/rain_merge.md
index 03688e0e..338265ad 100644
--- a/docs/rain_merge.md
+++ b/docs/rain_merge.md
@@ -29,4 +29,4 @@ rain merge <template> <template> ...
 
 * [rain](index.md)	 - 
 
-###### Auto generated by spf13/cobra on 28-May-2023
+###### Auto generated by spf13/cobra on 3-Jun-2023
diff --git a/docs/rain_pkg.md b/docs/rain_pkg.md
index 71ac3615..4765542b 100644
--- a/docs/rain_pkg.md
+++ b/docs/rain_pkg.md
@@ -66,4 +66,4 @@ rain pkg <template>
 
 * [rain](index.md)	 - 
 
-###### Auto generated by spf13/cobra on 28-May-2023
+###### Auto generated by spf13/cobra on 3-Jun-2023
diff --git a/docs/rain_rm.md b/docs/rain_rm.md
index 6326e3f0..1e540aee 100644
--- a/docs/rain_rm.md
+++ b/docs/rain_rm.md
@@ -32,4 +32,4 @@ rain rm <stack>
 
 * [rain](index.md)	 - 
 
-###### Auto generated by spf13/cobra on 28-May-2023
+###### Auto generated by spf13/cobra on 3-Jun-2023
diff --git a/docs/rain_stackset.md b/docs/rain_stackset.md
index 47b62fde..8917d214 100644
--- a/docs/rain_stackset.md
+++ b/docs/rain_stackset.md
@@ -28,4 +28,4 @@ This command manipulates stack sets. It has no action if specific stack set comm
 * [rain stackset ls](rain_stackset_ls.md)	 - List a CloudFormation stack sets in a given region
 * [rain stackset rm](rain_stackset_rm.md)	 - Delete a CloudFormation stack set and/or its instances.
 
-###### Auto generated by spf13/cobra on 28-May-2023
+###### Auto generated by spf13/cobra on 3-Jun-2023
diff --git a/docs/rain_stackset_deploy.md b/docs/rain_stackset_deploy.md
index fddb9ce2..ad41fedc 100644
--- a/docs/rain_stackset_deploy.md
+++ b/docs/rain_stackset_deploy.md
@@ -62,4 +62,4 @@ rain stackset deploy <template> [stackset] [flags]
 
 * [rain stackset](rain_stackset.md)	 - This command manipulates stack sets.
 
-###### Auto generated by spf13/cobra on 28-May-2023
+###### Auto generated by spf13/cobra on 3-Jun-2023
diff --git a/docs/rain_stackset_ls.md b/docs/rain_stackset_ls.md
index 062ebdbe..4e073f6d 100644
--- a/docs/rain_stackset_ls.md
+++ b/docs/rain_stackset_ls.md
@@ -30,4 +30,4 @@ rain stackset ls <stack set>
 
 * [rain stackset](rain_stackset.md)	 - This command manipulates stack sets.
 
-###### Auto generated by spf13/cobra on 28-May-2023
+###### Auto generated by spf13/cobra on 3-Jun-2023
diff --git a/docs/rain_stackset_rm.md b/docs/rain_stackset_rm.md
index 30db63eb..e535d2af 100644
--- a/docs/rain_stackset_rm.md
+++ b/docs/rain_stackset_rm.md
@@ -30,4 +30,4 @@ rain stackset rm <stackset>
 
 * [rain stackset](rain_stackset.md)	 - This command manipulates stack sets.
 
-###### Auto generated by spf13/cobra on 28-May-2023
+###### Auto generated by spf13/cobra on 3-Jun-2023
diff --git a/docs/rain_tree.md b/docs/rain_tree.md
index c4c9aecf..33bbd2e3 100644
--- a/docs/rain_tree.md
+++ b/docs/rain_tree.md
@@ -30,4 +30,4 @@ rain tree [template]
 
 * [rain](index.md)	 - 
 
-###### Auto generated by spf13/cobra on 28-May-2023
+###### Auto generated by spf13/cobra on 3-Jun-2023
diff --git a/docs/rain_watch.md b/docs/rain_watch.md
index 63c0520e..7d04723d 100644
--- a/docs/rain_watch.md
+++ b/docs/rain_watch.md
@@ -30,4 +30,4 @@ rain watch <stack>
 
 * [rain](index.md)	 - 
 
-###### Auto generated by spf13/cobra on 28-May-2023
+###### Auto generated by spf13/cobra on 3-Jun-2023
diff --git a/internal/cmd/deploy/deploy.go b/internal/cmd/deploy/deploy.go
index f75b7cfb..44a54c07 100644
--- a/internal/cmd/deploy/deploy.go
+++ b/internal/cmd/deploy/deploy.go
@@ -25,6 +25,7 @@ var configFilePath string
 var terminationProtection bool
 var keep bool
 var roleArn string
+var ignoreUnknownParams bool
 
 // Cmd is the deploy command's entrypoint
 var Cmd = &cobra.Command{
@@ -88,7 +89,7 @@ YAML:
 		spinner.Pop()
 
 		dc, err := dc.GetDeployConfig(tags, params, configFilePath, base,
-			template, stack, stackExists, yes)
+			template, stack, stackExists, yes, ignoreUnknownParams)
 		if err != nil {
 			panic(err)
 		}
@@ -186,4 +187,5 @@ func init() {
 	Cmd.Flags().BoolVarP(&terminationProtection, "termination-protection", "t", false, "enable termination protection on the stack")
 	Cmd.Flags().BoolVarP(&keep, "keep", "k", false, "keep deployed resources after a failure by disabling rollbacks")
 	Cmd.Flags().StringVarP(&roleArn, "role-arn", "", "", "ARN of an IAM role that CloudFormation should assume to deploy the stack")
+	Cmd.Flags().BoolVarP(&ignoreUnknownParams, "ignore-unknown-params", "", false, "Ignore unknown parameters")
 }
diff --git a/internal/cmd/forecast/forecast.go b/internal/cmd/forecast/forecast.go
index e9684826..144385bd 100644
--- a/internal/cmd/forecast/forecast.go
+++ b/internal/cmd/forecast/forecast.go
@@ -327,7 +327,7 @@ Resource-specific checks:
 		config.Debugf("Stack %v %v", stackName, msg)
 
 		dc, err := dc.GetDeployConfig(tags, params, configFilePath, base,
-			source, stack, stackExists, true)
+			source, stack, stackExists, true, false)
 		if err != nil {
 			panic(err)
 		}
diff --git a/internal/cmd/stackset/stackset_deploy.go b/internal/cmd/stackset/stackset_deploy.go
index 7ff57230..a4b9a8b5 100644
--- a/internal/cmd/stackset/stackset_deploy.go
+++ b/internal/cmd/stackset/stackset_deploy.go
@@ -368,7 +368,7 @@ func buildParameterTypes(template cft.Template, combinedParams map[string]string
 		oldParams = stackSet.Parameters
 		stackSetExist = true
 	}
-	return dc.GetParameters(template, combinedParams, oldParams, stackSetExist, true)
+	return dc.GetParameters(template, combinedParams, oldParams, stackSetExist, true, false)
 }
 
 // updates existing stack set and all its instances
diff --git a/internal/dc/dc.go b/internal/dc/dc.go
index 3d25d9a8..c98772ae 100644
--- a/internal/dc/dc.go
+++ b/internal/dc/dc.go
@@ -39,7 +39,8 @@ func GetParameters(
 	combinedParameters map[string]string,
 	old []types.Parameter,
 	stackExists bool,
-	yes bool) []types.Parameter {
+	yes bool,
+	ignoreUnknownParams bool) []types.Parameter {
 
 	newParams := make([]types.Parameter, 0)
 
@@ -55,7 +56,11 @@ func GetParameters(
 		// Check we don't have any unknown params
 		for k := range combinedParameters {
 			if _, ok := params.(map[string]interface{})[k]; !ok {
-				panic(fmt.Errorf("unknown parameter: %s", k))
+				if ignoreUnknownParams {
+					fmt.Println(console.Yellow(fmt.Sprintf("unknown parameter: %s", k)))
+				} else {
+					panic(fmt.Errorf("unknown parameter: %s\nif you want to proceed as is, add the --ignore-unknown-params flag", k))
+				}
 			}
 		}
 
@@ -187,7 +192,8 @@ func GetDeployConfig(
 	template cft.Template,
 	stack types.Stack,
 	stackExists bool,
-	yes bool) (*DeployConfig, error) {
+	yes bool,
+	ignoreUnknownParams bool) (*DeployConfig, error) {
 
 	dc := &DeployConfig{}
 
@@ -238,7 +244,7 @@ func GetDeployConfig(
 	// Parse params
 	config.Debugf("Handling parameters")
 	parameters := GetParameters(template, combinedParameters,
-		stack.Parameters, stackExists, yes)
+		stack.Parameters, stackExists, yes, ignoreUnknownParams)
 
 	if config.Debug {
 		for _, param := range parameters {


Test patch:
diff --git a/internal/cmd/deploy/deploy_test.go b/internal/cmd/deploy/deploy_test.go
index c4f389fa..0e34edf9 100644
--- a/internal/cmd/deploy/deploy_test.go
+++ b/internal/cmd/deploy/deploy_test.go
@@ -52,6 +52,7 @@ func Example_deploy_help() {
 	//   -c, --config string            YAML or JSON file to set tags and parameters
 	//   -d, --detach                   once deployment has started, don't wait around for it to finish
 	//   -h, --help                     help for deploy
+	//       --ignore-unknown-params    Ignore unknown parameters
 	//   -k, --keep                     keep deployed resources after a failure by disabling rollbacks
 	//       --params strings           set parameter values; use the format key1=value1,key2=value2
 	//       --role-arn string          ARN of an IAM role that CloudFormation should assume to deploy the stack