Skip to content

Commit f5c1dce

Browse files
Add new resource argocd_application_set (#278)
Co-authored-by: Olivier Boukili <[email protected]>
1 parent 38a00f8 commit f5c1dce

22 files changed

+21445
-98
lines changed

.github/workflows/tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ jobs:
4848
strategy:
4949
fail-fast: false
5050
matrix:
51-
argocd_version: ["v2.5.0", "v2.5.16", "v2.6.0", "v2.6.7", "v2.7.1"]
51+
argocd_version: ["v2.5.0", "v2.5.16", "v2.6.0", "v2.6.7", "v2.7.3"]
5252
steps:
5353
- name: Check out code
5454
uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c # v3.3.0

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 10m ./...
31+
TF_ACC=1 go test -v -cover -timeout 15m ./...
3232

3333
testacc_clean_env:
3434
kind delete cluster --name argocd

argocd/features.go

Lines changed: 36 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"github.com/argoproj/argo-cd/v2/pkg/apiclient"
1010
"github.com/argoproj/argo-cd/v2/pkg/apiclient/account"
1111
"github.com/argoproj/argo-cd/v2/pkg/apiclient/application"
12+
"github.com/argoproj/argo-cd/v2/pkg/apiclient/applicationset"
1213
"github.com/argoproj/argo-cd/v2/pkg/apiclient/certificate"
1314
"github.com/argoproj/argo-cd/v2/pkg/apiclient/cluster"
1415
"github.com/argoproj/argo-cd/v2/pkg/apiclient/project"
@@ -34,33 +35,38 @@ const (
3435
featureExecLogsPolicy
3536
featureProjectSourceNamespaces
3637
featureMultipleApplicationSources
38+
featureApplicationSet
39+
featureApplicationSetProgressiveSync
3740
)
3841

3942
var featureVersionConstraintsMap = map[int]*semver.Version{
40-
featureApplicationLevelSyncOptions: semver.MustParse("1.5.0"),
41-
featureIgnoreDiffJQPathExpressions: semver.MustParse("2.1.0"),
42-
featureRepositoryGet: semver.MustParse("1.6.0"),
43-
featureTokenIDs: semver.MustParse("1.5.3"),
44-
featureProjectScopedClusters: semver.MustParse("2.2.0"),
45-
featureProjectScopedRepositories: semver.MustParse("2.2.0"),
46-
featureClusterMetadata: semver.MustParse("2.2.0"),
47-
featureRepositoryCertificates: semver.MustParse("1.2.0"),
48-
featureApplicationHelmSkipCrds: semver.MustParse("2.3.0"),
49-
featureExecLogsPolicy: semver.MustParse("2.4.4"),
50-
featureProjectSourceNamespaces: semver.MustParse("2.5.0"),
51-
featureMultipleApplicationSources: semver.MustParse("2.6.3"), // Whilst the feature was introduced in 2.6.0 there was a bug that affects refresh of applications (and hence `wait` within this provider) that was only fixed in https://github.com/argoproj/argo-cd/pull/12576
43+
featureApplicationLevelSyncOptions: semver.MustParse("1.5.0"),
44+
featureIgnoreDiffJQPathExpressions: semver.MustParse("2.1.0"),
45+
featureRepositoryGet: semver.MustParse("1.6.0"),
46+
featureTokenIDs: semver.MustParse("1.5.3"),
47+
featureProjectScopedClusters: semver.MustParse("2.2.0"),
48+
featureProjectScopedRepositories: semver.MustParse("2.2.0"),
49+
featureClusterMetadata: semver.MustParse("2.2.0"),
50+
featureRepositoryCertificates: semver.MustParse("1.2.0"),
51+
featureApplicationHelmSkipCrds: semver.MustParse("2.3.0"),
52+
featureExecLogsPolicy: semver.MustParse("2.4.4"),
53+
featureProjectSourceNamespaces: semver.MustParse("2.5.0"),
54+
featureMultipleApplicationSources: semver.MustParse("2.6.3"), // Whilst the feature was introduced in 2.6.0 there was a bug that affects refresh of applications (and hence `wait` within this provider) that was only fixed in https://github.com/argoproj/argo-cd/pull/12576
55+
featureApplicationSet: semver.MustParse("2.5.0"),
56+
featureApplicationSetProgressiveSync: semver.MustParse("2.6.0"),
5257
}
5358

5459
type ServerInterface struct {
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
60+
AccountClient account.AccountServiceClient
61+
ApiClient apiclient.Client
62+
ApplicationClient application.ApplicationServiceClient
63+
ApplicationSetClient applicationset.ApplicationSetServiceClient
64+
CertificateClient certificate.CertificateServiceClient
65+
ClusterClient cluster.ClusterServiceClient
66+
ProjectClient project.ProjectServiceClient
67+
RepositoryClient repository.RepositoryServiceClient
68+
RepoCredsClient repocreds.RepoCredsServiceClient
69+
SessionClient session.SessionServiceClient
6470

6571
ServerVersion *semver.Version
6672
ServerVersionMessage *version.VersionMessage
@@ -125,6 +131,15 @@ func (p *ServerInterface) initClients(ctx context.Context) error {
125131
p.ApplicationClient = applicationClient
126132
}
127133

134+
if p.ApplicationSetClient == nil {
135+
_, applicationSetClient, err := (p.ApiClient).NewApplicationSetClient()
136+
if err != nil {
137+
return err
138+
}
139+
140+
p.ApplicationSetClient = applicationSetClient
141+
}
142+
128143
if p.ProjectClient == nil {
129144
_, projectClient, err := p.ApiClient.NewProjectClient()
130145
if err != nil {

argocd/provider.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,7 @@ func Provider() *schema.Provider {
224224
ResourcesMap: map[string]*schema.Resource{
225225
"argocd_account_token": resourceArgoCDAccountToken(),
226226
"argocd_application": resourceArgoCDApplication(),
227+
"argocd_application_set": resourceArgoCDApplicationSet(),
227228
"argocd_repository_certificate": resourceArgoCDRepositoryCertificates(),
228229
"argocd_cluster": resourceArgoCDCluster(),
229230
"argocd_project": resourceArgoCDProject(),

argocd/resource_argocd_application.go

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ func resourceArgoCDApplication() *schema.Resource {
2828
},
2929
Schema: map[string]*schema.Schema{
3030
"metadata": metadataSchema("applications.argoproj.io"),
31-
"spec": applicationSpecSchemaV4(),
31+
"spec": applicationSpecSchemaV4(false),
3232
"wait": {
3333
Type: schema.TypeBool,
3434
Description: "Upon application creation or update, wait for application health/sync status to be healthy/Synced, upon application deletion, wait for application to be removed, when set to true. Wait timeouts are controlled by Terraform Create, Update and Delete resource timeouts (all default to 5 minutes). **Note**: if ArgoCD decides not to sync an application (e.g. because the project to which the application belongs has a `sync_window` applied) then you will experience an expected timeout event if `wait = true`.",
@@ -74,9 +74,15 @@ func resourceArgoCDApplication() *schema.Resource {
7474
}
7575

7676
func resourceArgoCDApplicationCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
77-
objectMeta, spec, diags := expandApplication(d)
78-
if diags != nil {
79-
return diags
77+
objectMeta, spec, err := expandApplication(d)
78+
if err != nil {
79+
return []diag.Diagnostic{
80+
{
81+
Severity: diag.Error,
82+
Summary: fmt.Sprintf("application %s could not be created", objectMeta.Name),
83+
Detail: err.Error(),
84+
},
85+
}
8086
}
8187

8288
si := meta.(*ServerInterface)
@@ -383,9 +389,21 @@ func resourceArgoCDApplicationUpdate(ctx context.Context, d *schema.ResourceData
383389
}
384390
}
385391

386-
objectMeta, spec, diags := expandApplication(d)
387-
if diags != nil {
388-
return diags
392+
ids := strings.Split(d.Id(), ":")
393+
appQuery := &applicationClient.ApplicationQuery{
394+
Name: &ids[0],
395+
AppNamespace: &ids[1],
396+
}
397+
398+
objectMeta, spec, err := expandApplication(d)
399+
if err != nil {
400+
return []diag.Diagnostic{
401+
{
402+
Severity: diag.Error,
403+
Summary: fmt.Sprintf("application %s could not be updated", *appQuery.Name),
404+
Detail: err.Error(),
405+
},
406+
}
389407
}
390408

391409
featureApplicationLevelSyncOptionsSupported, err := si.isFeatureSupported(featureApplicationLevelSyncOptions)
@@ -494,12 +512,6 @@ func resourceArgoCDApplicationUpdate(ctx context.Context, d *schema.ResourceData
494512
}
495513
}
496514

497-
ids := strings.Split(d.Id(), ":")
498-
appQuery := &applicationClient.ApplicationQuery{
499-
Name: &ids[0],
500-
AppNamespace: &ids[1],
501-
}
502-
503515
apps, err := si.ApplicationClient.List(ctx, appQuery)
504516
if err != nil {
505517
return []diag.Diagnostic{

0 commit comments

Comments
 (0)