Skip to content

Cloudformation specific YAML encode function to validate template before using aws_cloudformation_stack #42790

@nitrocode

Description

@nitrocode

Description

Problem is that the cloudformation stacks sometimes do not follow the correct spacing or yaml spec when it is modified. We find out upon apply instead of during the init/plan phase.

We can use something like cfn-lint or other tools to catch this but it would be nice to have it in native in the provider so we do not have to use external tools.

For example, if we want to make sure the json or yaml is correct, we can do something like this before we create the resources that depend on these templates.

locals {
  yaml_object = yamldecode(file("${path.module}/stack.yaml"))
  json_object = jsondecode(file("${path.module}/stack.json"))
}

I tried this and received an error because the cloudformation yaml contains some cloudformation-isms that are not compliant with the YAML spec.

locals {
  raw_file    = file("${path.module}/cfstack.yaml")
  yaml_object = yamldecode(local.raw_file)
}

If there was a provider function to do this, that would make it much easier to turn this into a parsable object.

e.g. cfdecode

locals {
  raw_file    = file("${path.module}/cfstack.yaml")
  yaml_object = provider::aws::cfdecode(local.raw_file)
}

Affected Resource(s) or Data Source(s)

  • aws_cloudformation_stack

Potential Terraform Configuration

See above

References

N/A

Would you like to implement the enhancement?

No

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementRequests to existing resources that expand the functionality or scope.functionPertains to provider functions.new-functionIntroduces a new function.service/cloudformationIssues and PRs that pertain to the cloudformation service.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions