-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feat: add Support for K8s Credentials (#847)
* Feat: add Support for K8s Credentials * add azure aks * added gcp gke * add update operation
- Loading branch information
1 parent
d3efb20
commit 7595cfd
Showing
14 changed files
with
1,043 additions
and
23 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
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 resourceAwsEksCredentials() *schema.Resource { | ||
return &schema.Resource{ | ||
CreateContext: resourceAwsEksCredentialsCreate, | ||
UpdateContext: resourceAwsEksCredentialsUpdate, | ||
ReadContext: resourceCredentialsRead(AWS_EKS_TYPE), | ||
DeleteContext: resourceCredentialsDelete, | ||
|
||
Importer: &schema.ResourceImporter{StateContext: resourceCredentialsImport(AWS_EKS_TYPE)}, | ||
|
||
Schema: map[string]*schema.Schema{ | ||
"name": { | ||
Type: schema.TypeString, | ||
Description: "name for the credentials", | ||
Required: true, | ||
ForceNew: true, | ||
}, | ||
"cluster_name": { | ||
Type: schema.TypeString, | ||
Description: "eks cluster name", | ||
Required: true, | ||
}, | ||
"cluster_region": { | ||
Type: schema.TypeString, | ||
Description: "the AWS region of the eks cluster", | ||
Required: true, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func resourceAwsEksCredentialsCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { | ||
value := client.AwsEksValue{} | ||
if err := readResourceData(&value, d); err != nil { | ||
return diag.Errorf("schema resource data deserialization failed: %v", err) | ||
} | ||
|
||
apiClient := meta.(client.ApiClientInterface) | ||
|
||
request := client.KubernetesCredentialsCreatePayload{ | ||
Name: d.Get("name").(string), | ||
Value: value, | ||
Type: client.AwsEksCredentialsType, | ||
} | ||
|
||
credentials, err := apiClient.KubernetesCredentialsCreate(&request) | ||
if err != nil { | ||
return diag.Errorf("could not create credentials: %v", err) | ||
} | ||
|
||
d.SetId(credentials.Id) | ||
|
||
return nil | ||
} | ||
|
||
func resourceAwsEksCredentialsUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { | ||
value := client.AwsEksValue{} | ||
if err := readResourceData(&value, d); err != nil { | ||
return diag.Errorf("schema resource data deserialization failed: %v", err) | ||
} | ||
|
||
apiClient := meta.(client.ApiClientInterface) | ||
|
||
request := client.KubernetesCredentialsUpdatePayload{ | ||
Value: value, | ||
Type: client.AwsEksCredentialsType, | ||
} | ||
|
||
if _, err := apiClient.KubernetesCredentialsUpdate(d.Id(), &request); err != nil { | ||
return diag.Errorf("could not create credentials: %v", err) | ||
} | ||
|
||
return nil | ||
} |
Oops, something went wrong.