Skip to content

Commit ac65e67

Browse files
authored
Add new resource argocd_account_token (#281)
* 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`
1 parent e369a6d commit ac65e67

File tree

12 files changed

+851
-11
lines changed

12 files changed

+851
-11
lines changed

GNUmakefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ test:
2828
go test -v -cover -timeout=120s -parallel=4 ./...
2929

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

3333
testacc_clean_env:
3434
kind delete cluster --name argocd

argocd/features.go

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,14 @@ import (
77

88
"github.com/Masterminds/semver"
99
"github.com/argoproj/argo-cd/v2/pkg/apiclient"
10+
"github.com/argoproj/argo-cd/v2/pkg/apiclient/account"
1011
"github.com/argoproj/argo-cd/v2/pkg/apiclient/application"
1112
"github.com/argoproj/argo-cd/v2/pkg/apiclient/certificate"
1213
"github.com/argoproj/argo-cd/v2/pkg/apiclient/cluster"
1314
"github.com/argoproj/argo-cd/v2/pkg/apiclient/project"
1415
"github.com/argoproj/argo-cd/v2/pkg/apiclient/repocreds"
1516
"github.com/argoproj/argo-cd/v2/pkg/apiclient/repository"
17+
"github.com/argoproj/argo-cd/v2/pkg/apiclient/session"
1618
"github.com/argoproj/argo-cd/v2/pkg/apiclient/version"
1719
"github.com/argoproj/argo-cd/v2/util/io"
1820
"github.com/golang/protobuf/ptypes/empty"
@@ -50,13 +52,16 @@ var featureVersionConstraintsMap = map[int]*semver.Version{
5052
}
5153

5254
type ServerInterface struct {
53-
ApiClient apiclient.Client
54-
ApplicationClient application.ApplicationServiceClient
55-
CertificateClient certificate.CertificateServiceClient
56-
ClusterClient cluster.ClusterServiceClient
57-
ProjectClient project.ProjectServiceClient
58-
RepositoryClient repository.RepositoryServiceClient
59-
RepoCredsClient repocreds.RepoCredsServiceClient
55+
AccountClient account.AccountServiceClient
56+
ApiClient apiclient.Client
57+
ApplicationClient application.ApplicationServiceClient
58+
CertificateClient certificate.CertificateServiceClient
59+
ClusterClient cluster.ClusterServiceClient
60+
ProjectClient project.ProjectServiceClient
61+
RepositoryClient repository.RepositoryServiceClient
62+
RepoCredsClient repocreds.RepoCredsServiceClient
63+
SessionClient session.SessionServiceClient
64+
6065
ServerVersion *semver.Version
6166
ServerVersionMessage *version.VersionMessage
6267
ProviderData *schema.ResourceData
@@ -84,6 +89,15 @@ func (p *ServerInterface) initClients(ctx context.Context) error {
8489
p.ApiClient = apiClient
8590
}
8691

92+
if p.AccountClient == nil {
93+
_, accountClient, err := p.ApiClient.NewAccountClient()
94+
if err != nil {
95+
return err
96+
}
97+
98+
p.AccountClient = accountClient
99+
}
100+
87101
if p.ClusterClient == nil {
88102
_, clusterClient, err := p.ApiClient.NewClusterClient()
89103
if err != nil {
@@ -138,6 +152,15 @@ func (p *ServerInterface) initClients(ctx context.Context) error {
138152
p.RepoCredsClient = repoCredsClient
139153
}
140154

155+
if p.SessionClient == nil {
156+
_, sessionClient, err := p.ApiClient.NewSessionClient()
157+
if err != nil {
158+
return err
159+
}
160+
161+
p.SessionClient = sessionClient
162+
}
163+
141164
acCloser, versionClient, err := p.ApiClient.NewVersionClient()
142165
if err != nil {
143166
return err

argocd/provider.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ var tokenMutexClusters = &sync.RWMutex{}
3333
// Used to handle concurrent access to each ArgoCD project
3434
var tokenMutexProjectMap = make(map[string]*sync.RWMutex, 0)
3535

36+
// Used to handle concurrent access to ArgoCD secrets
37+
var tokenMutexSecrets = &sync.RWMutex{}
38+
3639
var runtimeErrorHandlers []func(error)
3740

3841
func Provider() *schema.Provider {
@@ -219,6 +222,7 @@ func Provider() *schema.Provider {
219222
},
220223

221224
ResourcesMap: map[string]*schema.Resource{
225+
"argocd_account_token": resourceArgoCDAccountToken(),
222226
"argocd_application": resourceArgoCDApplication(),
223227
"argocd_repository_certificate": resourceArgoCDRepositoryCertificates(),
224228
"argocd_cluster": resourceArgoCDCluster(),

0 commit comments

Comments
 (0)