-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix: env0_aws_credentials - apply after import will delete+create (#371)
* Fix: env0_aws_credentials - apply after import will delete+create * improvements based on CR comments
- Loading branch information
1 parent
e02675e
commit f488f56
Showing
18 changed files
with
261 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package client | ||
|
||
type NotFoundError struct{} | ||
|
||
func (e *NotFoundError) Error() string { | ||
return "not found" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package env0 | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
"strings" | ||
|
||
"github.com/env0/terraform-provider-env0/client" | ||
"github.com/google/uuid" | ||
) | ||
|
||
func getCredentialsByName(name string, prefix string, meta interface{}) (client.Credentials, error) { | ||
apiClient := meta.(client.ApiClientInterface) | ||
|
||
credentialsList, err := apiClient.CloudCredentialsList() | ||
if err != nil { | ||
return client.Credentials{}, err | ||
} | ||
|
||
var foundCredentials []client.Credentials | ||
for _, credentials := range credentialsList { | ||
if credentials.Name == name && strings.HasPrefix(credentials.Type, prefix) { | ||
foundCredentials = append(foundCredentials, credentials) | ||
} | ||
} | ||
|
||
if len(foundCredentials) == 0 { | ||
return client.Credentials{}, fmt.Errorf("credentials with name %v not found", name) | ||
} | ||
|
||
if len(foundCredentials) > 1 { | ||
return client.Credentials{}, fmt.Errorf("found multiple credentials with name: %s. Use id instead or make sure credential names are unique %v", name, foundCredentials) | ||
} | ||
|
||
return foundCredentials[0], nil | ||
} | ||
|
||
func getCredentials(id string, prefix string, meta interface{}) (client.Credentials, error) { | ||
_, err := uuid.Parse(id) | ||
if err == nil { | ||
log.Println("[INFO] Resolving credentials by id: ", id) | ||
return meta.(client.ApiClientInterface).CloudCredentials(id) | ||
} else { | ||
log.Println("[INFO] Resolving credentials by name: ", id) | ||
return getCredentialsByName(id, prefix, meta) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.