Skip to content

Commit

Permalink
Add new resource argocd_application_set (#278)
Browse files Browse the repository at this point in the history
Co-authored-by: Olivier Boukili <[email protected]>
  • Loading branch information
onematchfox and oboukili authored May 25, 2023
1 parent 38a00f8 commit f5c1dce
Show file tree
Hide file tree
Showing 22 changed files with 21,445 additions and 98 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ jobs:
strategy:
fail-fast: false
matrix:
argocd_version: ["v2.5.0", "v2.5.16", "v2.6.0", "v2.6.7", "v2.7.1"]
argocd_version: ["v2.5.0", "v2.5.16", "v2.6.0", "v2.6.7", "v2.7.3"]
steps:
- name: Check out code
uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c # v3.3.0
Expand Down
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 10m ./...
TF_ACC=1 go test -v -cover -timeout 15m ./...

testacc_clean_env:
kind delete cluster --name argocd
Expand Down
57 changes: 36 additions & 21 deletions argocd/features.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"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/applicationset"
"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"
Expand All @@ -34,33 +35,38 @@ const (
featureExecLogsPolicy
featureProjectSourceNamespaces
featureMultipleApplicationSources
featureApplicationSet
featureApplicationSetProgressiveSync
)

var featureVersionConstraintsMap = map[int]*semver.Version{
featureApplicationLevelSyncOptions: semver.MustParse("1.5.0"),
featureIgnoreDiffJQPathExpressions: semver.MustParse("2.1.0"),
featureRepositoryGet: semver.MustParse("1.6.0"),
featureTokenIDs: semver.MustParse("1.5.3"),
featureProjectScopedClusters: semver.MustParse("2.2.0"),
featureProjectScopedRepositories: semver.MustParse("2.2.0"),
featureClusterMetadata: semver.MustParse("2.2.0"),
featureRepositoryCertificates: semver.MustParse("1.2.0"),
featureApplicationHelmSkipCrds: semver.MustParse("2.3.0"),
featureExecLogsPolicy: semver.MustParse("2.4.4"),
featureProjectSourceNamespaces: semver.MustParse("2.5.0"),
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
featureApplicationLevelSyncOptions: semver.MustParse("1.5.0"),
featureIgnoreDiffJQPathExpressions: semver.MustParse("2.1.0"),
featureRepositoryGet: semver.MustParse("1.6.0"),
featureTokenIDs: semver.MustParse("1.5.3"),
featureProjectScopedClusters: semver.MustParse("2.2.0"),
featureProjectScopedRepositories: semver.MustParse("2.2.0"),
featureClusterMetadata: semver.MustParse("2.2.0"),
featureRepositoryCertificates: semver.MustParse("1.2.0"),
featureApplicationHelmSkipCrds: semver.MustParse("2.3.0"),
featureExecLogsPolicy: semver.MustParse("2.4.4"),
featureProjectSourceNamespaces: semver.MustParse("2.5.0"),
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
featureApplicationSet: semver.MustParse("2.5.0"),
featureApplicationSetProgressiveSync: semver.MustParse("2.6.0"),
}

type ServerInterface struct {
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
AccountClient account.AccountServiceClient
ApiClient apiclient.Client
ApplicationClient application.ApplicationServiceClient
ApplicationSetClient applicationset.ApplicationSetServiceClient
CertificateClient certificate.CertificateServiceClient
ClusterClient cluster.ClusterServiceClient
ProjectClient project.ProjectServiceClient
RepositoryClient repository.RepositoryServiceClient
RepoCredsClient repocreds.RepoCredsServiceClient
SessionClient session.SessionServiceClient

ServerVersion *semver.Version
ServerVersionMessage *version.VersionMessage
Expand Down Expand Up @@ -125,6 +131,15 @@ func (p *ServerInterface) initClients(ctx context.Context) error {
p.ApplicationClient = applicationClient
}

if p.ApplicationSetClient == nil {
_, applicationSetClient, err := (p.ApiClient).NewApplicationSetClient()
if err != nil {
return err
}

p.ApplicationSetClient = applicationSetClient
}

if p.ProjectClient == nil {
_, projectClient, err := p.ApiClient.NewProjectClient()
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions argocd/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ func Provider() *schema.Provider {
ResourcesMap: map[string]*schema.Resource{
"argocd_account_token": resourceArgoCDAccountToken(),
"argocd_application": resourceArgoCDApplication(),
"argocd_application_set": resourceArgoCDApplicationSet(),
"argocd_repository_certificate": resourceArgoCDRepositoryCertificates(),
"argocd_cluster": resourceArgoCDCluster(),
"argocd_project": resourceArgoCDProject(),
Expand Down
38 changes: 25 additions & 13 deletions argocd/resource_argocd_application.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func resourceArgoCDApplication() *schema.Resource {
},
Schema: map[string]*schema.Schema{
"metadata": metadataSchema("applications.argoproj.io"),
"spec": applicationSpecSchemaV4(),
"spec": applicationSpecSchemaV4(false),
"wait": {
Type: schema.TypeBool,
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`.",
Expand Down Expand Up @@ -74,9 +74,15 @@ func resourceArgoCDApplication() *schema.Resource {
}

func resourceArgoCDApplicationCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
objectMeta, spec, diags := expandApplication(d)
if diags != nil {
return diags
objectMeta, spec, err := expandApplication(d)
if err != nil {
return []diag.Diagnostic{
{
Severity: diag.Error,
Summary: fmt.Sprintf("application %s could not be created", objectMeta.Name),
Detail: err.Error(),
},
}
}

si := meta.(*ServerInterface)
Expand Down Expand Up @@ -383,9 +389,21 @@ func resourceArgoCDApplicationUpdate(ctx context.Context, d *schema.ResourceData
}
}

objectMeta, spec, diags := expandApplication(d)
if diags != nil {
return diags
ids := strings.Split(d.Id(), ":")
appQuery := &applicationClient.ApplicationQuery{
Name: &ids[0],
AppNamespace: &ids[1],
}

objectMeta, spec, err := expandApplication(d)
if err != nil {
return []diag.Diagnostic{
{
Severity: diag.Error,
Summary: fmt.Sprintf("application %s could not be updated", *appQuery.Name),
Detail: err.Error(),
},
}
}

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

ids := strings.Split(d.Id(), ":")
appQuery := &applicationClient.ApplicationQuery{
Name: &ids[0],
AppNamespace: &ids[1],
}

apps, err := si.ApplicationClient.List(ctx, appQuery)
if err != nil {
return []diag.Diagnostic{
Expand Down
Loading

0 comments on commit f5c1dce

Please sign in to comment.