@@ -323,7 +323,7 @@ func promptAddExceptionConstraints(policy api.Policy) ([]api.PolicyExceptionCons
323323 answer , err := promptAskConstraintsQuestion (q )
324324
325325 if err != nil {
326- return []api.PolicyExceptionConstraint {}, nil
326+ return []api.PolicyExceptionConstraint {}, err
327327 }
328328
329329 if answer != nil {
@@ -361,10 +361,15 @@ func promptAskConstraintsQuestion(constraintQuestion PolicyExceptionSurveyQuesti
361361 }
362362 case "KVTagPair" :
363363 if constraintQuestion .constraint .MultiValue {
364- //prompt kv tag list
365- answer , err = promptAddExceptionConstraintMapList (
366- constraintQuestion .constraint .FieldKey , constraintQuestion .questions ,
367- )
364+ // workaround for the unique shape of resourceTags data, see GROW-2831
365+ if constraintQuestion .constraint .FieldKey == "resourceTags" {
366+ answer , err = promptAddExceptionConstraintResourceTags (constraintQuestion .constraint .FieldKey )
367+ } else {
368+ //prompt kv tag list
369+ answer , err = promptAddExceptionConstraintMapList (
370+ constraintQuestion .constraint .FieldKey , constraintQuestion .questions ,
371+ )
372+ }
368373 } else {
369374 //prompt kv tag
370375 mapAnswers , err := promptAddExceptionConstraintMap (constraintQuestion .questions )
@@ -548,11 +553,44 @@ func promptAddExceptionConstraintMap(mapQuestions []*survey.Question) (constrain
548553 return mapAnswer , nil
549554}
550555
551- type constraintMapAnswer struct {
556+ // resourceTags requires special handling, see GROW-2831
557+ type resourceTagsConstraintAnswer struct {
552558 Key string `json:"key"`
553559 Value string `json:"value"`
554560}
555561
562+ // resourceTags requires special handling, see GROW-2831
563+ func promptAddExceptionConstraintResourceTags (key string ) (* api.PolicyExceptionConstraint , error ) {
564+ questions := []* survey.Question {{
565+ Name : "key" ,
566+ Prompt : & survey.Input {Message : "tag name:" },
567+ Validate : survey .Required ,
568+ }, {
569+ Name : "value" ,
570+ Prompt : & survey.Input {Message : "values:" , Help : "Supply a comma seperated list for multiple" },
571+ Validate : survey .Required ,
572+ }}
573+
574+ var answer resourceTagsConstraintAnswer
575+ if err := survey .Ask (questions , & answer ); err != nil {
576+ return nil , err
577+ }
578+
579+ finalAnswer := strings .Split (answer .Value , "," )
580+ return & api.PolicyExceptionConstraint {
581+ FieldKey : key ,
582+ FieldValues : []any {
583+ map [string ]interface {}{"key" : answer .Key , "value" : finalAnswer },
584+ },
585+ }, nil
586+
587+ }
588+
589+ type constraintMapAnswer struct {
590+ Key string `json:"key"`
591+ Value []string `json:"value"`
592+ }
593+
556594func promptAddExceptionConstraintMapList (
557595 key string , mapQuestions []* survey.Question ,
558596) (* api.PolicyExceptionConstraint , error ) {
0 commit comments