hashicorp / terraform-provider-bitbucket

This Terraform provider is archived per our provider archiving process: https://terraform.io/docs/internals/archiving.html
https://registry.terraform.io
Mozilla Public License 2.0
32 stars 105 forks source link

Fix repository resource importability #7

Closed pdecat closed 6 years ago

pdecat commented 7 years ago

ImportStatePassthrough requires ID only refresh capability.

Without this fix, the API request is incorrect (https://api.bitbucket.org/2.0/repositories//), the ID of the imported resource stored in the state is incorrect and fields are not correctly populated with actual state:

bitbucket_repository.test: Import complete!                                                                                                                                                                    
  Imported bitbucket_repository (ID: test)                                                                                                                                                                     
2017/08/25 16:52:25 [TRACE] dag/walk: added new vertex: "import bitbucket_repository.test result: test"                                                                                                        
2017/08/25 16:52:25 [TRACE] dag/walk: walking "import bitbucket_repository.test result: test"                                                                                                                  
2017/08/25 16:52:25 [TRACE] vertex 'root.import bitbucket_repository.test result: test': walking                                                                                                               
2017/08/25 16:52:25 [TRACE] vertex 'root.import bitbucket_repository.test result: test': evaluating                                                                                                            
2017/08/25 16:52:25 [TRACE] [walkImport] Entering eval tree: import bitbucket_repository.test result: test                                                                                                     
2017/08/25 16:52:25 [TRACE] root: eval: *terraform.EvalSequence                                                                                                                                                
2017/08/25 16:52:25 [TRACE] root: eval: *terraform.EvalGetProvider                                                                                                                                             
2017/08/25 16:52:25 [TRACE] root: eval: *terraform.EvalRefresh                                                                                                                                                 
bitbucket_repository.test: Refreshing state... (ID: test)                                                                                                                                                      
2017-08-25T16:52:25.628+0200 [DEBUG] plugin.terraform-provider-bitbucket: 2017/08/25 16:52:25 [DEBUG] Sending request to GET https://api.bitbucket.org/2.0/repositories//                                      
2017-08-25T16:52:26.220+0200 [DEBUG] plugin.terraform-provider-bitbucket: 2017/08/25 16:52:26 [DEBUG] Resp: &{404 Not Found 404 HTTP/2.0 2 0 map[Date:[Fri, 25 Aug 2017 14:52:26 GMT] X-Render-Time:[0.0351650$

With the fix, the resource is correctly read:

bitbucket_repository.test: Import complete!                                                                  
  Imported bitbucket_repository (ID: patrick_decat/test)                                                                                                                                                       2017/08/25 17:26:11 [TRACE] dag/walk: added new vertex: "import bitbucket_repository.test result: patrick_decat/test"
2017/08/25 17:26:11 [TRACE] dag/walk: walking "import bitbucket_repository.test result: patrick_decat/test"                       
2017/08/25 17:26:11 [TRACE] vertex 'root.import bitbucket_repository.test result: patrick_decat/test': walking
2017/08/25 17:26:11 [TRACE] vertex 'root.import bitbucket_repository.test result: patrick_decat/test': evaluating
2017/08/25 17:26:11 [TRACE] [walkImport] Entering eval tree: import bitbucket_repository.test result: patrick_decat/test
2017/08/25 17:26:11 [TRACE] root: eval: *terraform.EvalSequence      
2017/08/25 17:26:11 [TRACE] root: eval: *terraform.EvalGetProvider                                             
2017/08/25 17:26:11 [TRACE] root: eval: *terraform.EvalRefresh            
bitbucket_repository.test: Refreshing state... (ID: patrick_decat/test)                          
2017-08-25T17:26:11.869+0200 [DEBUG] plugin.terraform-provider-bitbucket: 2017/08/25 17:26:11 [DEBUG] Sending request to GET https://api.bitbucket.org/2.0/repositories/patrick_decat/test
2017-08-25T17:26:12.535+0200 [DEBUG] plugin.terraform-provider-bitbucket: 2017/08/25 17:26:12 [DEBUG] Resp: &{200 OK 200 HTTP/2.0 2 0 map[Vary:[Authorization Accept-Encoding] Strict-Transport-Security:[max-a

PS: the import command does not fail if the API resource does not exist because the read function does not fail in case of 404, it only tests for 200 to proceed. That probably also needs to be fixed.

m3gg3r commented 6 years ago

Some news on this pull-request?