OutputSub checks a Sub to see if it refers to a module Output. A Sub string can refer to an output scalar value. The reference needs to be like a GetAtt. For example, !Sub ${A.B} refers to module A, output B.
(outputName string, outputVal any, n *yaml.Node)
| 225 | // The reference needs to be like a GetAtt. |
| 226 | // For example, !Sub ${A.B} refers to module A, output B. |
| 227 | func (module *Module) OutputSub(outputName string, outputVal any, n *yaml.Node) error { |
| 228 | s := n.Content[1].Value |
| 229 | words, err := parse.ParseSub(s, true) |
| 230 | if err != nil { |
| 231 | return err |
| 232 | } |
| 233 | sub := "" |
| 234 | for _, word := range words { |
| 235 | switch word.T { |
| 236 | case parse.STR: |
| 237 | sub += word.W |
| 238 | case parse.AWS: |
| 239 | sub += "${AWS::" + word.W + "}" |
| 240 | case parse.REF: |
| 241 | sub += "${" + word.W + "}" |
| 242 | case parse.GETATT: |
| 243 | outputValue, err := module.CheckOutputGetAtt(word.W, outputName, outputVal) |
| 244 | if err != nil { |
| 245 | return err |
| 246 | } |
| 247 | if outputValue == nil { |
| 248 | sub += "${" + word.W + "}" |
| 249 | } else { |
| 250 | if outputValue.Kind == yaml.MappingNode { |
| 251 | // Prepend the module name |
| 252 | v := outputValue.Content[1] |
| 253 | switch outputValue.Content[0].Value { |
| 254 | case string(cft.Sub): |
| 255 | sub += "${" + v.Value + "}" |
| 256 | case string(cft.GetAtt): |
| 257 | ss := node.SequenceToStrings(v) |
| 258 | joined := strings.Join(ss, ".") |
| 259 | sub += "${" + joined + "}" |
| 260 | case string(cft.Ref): |
| 261 | sub += "${" + v.Value + "}" |
| 262 | } |
| 263 | } else if outputValue.Kind == yaml.ScalarNode { |
| 264 | sub += outputValue.Value |
| 265 | } |
| 266 | } |
| 267 | } |
| 268 | } |
| 269 | |
| 270 | var subNode *yaml.Node |
| 271 | if parse.IsSubNeeded(sub) { |
| 272 | subNode = node.MakeMapping() |
| 273 | subNode.Content = append(subNode.Content, node.MakeScalar(string(cft.Sub))) |
| 274 | subNode.Content = append(subNode.Content, node.MakeScalar(sub)) |
| 275 | } else { |
| 276 | subNode = node.MakeScalar(sub) |
| 277 | } |
| 278 | if sub != s { |
| 279 | *n = *subNode |
| 280 | } |
| 281 | return nil |
| 282 | } |
| 283 | |
| 284 | // After processing normal outputs, go back and look for array references |
no test coverage detected