My goal here is to raise a custom error instead of the error received from terraform for this sample code:
resource "aws_instance" "example" {
ami = "ami-0f" # Invalid AMI ID intentionally causing an error
instance_type = "t2.micro"
}
for this code I got an error output:
aws_instance.example: Creating...
╷
│ Error: creating EC2 Instance: InvalidAMIID.NotFound: The image id '[ami-0f]' does not exist
│ status code: 400, request id: 2d665c80-8918-4940-92cc-11f7a14ecd57
│
│ with aws_instance.example,
│ on main.tf line 27, in resource "aws_instance" "example":
│ 27: resource "aws_instance" "example" {
│
╵
The above error is a proper error.. But I want to create a custom error like below:
Custom message: Failed to create the AWS instance.
Kindly give suggestions on:
- How to display my custom error instead of the proper error displayed by terraform?
- and also How to display my custom error along with the proper error displayed by terraform?
If you have any standard logics for error handling and exception handling in terraform please do share.
Checkboxes:
I have properly configured the aws provider, the access and secret tokens
Thank you