@@ -24,14 +24,14 @@ func resourceAwsEfsFileSystem() *schema.Resource {
2424 },
2525
2626 Schema : map [string ]* schema.Schema {
27- "creation_token" : & schema. Schema {
27+ "creation_token" : {
2828 Type : schema .TypeString ,
2929 Optional : true ,
3030 ForceNew : true ,
3131 ValidateFunc : validateMaxLength (64 ),
3232 },
3333
34- "reference_name" : & schema. Schema {
34+ "reference_name" : {
3535 Type : schema .TypeString ,
3636 Optional : true ,
3737 ForceNew : true ,
@@ -40,7 +40,7 @@ func resourceAwsEfsFileSystem() *schema.Resource {
4040 ValidateFunc : validateReferenceName ,
4141 },
4242
43- "performance_mode" : & schema. Schema {
43+ "performance_mode" : {
4444 Type : schema .TypeString ,
4545 Optional : true ,
4646 ForceNew : true ,
@@ -95,8 +95,8 @@ func resourceAwsEfsFileSystemCreate(d *schema.ResourceData, meta interface{}) er
9595 return nil , "error" , err
9696 }
9797
98- if len (resp . FileSystems ) < 1 {
99- return nil , "not-found" , fmt .Errorf ("EFS file system %q not found" , d .Id ())
98+ if hasEmptyFileSystems (resp ) {
99+ return nil , "not-found" , fmt .Errorf ("EFS file system %q could not be found. " , d .Id ())
100100 }
101101
102102 fs := resp .FileSystems [0 ]
@@ -110,7 +110,7 @@ func resourceAwsEfsFileSystemCreate(d *schema.ResourceData, meta interface{}) er
110110
111111 _ , err = stateConf .WaitForState ()
112112 if err != nil {
113- return fmt .Errorf ("Error waiting for EFS file system (%q) to create: %q " ,
113+ return fmt .Errorf ("Error waiting for EFS file system (%q) to create: %s " ,
114114 d .Id (), err .Error ())
115115 }
116116 log .Printf ("[DEBUG] EFS file system %q created." , d .Id ())
@@ -122,7 +122,7 @@ func resourceAwsEfsFileSystemUpdate(d *schema.ResourceData, meta interface{}) er
122122 conn := meta .(* AWSClient ).efsconn
123123 err := setTagsEFS (conn , d )
124124 if err != nil {
125- return fmt .Errorf ("Error setting EC2 tags for EFS file system (%q): %q " ,
125+ return fmt .Errorf ("Error setting EC2 tags for EFS file system (%q): %s " ,
126126 d .Id (), err .Error ())
127127 }
128128
@@ -137,25 +137,29 @@ func resourceAwsEfsFileSystemRead(d *schema.ResourceData, meta interface{}) erro
137137 })
138138 if err != nil {
139139 if awsErr , ok := err .(awserr.Error ); ok && awsErr .Code () == "FileSystemNotFound" {
140- log .Printf ("[WARN] EFS File System (%s) not found, error code (404) " , d .Id ())
140+ log .Printf ("[WARN] EFS file system (%s) could not be found. " , d .Id ())
141141 d .SetId ("" )
142142 return nil
143143 }
144144 return err
145145 }
146- if len (resp .FileSystems ) < 1 {
147- return fmt .Errorf ("EFS file system %q not found" , d .Id ())
146+
147+ if hasEmptyFileSystems (resp ) {
148+ return fmt .Errorf ("EFS file system %q could not be found." , d .Id ())
148149 }
149150
150151 tagsResp , err := conn .DescribeTags (& efs.DescribeTagsInput {
151152 FileSystemId : aws .String (d .Id ()),
152153 })
153154 if err != nil {
154- return fmt .Errorf ("Error retrieving EC2 tags for EFS file system (%q): %q " ,
155+ return fmt .Errorf ("Error retrieving EC2 tags for EFS file system (%q): %s " ,
155156 d .Id (), err .Error ())
156157 }
157158
158- d .Set ("tags" , tagsToMapEFS (tagsResp .Tags ))
159+ err = d .Set ("tags" , tagsToMapEFS (tagsResp .Tags ))
160+ if err != nil {
161+ return err
162+ }
159163
160164 return nil
161165}
@@ -182,7 +186,7 @@ func resourceAwsEfsFileSystemDelete(d *schema.ResourceData, meta interface{}) er
182186 return nil , "error" , err
183187 }
184188
185- if len (resp . FileSystems ) < 1 {
189+ if hasEmptyFileSystems (resp ) {
186190 return nil , "" , nil
187191 }
188192
@@ -197,7 +201,7 @@ func resourceAwsEfsFileSystemDelete(d *schema.ResourceData, meta interface{}) er
197201
198202 _ , err = stateConf .WaitForState ()
199203 if err != nil {
200- return fmt .Errorf ("Error waiting for EFS file system (%q) to delete: %q " ,
204+ return fmt .Errorf ("Error waiting for EFS file system (%q) to delete: %s " ,
201205 d .Id (), err .Error ())
202206 }
203207
@@ -218,10 +222,17 @@ func validateReferenceName(v interface{}, k string) (ws []string, errors []error
218222
219223func validatePerformanceModeType (v interface {}, k string ) (ws []string , errors []error ) {
220224 value := v .(string )
221- if value != "generalPurpose" && value != "maxIO" {
225+ if value != efs . PerformanceModeGeneralPurpose && value != efs . PerformanceModeMaxIo {
222226 errors = append (errors , fmt .Errorf (
223- "%q contains an invalid Performance Mode %q. Valid modes are either %q or %q" ,
224- k , value , "generalPurpose" , "maxIO" ))
227+ "%q contains an invalid Performance Mode %q. Valid modes are either %q or %q. " ,
228+ k , value , efs . PerformanceModeGeneralPurpose , efs . PerformanceModeMaxIo ))
225229 }
226230 return
227231}
232+
233+ func hasEmptyFileSystems (fs * efs.DescribeFileSystemsOutput ) bool {
234+ if fs != nil && len (fs .FileSystems ) > 0 {
235+ return false
236+ }
237+ return true
238+ }
0 commit comments