github.com/darmach/terratest@v0.34.8-0.20210517103231-80931f95e3ff/modules/aws/errors.go (about) 1 package aws 2 3 import ( 4 "fmt" 5 ) 6 7 // IpForEc2InstanceNotFound is an error that occurs when the IP for an EC2 instance is not found. 8 type IpForEc2InstanceNotFound struct { 9 InstanceId string 10 AwsRegion string 11 Type string 12 } 13 14 func (err IpForEc2InstanceNotFound) Error() string { 15 return fmt.Sprintf("Could not find a %s IP address for EC2 Instance %s in %s", err.Type, err.InstanceId, err.AwsRegion) 16 } 17 18 // HostnameForEc2InstanceNotFound is an error that occurs when the IP for an EC2 instance is not found. 19 type HostnameForEc2InstanceNotFound struct { 20 InstanceId string 21 AwsRegion string 22 Type string 23 } 24 25 func (err HostnameForEc2InstanceNotFound) Error() string { 26 return fmt.Sprintf("Could not find a %s hostname for EC2 Instance %s in %s", err.Type, err.InstanceId, err.AwsRegion) 27 } 28 29 // NotFoundError is returned when an expected object is not found 30 type NotFoundError struct { 31 objectType string 32 objectID string 33 region string 34 } 35 36 func (err NotFoundError) Error() string { 37 return fmt.Sprintf("Object of type %s with id %s not found in region %s", err.objectType, err.objectID, err.region) 38 } 39 40 func NewNotFoundError(objectType string, objectID string, region string) NotFoundError { 41 return NotFoundError{objectType, objectID, region} 42 } 43 44 // AsgCapacityNotMetError is returned when the ASG capacity is not yet at the desired capacity. 45 type AsgCapacityNotMetError struct { 46 asgName string 47 desiredCapacity int64 48 currentCapacity int64 49 } 50 51 func (err AsgCapacityNotMetError) Error() string { 52 return fmt.Sprintf( 53 "ASG %s not yet at desired capacity %d (current %d)", 54 err.asgName, 55 err.desiredCapacity, 56 err.currentCapacity, 57 ) 58 } 59 60 func NewAsgCapacityNotMetError(asgName string, desiredCapacity int64, currentCapacity int64) AsgCapacityNotMetError { 61 return AsgCapacityNotMetError{asgName, desiredCapacity, currentCapacity} 62 } 63 64 // BucketVersioningNotEnabledError is returned when an S3 bucket that should have versioning does not have it applied 65 type BucketVersioningNotEnabledError struct { 66 s3BucketName string 67 awsRegion string 68 versioningStatus string 69 } 70 71 func (err BucketVersioningNotEnabledError) Error() string { 72 return fmt.Sprintf( 73 "Versioning status for bucket %s in the %s region is %s", 74 err.s3BucketName, 75 err.awsRegion, 76 err.versioningStatus, 77 ) 78 } 79 80 func NewBucketVersioningNotEnabledError(s3BucketName string, awsRegion string, versioningStatus string) BucketVersioningNotEnabledError { 81 return BucketVersioningNotEnabledError{s3BucketName: s3BucketName, awsRegion: awsRegion, versioningStatus: versioningStatus} 82 } 83 84 // NoBucketPolicyError is returned when an S3 bucket that should have a policy applied does not 85 type NoBucketPolicyError struct { 86 s3BucketName string 87 awsRegion string 88 bucketPolicy string 89 } 90 91 func (err NoBucketPolicyError) Error() string { 92 return fmt.Sprintf( 93 "The policy for bucket %s in the %s region does not have a policy attached.", 94 err.s3BucketName, 95 err.awsRegion, 96 ) 97 } 98 99 func NewNoBucketPolicyError(s3BucketName string, awsRegion string, bucketPolicy string) NoBucketPolicyError { 100 return NoBucketPolicyError{s3BucketName: s3BucketName, awsRegion: awsRegion, bucketPolicy: bucketPolicy} 101 } 102 103 // NoInstanceTypeError is returned when none of the given instance type options are available in all AZs in a region 104 type NoInstanceTypeError struct { 105 InstanceTypeOptions []string 106 Azs []string 107 } 108 109 func (err NoInstanceTypeError) Error() string { 110 return fmt.Sprintf( 111 "None of the given instance types (%v) is available in all the AZs in this region (%v).", 112 err.InstanceTypeOptions, 113 err.Azs, 114 ) 115 } 116 117 // NoRdsInstanceTypeError is returned when none of the given instance types are avaiable for the region, database engine, and database engine combination given 118 type NoRdsInstanceTypeError struct { 119 InstanceTypeOptions []string 120 DatabaseEngine string 121 DatabaseEngineVersion string 122 } 123 124 func (err NoRdsInstanceTypeError) Error() string { 125 return fmt.Sprintf( 126 "None of the given RDS instance types (%v) is available in this region for database engine (%v) of version (%v).", 127 err.InstanceTypeOptions, 128 err.DatabaseEngine, 129 err.DatabaseEngineVersion, 130 ) 131 }