Skip to content
This repository has been archived by the owner on Dec 8, 2020. It is now read-only.

Fix repository resource importability #7

Merged
merged 1 commit into from
Nov 7, 2017

Conversation

pdecat
Copy link
Contributor

@pdecat pdecat commented Aug 25, 2017

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.

@radeksimko radeksimko added the bug label Aug 31, 2017
@m3gg3r
Copy link

m3gg3r commented Oct 4, 2017

Some news on this pull-request?

@pdecat pdecat force-pushed the fix_import_repository branch from 46766ed to c758202 Compare October 5, 2017 10:21
@cwood cwood merged commit dbb3d7f into hashicorp:master Nov 7, 2017
@pdecat pdecat deleted the fix_import_repository branch November 7, 2017 22:50
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants