Assumption: Terraform installed on MS Visual Studio Code.
Since CloudFormation supports both JSON templates and Terraform supports JSON this seems like a yes. However when I load a CloudFormation template into MS VisualStudio Code, and change the name from test.json to test.tf VS Code doesn't recognize the formatting, well visually as the name implies.
Also tried to just Run the test.json and test.tf files and Code says it doesn't know how to debug json. Also Code can't find a json debugger in the marketplace (which seems a little hard to imagine)
Anyone else have experience with this?
CodePudding user response:
Since CloudFormation supports both JSON templates and Terraform supports JSON this seems like a yes.
This is far from being true.
Although, both Terraform and CloudFormation have support for JSON files, this does not means that the syntax of those JSON files are understood by both of them. They are entirely different products developed by different maintainers. They have different ways of defining and managing resources which you would want to provision.
Terraform's AWS provider has support for creating CloudFormation stacks, more info in the documentation. If you really want to, you might be able to provision resources from CFN files, but certainly this is not accomplished just by renaming a test.json
to test.tf
.
CodePudding user response:
It seems that you have misunderstood some things:
- Both CloudFormation JSON or YML files and Terraform TF (or JSON) are in a declarative language. This is true for JSON and YML in general. You can't debug or run these files, as they are only describing an infrastructure (or an object in general) and don't implement any logic.
- For Terraform you need to install the HashiCorp.terraform extension. This will give you syntax highlighting.
- For Cloudformation I recommend cf-lint extension.
Both in CloudFormation and in Terraform you edit the files (JSON, YML, TF) and use a CLI to deploy your code. Terraform works in a much higher-level than CloudFormation. CloudFormation can only be used to deploy stacks, i.e. a set of resources. If you also need to deploy application code, you must have done that beforehand in a S3 bucket and reference it from there. Also in many situations you need to create a stack and then update it. Or you need to combine two or more stacks in a Stack Set.
Terraform manages all this complexity for you and offers a lot of features on top of CloudFormation. As already said, the JSON file formats isn't the same and can't be used interchangeably. You can provision a CloudFormation stack with Terraform though.