Skip to content

Commit

Permalink
Add new resource argocd_account_token (#281)
Browse files Browse the repository at this point in the history
* tests: run `TestAccArgoCDProjectToken_Renew*` in serial

Since these tests are time sensitive we don't want steps/checks running in parallel since this causes flakiness as the token may need to be renewed by the time Terraform checks that the apply results in a subsequent non-empty plan.

* build: extend timeout for acceptance tests

* feat: new resource `argocd_account_token`
  • Loading branch information
onematchfox authored May 24, 2023
1 parent e369a6d commit ac65e67
Show file tree
Hide file tree
Showing 12 changed files with 851 additions and 11 deletions.
2 changes: 1 addition & 1 deletion GNUmakefile
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ test:
go test -v -cover -timeout=120s -parallel=4 ./...

testacc:
TF_ACC=1 go test -v -cover -timeout 8m ./...
TF_ACC=1 go test -v -cover -timeout 10m ./...

testacc_clean_env:
kind delete cluster --name argocd
Expand Down
37 changes: 30 additions & 7 deletions argocd/features.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@ import (

"github.com/Masterminds/semver"
"github.com/argoproj/argo-cd/v2/pkg/apiclient"
"github.com/argoproj/argo-cd/v2/pkg/apiclient/account"
"github.com/argoproj/argo-cd/v2/pkg/apiclient/application"
"github.com/argoproj/argo-cd/v2/pkg/apiclient/certificate"
"github.com/argoproj/argo-cd/v2/pkg/apiclient/cluster"
"github.com/argoproj/argo-cd/v2/pkg/apiclient/project"
"github.com/argoproj/argo-cd/v2/pkg/apiclient/repocreds"
"github.com/argoproj/argo-cd/v2/pkg/apiclient/repository"
"github.com/argoproj/argo-cd/v2/pkg/apiclient/session"
"github.com/argoproj/argo-cd/v2/pkg/apiclient/version"
"github.com/argoproj/argo-cd/v2/util/io"
"github.com/golang/protobuf/ptypes/empty"
Expand Down Expand Up @@ -50,13 +52,16 @@ var featureVersionConstraintsMap = map[int]*semver.Version{
}

type ServerInterface struct {
ApiClient apiclient.Client
ApplicationClient application.ApplicationServiceClient
CertificateClient certificate.CertificateServiceClient
ClusterClient cluster.ClusterServiceClient
ProjectClient project.ProjectServiceClient
RepositoryClient repository.RepositoryServiceClient
RepoCredsClient repocreds.RepoCredsServiceClient
AccountClient account.AccountServiceClient
ApiClient apiclient.Client
ApplicationClient application.ApplicationServiceClient
CertificateClient certificate.CertificateServiceClient
ClusterClient cluster.ClusterServiceClient
ProjectClient project.ProjectServiceClient
RepositoryClient repository.RepositoryServiceClient
RepoCredsClient repocreds.RepoCredsServiceClient
SessionClient session.SessionServiceClient

ServerVersion *semver.Version
ServerVersionMessage *version.VersionMessage
ProviderData *schema.ResourceData
Expand Down Expand Up @@ -84,6 +89,15 @@ func (p *ServerInterface) initClients(ctx context.Context) error {
p.ApiClient = apiClient
}

if p.AccountClient == nil {
_, accountClient, err := p.ApiClient.NewAccountClient()
if err != nil {
return err
}

p.AccountClient = accountClient
}

if p.ClusterClient == nil {
_, clusterClient, err := p.ApiClient.NewClusterClient()
if err != nil {
Expand Down Expand Up @@ -138,6 +152,15 @@ func (p *ServerInterface) initClients(ctx context.Context) error {
p.RepoCredsClient = repoCredsClient
}

if p.SessionClient == nil {
_, sessionClient, err := p.ApiClient.NewSessionClient()
if err != nil {
return err
}

p.SessionClient = sessionClient
}

acCloser, versionClient, err := p.ApiClient.NewVersionClient()
if err != nil {
return err
Expand Down
4 changes: 4 additions & 0 deletions argocd/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ var tokenMutexClusters = &sync.RWMutex{}
// Used to handle concurrent access to each ArgoCD project
var tokenMutexProjectMap = make(map[string]*sync.RWMutex, 0)

// Used to handle concurrent access to ArgoCD secrets
var tokenMutexSecrets = &sync.RWMutex{}

var runtimeErrorHandlers []func(error)

func Provider() *schema.Provider {
Expand Down Expand Up @@ -219,6 +222,7 @@ func Provider() *schema.Provider {
},

ResourcesMap: map[string]*schema.Resource{
"argocd_account_token": resourceArgoCDAccountToken(),
"argocd_application": resourceArgoCDApplication(),
"argocd_repository_certificate": resourceArgoCDRepositoryCertificates(),
"argocd_cluster": resourceArgoCDCluster(),
Expand Down
Loading

0 comments on commit ac65e67

Please sign in to comment.