Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Asm 3001 expand terraform commands - pending for renana #38

Draft
wants to merge 91 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
91 commits
Select commit Hold shift + click to select a range
b6432ce
add 2 commands to provider list
tuvia-akeyless Apr 25, 2022
e1ae705
resource gcp done
tuvia-akeyless Apr 26, 2022
652ca3a
fixed auto-rotate panic
tuvia-akeyless Apr 26, 2022
da99722
remove attempts to get no-get values
tuvia-akeyless Apr 26, 2022
d3c7bb7
resource rotated-secret done
tuvia-akeyless Apr 26, 2022
6f59ce2
clean up
tuvia-akeyless Apr 26, 2022
692a9d1
remove producer test - to upload in future
tuvia-akeyless Apr 26, 2022
ee5bb0a
version
tuvia-akeyless Apr 26, 2022
3a5eb1b
add skipped tests - fictive params
tuvia-akeyless Apr 26, 2022
cf267a2
docs generated
tuvia-akeyless Apr 27, 2022
20e5ce6
authentication-credentials instead of rotator-creds-type
tuvia-akeyless Apr 27, 2022
a5d08dd
fix test. done
tuvia-akeyless Apr 27, 2022
78a39a8
fix bugs & add updated fields
tuvia-akeyless Apr 28, 2022
dc8a8fd
fix rotated secret value conditions
tuvia-akeyless May 1, 2022
3b881b9
data source clean up
tuvia-akeyless May 1, 2022
c39d6ce
support producer-custom
tuvia-akeyless May 1, 2022
3f61c56
add test
tuvia-akeyless May 1, 2022
5cebd08
fixed generated lines
tuvia-akeyless May 1, 2022
2283037
improve tests
tuvia-akeyless May 1, 2022
46bd422
remove bin
tuvia-akeyless May 1, 2022
d13587e
fix rotator type reading
tuvia-akeyless May 1, 2022
ff965e0
docs
renanaAkeyless May 2, 2022
8d16440
classic key - test fails
tuvia-akeyless May 2, 2022
1f6e852
Merge branch 'ASM-2960-Terraform-fix-GCP-and-roteted-secret' of githu…
tuvia-akeyless May 2, 2022
1cb0721
classic key resource done
tuvia-akeyless May 3, 2022
d578d27
auth-method-cert with bug
tuvia-akeyless May 4, 2022
a5ac3f6
Merge branch 'master' into ASM-3001-expand-terraform-commands
tuvia-akeyless May 4, 2022
af7281e
inserted cert_data a valid value
tuvia-akeyless May 6, 2022
4420d6f
dockerhub target done
tuvia-akeyless May 8, 2022
7e3311a
auth-method-cert + producer-hanadb
tuvia-akeyless May 8, 2022
2f9eec8
dockerhub done and tested. hanadb in progress.
tuvia-akeyless May 9, 2022
9046d41
fix bugs
tuvia-akeyless May 9, 2022
8791395
dockerhub tested and done
tuvia-akeyless May 9, 2022
8c408f5
cert try to fix bug
tuvia-akeyless May 9, 2022
87b5175
support producer ldap. need to write test.
tuvia-akeyless May 10, 2022
e73a472
Merge branch 'master' into ASM-3001-expand-terraform-commands
tuvia-akeyless May 10, 2022
ff31202
support producer rabbitmq
tuvia-akeyless May 11, 2022
153c92b
remove revealed public key
tuvia-akeyless May 11, 2022
2f3c0d3
support ssh-certificate
tuvia-akeyless May 11, 2022
58b5fdd
Merge branch 'master' into ASM-3001-expand-terraform-commands
tuvia-akeyless May 11, 2022
4db1ec4
support get-pki-certificate
tuvia-akeyless May 12, 2022
dd12901
internal merge conflict
tuvia-akeyless May 12, 2022
f7bb94b
try to fix access-rules update
tuvia-akeyless May 12, 2022
b6cd59e
option 1 - care cert in terraform side
tuvia-akeyless May 19, 2022
b57d7ff
support: producer-snowflake, set-role-rule
tuvia-akeyless May 24, 2022
8912d94
support start-producer, stop-producer
tuvia-akeyless May 24, 2022
158dc27
clean up
tuvia-akeyless May 25, 2022
cea4423
fix dockerhub target braces
tuvia-akeyless May 25, 2022
e650e93
clean up + hana producer test
tuvia-akeyless May 25, 2022
8e74f0b
role test fixed (merge)
tuvia-akeyless May 25, 2022
cd0e0b2
delete exist items before
tuvia-akeyless May 25, 2022
7c3b9f8
resource role (merge)
tuvia-akeyless May 25, 2022
8ba04c0
skip rabbit test - until sdk update
tuvia-akeyless May 25, 2022
d372eed
assoc fix (merge)
tuvia-akeyless May 25, 2022
4dc77e6
remove all merge changes
tuvia-akeyless May 25, 2022
b47c2e9
solve conflict in role-test
tuvia-akeyless May 25, 2022
ec73127
added checks to test: set-role-rule
tuvia-akeyless May 25, 2022
5a6d18b
add check in test: producer start, stop
tuvia-akeyless May 25, 2022
97c4c25
test only in /terraform-tests/*
tuvia-akeyless May 25, 2022
abff92d
fix set-role-rule
tuvia-akeyless May 25, 2022
c0f5d25
added test for auth-method-ldap
tuvia-akeyless May 26, 2022
8f8680e
certificate updated from []int to string
tuvia-akeyless May 29, 2022
9c1355e
skip on create-auth-method-ldap
tuvia-akeyless May 29, 2022
70caffe
tests include auth-method-ldap
tuvia-akeyless May 29, 2022
835b4aa
fix after CR
tuvia-akeyless Jun 1, 2022
a82599b
Merge branch 'master' into ASM-3001-expand-terraform-commands
tuvia-akeyless Jun 1, 2022
c518b1d
solved conflicts
tuvia-akeyless Jun 1, 2022
cea5f74
version 1.1.8
tuvia-akeyless Jun 1, 2022
75f42bd
.
tuvia-akeyless Jun 1, 2022
22eb730
.
tuvia-akeyless Jun 1, 2022
a832156
Merge branch 'master' into ASM-3001-expand-terraform-commands
tuvia-akeyless Jun 2, 2022
a08b1ef
version 1.1.9
tuvia-akeyless Jun 2, 2022
c9b57fe
.
tuvia-akeyless Jun 2, 2022
9eaad76
parallel tests
tuvia-akeyless Jun 2, 2022
3042bf3
version
tuvia-akeyless Jun 2, 2022
d2f02d6
fix auth-method-cert
tuvia-akeyless Jun 2, 2022
4714d12
all parallel, unique names
tuvia-akeyless Jun 2, 2022
3333d8c
delete key before create
tuvia-akeyless Jun 2, 2022
6015cd8
rabbit producer updated
tuvia-akeyless Jun 2, 2022
fc3e108
skip on tests using gateway
tuvia-akeyless Jun 2, 2022
792d1ef
ldap - fix bugs, add test
tuvia-akeyless Jun 9, 2022
fd588dd
fixed bugs and checked all manually
tuvia-akeyless Jun 12, 2022
768f578
Merge branch 'master' into ASM-3001-expand-terraform-commands
tuvia-akeyless Aug 28, 2022
0cef2cc
auth-method-cert in separated pr
tuvia-akeyless Oct 30, 2022
8e4a379
version 1.1.14
tuvia-akeyless Oct 30, 2022
1738da3
Merge branch 'master' into ASM-3001-expand-terraform-commands
tuvia-akeyless Oct 30, 2022
52c18da
set-role-rule in develop
tuvia-akeyless Dec 22, 2022
ccf9b5f
move data source pki,ssh to other branch
tuvia-akeyless Jun 5, 2023
9ed9692
cleanup dfc changes and tests
tuvia-akeyless Jun 8, 2023
0f66dd4
Merge branch 'master' into ASM-3001-expand-terraform-commands
tuvia-akeyless Jun 8, 2023
354c7a0
update from master
tuvia-akeyless Jun 8, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ vendor
*.tfvars
akeyless/resource_producer1_test.go
akeyless/resource_auth_methods1_test.go
akeyless/resource_item1_test.go
akeyless/resource_target1_test.go
akeyless/resource_item1_test.go
26 changes: 17 additions & 9 deletions akeyless/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ func Provider() *schema.Provider {
//ConfigureFunc: configureProvider,
ConfigureContextFunc: configureProvider,
ResourcesMap: map[string]*schema.Resource{
"akeyless_classic_key": resourceClassicKey(),
"akeyless_dfc_key": resourceDfcKey(),
"akeyless_static_secret": resourceStaticSecret(),
"akeyless_pki_cert_issuer": resourcePKICertIssuer(),
Expand All @@ -132,33 +133,40 @@ func Provider() *schema.Provider {
"akeyless_auth_method_cert": resourceAuthMethodCert(),
"akeyless_auth_method_gcp": resourceAuthMethodGcp(),
"akeyless_auth_method_k8s": resourceAuthMethodK8s(),
"akeyless_auth_method_ldap": resourceAuthMethodLdap(),
"akeyless_auth_method_oauth2": resourceAuthMethodOauth2(),
"akeyless_auth_method_oidc": resourceAuthMethodOidc(),
"akeyless_auth_method_saml": resourceAuthMethodSaml(),
"akeyless_auth_method_universal_identity": resourceAuthMethodUniversalIdentity(),
"akeyless_role": resourceRole(),
"akeyless_producer_artifactory": resourceProducerArtifactory(),
"akeyless_producer_aws": resourceProducerAws(),
"akeyless_producer_azure": resourceProducerAzure(),
"akeyless_producer_cassandra": resourceProducerCassandra(),
"akeyless_producer_custom": resourceProducerCustom(),
"akeyless_producer_rdp": resourceProducerRdp(),
"akeyless_producer_dockerhub": resourceProducerDockerhub(),
"akeyless_producer_eks": resourceProducerEks(),
"akeyless_producer_gcp": resourceProducerGcp(),
"akeyless_producer_github": resourceProducerGithub(),
"akeyless_producer_gke": resourceProducerGke(),
"akeyless_producer_hanadb": resourceProducerHanadb(),
"akeyless_producer_k8s": resourceProducerK8s(),
"akeyless_producer_ldap": resourceProducerLdap(),
"akeyless_producer_mongo": resourceProducerMongo(),
"akeyless_producer_mssql": resourceProducerMssql(),
"akeyless_producer_mysql": resourceProducerMysql(),
"akeyless_producer_oracle": resourceProducerOracle(),
"akeyless_producer_postgres": resourceProducerPostgresql(),
"akeyless_producer_rabbitmq": resourceProducerRabbitmq(),
"akeyless_producer_rdp": resourceProducerRdp(),
"akeyless_producer_redshift": resourceProducerRedshift(),
"akeyless_producer_gcp": resourceProducerGcp(),
"akeyless_producer_gke": resourceProducerGke(),
"akeyless_producer_github": resourceProducerGithub(),
"akeyless_producer_eks": resourceProducerEks(),
"akeyless_producer_cassandra": resourceProducerCassandra(),
"akeyless_producer_azure": resourceProducerAzure(),
"akeyless_producer_artifactory": resourceProducerArtifactory(),
"akeyless_producer_k8s": resourceProducerK8s(),
"akeyless_producer_snowflake": resourceProducerSnowflake(),
"akeyless_rotated_secret": resourceRotatedSecret(),
"akeyless_target_artifactory": resourceArtifactoryTarget(),
"akeyless_target_aws": resourceAwsTarget(),
"akeyless_target_azure": resourceAzureTarget(),
"akeyless_target_db": resourceDbTarget(),
"akeyless_target_dockerhub": resourceDockerhubTarget(),
"akeyless_target_eks": resourceEksTarget(),
"akeyless_target_github": resourceGithubTarget(),
"akeyless_target_gke": resourceGkeTarget(),
Expand Down
298 changes: 298 additions & 0 deletions akeyless/resource_auth_method_ldap.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,298 @@
// generated fule
package akeyless

import (
"context"
"errors"
"fmt"
"net/http"
"strings"

"github.com/akeylesslabs/akeyless-go/v3"
"github.com/akeylesslabs/terraform-provider-akeyless/akeyless/common"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)

func resourceAuthMethodLdap() *schema.Resource {
return &schema.Resource{
Description: "LDAP Auth Method Resource",
Create: resourceAuthMethodLdapCreate,
Read: resourceAuthMethodLdapRead,
Update: resourceAuthMethodLdapUpdate,
Delete: resourceAuthMethodLdapDelete,
Importer: &schema.ResourceImporter{
State: resourceAuthMethodLdapImport,
},
Schema: map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Required: true,
Description: "Auth Method name",
ForceNew: true,
},
"access_expires": {
Type: schema.TypeInt,
Required: false,
Optional: true,
Description: "Access expiration date in Unix timestamp (select 0 for access without expiry date)",
Default: "0",
},
"bound_ips": {
Type: schema.TypeSet,
Required: false,
Optional: true,
Description: "A CIDR whitelist with the IPs that the access is restricted to",
Elem: &schema.Schema{Type: schema.TypeString},
},
"force_sub_claims": {
Type: schema.TypeBool,
Required: false,
Optional: true,
Description: "enforce role-association must include sub claims",
},
"jwt_ttl": {
Type: schema.TypeInt,
Required: false,
Optional: true,
Description: "creds expiration time in minutes. If not set, use default according to account settings (see get-account-settings)",
},
"public_key_data": {
Type: schema.TypeString,
Required: false,
Optional: true,
Description: "A public key generated for LDAP authentication method on Akeyless [RSA2048] in encoded in base 64 format",
},
"unique_identifier": {
Type: schema.TypeString,
Required: false,
Optional: true,
Description: "A unique identifier (ID) value should be configured for LDAP, OAuth2 and SAML authentication method types and is usually a value such as the email, username, or upn for example. Whenever a user logs in with a token, these authentication types issue a sub claim that contains details uniquely identifying that user. This sub claim includes a key containing the ID value that you configured, and is used to distinguish between different users from within the same organization.",
Default: "users",
},
},
}
}

func resourceAuthMethodLdapCreate(d *schema.ResourceData, m interface{}) error {

provider := m.(providerMeta)
client := *provider.client
token := *provider.token

var apiErr akeyless.GenericOpenAPIError
ctx := context.Background()
name := d.Get("name").(string)
accessExpires := d.Get("access_expires").(int)
boundIpsSet := d.Get("bound_ips").(*schema.Set)
boundIps := common.ExpandStringList(boundIpsSet.List())
forceSubClaims := d.Get("force_sub_claims").(bool)
jwtTtl := d.Get("jwt_ttl").(int)
publicKeyData := d.Get("public_key_data").(string)
uniqueIdentifier := d.Get("unique_identifier").(string)

body := akeyless.CreateAuthMethodLDAP{
Name: name,
Token: &token,
}
common.GetAkeylessPtr(&body.AccessExpires, accessExpires)
common.GetAkeylessPtr(&body.BoundIps, boundIps)
common.GetAkeylessPtr(&body.ForceSubClaims, forceSubClaims)
common.GetAkeylessPtr(&body.JwtTtl, jwtTtl)
common.GetAkeylessPtr(&body.PublicKeyData, publicKeyData)
common.GetAkeylessPtr(&body.UniqueIdentifier, uniqueIdentifier)

_, _, err := client.CreateAuthMethodLDAP(ctx).Body(body).Execute()
if err != nil {
if errors.As(err, &apiErr) {
return fmt.Errorf("can't create Secret: %v", string(apiErr.Body()))
}
return fmt.Errorf("can't create Secret: %v", err)
}

d.SetId(name)

return nil
}

func resourceAuthMethodLdapRead(d *schema.ResourceData, m interface{}) error {

provider := m.(providerMeta)
client := *provider.client
token := *provider.token

var apiErr akeyless.GenericOpenAPIError
ctx := context.Background()

path := d.Id()

body := akeyless.GetAuthMethod{
Name: path,
Token: &token,
}

rOut, res, err := client.GetAuthMethod(ctx).Body(body).Execute()
if err != nil {
if errors.As(err, &apiErr) {
if res.StatusCode == http.StatusNotFound {
// The resource was deleted outside of the current Terraform workspace, so invalidate this resource
d.SetId("")
return nil
}
return fmt.Errorf("can't value: %v", string(apiErr.Body()))
}
return fmt.Errorf("can't get value: %v", err)
}

if rOut.AccessInfo != nil {
accessInfo := *rOut.AccessInfo
if accessInfo.AccessExpires != nil {
err = d.Set("access_expires", *accessInfo.AccessExpires)
if err != nil {
return err
}
}
if accessInfo.ForceSubClaims != nil {
err = d.Set("force_sub_claims", *accessInfo.ForceSubClaims)
if err != nil {
return err
}
}
bodyAcc := akeyless.GetAccountSettings{
Token: &token,
}
rOutAcc, _, err := client.GetAccountSettings(ctx).Body(bodyAcc).Execute()
if err != nil {
if errors.As(err, &apiErr) {
if res.StatusCode == http.StatusNotFound {
// The resource was deleted outside of the current Terraform workspace, so invalidate this resource
d.SetId("")
return nil
}
return fmt.Errorf("can't get account settings: %v", string(apiErr.Body()))
}
return fmt.Errorf("can't get account settings: %v", err)
}
jwtDefault := *rOutAcc.SystemAccessCredsSettings.JwtTtlDefault
if accessInfo.JwtTtl != nil {
if *accessInfo.JwtTtl != jwtDefault || d.Get("jwt_ttl").(int) != 0 {
err = d.Set("jwt_ttl", *accessInfo.JwtTtl)
if err != nil {
return err
}
}
}
if accessInfo.LdapAccessRules.UniqueIdentifier != nil {
err = d.Set("unique_identifier", *accessInfo.LdapAccessRules.UniqueIdentifier)
if err != nil {
return err
}
}

if accessInfo.CidrWhitelist != nil && *accessInfo.CidrWhitelist != "" {
err = d.Set("bound_ips", strings.Split(*accessInfo.CidrWhitelist, ","))
if err != nil {
return err
}
}
if accessInfo.ApiKeyAccessRules != nil {
err = d.Set("public_key_data", *accessInfo.ApiKeyAccessRules)
if err != nil {
return err
}
}
}

d.SetId(path)

return nil
}

func resourceAuthMethodLdapUpdate(d *schema.ResourceData, m interface{}) error {

provider := m.(providerMeta)
client := *provider.client
token := *provider.token

var apiErr akeyless.GenericOpenAPIError
ctx := context.Background()

name := d.Get("name").(string)
accessExpires := d.Get("access_expires").(int)
boundIpsSet := d.Get("bound_ips").(*schema.Set)
boundIps := common.ExpandStringList(boundIpsSet.List())
forceSubClaims := d.Get("force_sub_claims").(bool)
jwtTtl := d.Get("jwt_ttl").(int)
publicKeyData := d.Get("public_key_data").(string)
uniqueIdentifier := d.Get("unique_identifier").(string)

body := akeyless.UpdateAuthMethodLDAP{
Name: name,
UniqueIdentifier: &uniqueIdentifier,
Token: &token,
}
common.GetAkeylessPtr(&body.AccessExpires, accessExpires)
common.GetAkeylessPtr(&body.BoundIps, boundIps)
common.GetAkeylessPtr(&body.ForceSubClaims, forceSubClaims)
common.GetAkeylessPtr(&body.JwtTtl, jwtTtl)
common.GetAkeylessPtr(&body.PublicKeyData, publicKeyData)

_, _, err := client.UpdateAuthMethodLDAP(ctx).Body(body).Execute()
if err != nil {
if errors.As(err, &apiErr) {
return fmt.Errorf("can't update : %v", string(apiErr.Body()))
}
return fmt.Errorf("can't update : %v", err)
}

d.SetId(name)

return nil
}

func resourceAuthMethodLdapDelete(d *schema.ResourceData, m interface{}) error {

provider := m.(providerMeta)
client := *provider.client
token := *provider.token

path := d.Id()

deleteItem := akeyless.DeleteAuthMethod{
Token: &token,
Name: path,
}

ctx := context.Background()
_, _, err := client.DeleteAuthMethod(ctx).Body(deleteItem).Execute()
if err != nil {
return err
}

return nil
}

func resourceAuthMethodLdapImport(d *schema.ResourceData, m interface{}) ([]*schema.ResourceData, error) {
provider := m.(providerMeta)
client := *provider.client
token := *provider.token

path := d.Id()

item := akeyless.GetAuthMethod{
Name: path,
Token: &token,
}

ctx := context.Background()
_, _, err := client.GetAuthMethod(ctx).Body(item).Execute()
if err != nil {
return nil, err
}

err = d.Set("name", path)
if err != nil {
return nil, err
}

return []*schema.ResourceData{d}, nil
}
Loading