-
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.
* Feat: Add azure credentials * Update docs * added resource and tests ( removed import from gcp ) * Update docs * missing argument test * removed aws credentials import * added example and IT * Update docs * added & fix client tests * pr-comments removed cloud credentials data * pr-comments sensitive * pr-comments data * Update docs * Revert "pr-comments data" This reverts commit d46d1de. * Revert "pr-comments removed cloud credentials data" This reverts commit 0f20b41. * Update docs Co-authored-by: update generated docs action <[email protected]>
- Loading branch information
1 parent
223efb3
commit dd8a54d
Showing
21 changed files
with
639 additions
and
65 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
--- | ||
# generated by https://github.com/hashicorp/terraform-plugin-docs | ||
page_title: "env0_azure_credentials Data Source - terraform-provider-env0" | ||
subcategory: "" | ||
description: |- | ||
--- | ||
|
||
# env0_azure_credentials (Data Source) | ||
|
||
|
||
|
||
|
||
|
||
<!-- schema generated by tfplugindocs --> | ||
## Schema | ||
|
||
### Optional | ||
|
||
- **id** (String) the id of the credential | ||
- **name** (String) the name of the credential | ||
|
||
|
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,40 @@ | ||
--- | ||
# generated by https://github.com/hashicorp/terraform-plugin-docs | ||
page_title: "env0_azure_credentials Resource - terraform-provider-env0" | ||
subcategory: "" | ||
description: |- | ||
--- | ||
|
||
# env0_azure_credentials (Resource) | ||
|
||
|
||
|
||
## Example Usage | ||
|
||
```terraform | ||
resource "env0_azure_credentials" "credentials" { | ||
name = "name" | ||
client_id = "client_id" | ||
client_secret = "client_secret" | ||
subscription_id = "subscription_id" | ||
tenant_id = "tenant_id" | ||
} | ||
``` | ||
|
||
<!-- schema generated by tfplugindocs --> | ||
## Schema | ||
|
||
### Required | ||
|
||
- **client_id** (String) the azure client id | ||
- **client_secret** (String, Sensitive) the azure client secret | ||
- **name** (String) name for the credentials | ||
- **subscription_id** (String) the azure subscription id | ||
- **tenant_id** (String) the azure tenant id | ||
|
||
### Optional | ||
|
||
- **id** (String) The ID of this resource. | ||
|
||
|
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,93 @@ | ||
package env0 | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/env0/terraform-provider-env0/client" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/diag" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||
) | ||
|
||
func dataAzureCredentials() *schema.Resource { | ||
return &schema.Resource{ | ||
ReadContext: dataAzureCredentialsRead, | ||
|
||
Schema: map[string]*schema.Schema{ | ||
"name": { | ||
Type: schema.TypeString, | ||
Description: "the name of the credential", | ||
Optional: true, | ||
ExactlyOneOf: []string{"name", "id"}, | ||
}, | ||
"id": { | ||
Type: schema.TypeString, | ||
Description: "the id of the credential", | ||
Optional: true, | ||
ExactlyOneOf: []string{"name", "id"}, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func dataAzureCredentialsRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { | ||
var err diag.Diagnostics | ||
var credentials client.ApiKey | ||
|
||
id, ok := d.GetOk("id") | ||
if ok { | ||
credentials, err = getAzureCredentialsById(id.(string), meta) | ||
if err != nil { | ||
return err | ||
} | ||
} else { | ||
name, _ := d.Get("name").(string) // name must be specified here | ||
credentials, err = getAzureCredentialsByName(name, meta) | ||
if err != nil { | ||
return err | ||
} | ||
} | ||
|
||
d.SetId(credentials.Id) | ||
d.Set("name", credentials.Name) | ||
|
||
return nil | ||
} | ||
|
||
func getAzureCredentialsByName(name interface{}, meta interface{}) (client.ApiKey, diag.Diagnostics) { | ||
apiClient := meta.(client.ApiClientInterface) | ||
credentialsList, err := apiClient.CloudCredentialsList() | ||
if err != nil { | ||
return client.ApiKey{}, diag.Errorf("Could not query Azure Credentials by name: %v", err) | ||
} | ||
|
||
credentialsByNameAndType := make([]client.ApiKey, 0) | ||
for _, candidate := range credentialsList { | ||
if candidate.Name == name.(string) && isValidAzureCredentialsType(candidate.Type) { | ||
credentialsByNameAndType = append(credentialsByNameAndType, candidate) | ||
} | ||
} | ||
|
||
if len(credentialsByNameAndType) > 1 { | ||
return client.ApiKey{}, diag.Errorf("Found multiple Azure Credentials for name: %s", name) | ||
} | ||
if len(credentialsByNameAndType) == 0 { | ||
return client.ApiKey{}, diag.Errorf("Could not find Azure Credentials with name: %s", name) | ||
} | ||
return credentialsByNameAndType[0], nil | ||
} | ||
|
||
func getAzureCredentialsById(id string, meta interface{}) (client.ApiKey, diag.Diagnostics) { | ||
apiClient := meta.(client.ApiClientInterface) | ||
credentials, err := apiClient.CloudCredentials(id) | ||
if !isValidAzureCredentialsType(credentials.Type) { | ||
return client.ApiKey{}, diag.Errorf("Found credentials which are not Azure Credentials: %v", credentials) | ||
} | ||
if err != nil { | ||
return client.ApiKey{}, diag.Errorf("Could not query Azure Credentials: %v", err) | ||
} | ||
return credentials, nil | ||
} | ||
|
||
func isValidAzureCredentialsType(credentialsType string) bool { | ||
return client.AzureCredentialsType(credentialsType) == client.AzureServicePrincipalCredentialsType | ||
} |
Oops, something went wrong.