cfn-lint version: (cfn-lint --version)
0.20.0
Description of issue.
Creating additional volumes require AvailabilityZone as a mandatory property.
Please provide as much information as possible:
When creating additional volumes to be associated with an instance, there is a requirement to add the AvailabilityZone as a mandatory property.
AvailabilityZone
The Availability Zone in which to create the new volume.
Required: Yes
Type: String
https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-ec2-ebs-volume.html
Cfn-lint uses the CloudFormation Resource Specifications as the base to do validation. These files are included as part of the application version. Please update to the latest version of cfn-lint or update the spec files manually (cfn-lint -u)
When I test this scenario.
NewVolume:
Type: "AWS::EC2::Volume"
Properties:
Size: 100
VolumeType: io1
Iops: 100
will result in
E3003 Property AvailabilityZone missing at Resources/NewVolume/Properties
Are you not seeing this error for some reason?
Adding AvailabilityZone throws W3010, removing it will throw E3003.
Either way there will be one exception.
The rule is there to prevent you from hardcoding AZ's, making going multi-region more complex.
In this an AZ is indeed needed, but it's about how to specify this. Never "lock" it to a region/AZ in the template itself, but use parameters or intrinsic function (or something else) so the template can be deployed to other regions.
Example
AWSTemplateFormatVersion: "2010-09-09"
Parameters:
AvailabilityZone1a:
Type: "AWS::EC2::AvailabilityZone::Name"
Default: "us-east-1a"
Resources:
VolumeHardcoded:
Type: "AWS::EC2::Volume"
Properties:
AvailabilityZone: "us-east-1a" # Hardcoded
VolumeParameter:
Type: "AWS::EC2::Volume"
Properties:
AvailabilityZone: !Ref "AvailabilityZone1a"
VolumeGetAz:
Type: "AWS::EC2::Volume"
Properties:
AvailabilityZone: !Select
- 0
- Fn::GetAZs: !Ref 'AWS::Region'
In this template, only the first one (hardcoded one) generated an error (The W3010 warning in this case). The other 2 are "dynamic" ways of specifying the AZ.
If you are associating to an instance you can use the instance attribute too.
VolumeGetAz:
Type: "AWS::EC2::Volume"
Properties:
AvailabilityZone: !GetAtt EC2Instance.AvailabilityZone
thanks, @fatbasstard that resolved my issue.
Most helpful comment
If you are associating to an instance you can use the instance attribute too.