Skip to content

Commit fa86a9b

Browse files
authored
Add support for multiple application sources (#262)
1 parent 60b7ad0 commit fa86a9b

File tree

9 files changed

+585
-318
lines changed

9 files changed

+585
-318
lines changed

argocd/features.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ const (
3131
featureApplicationHelmSkipCrds
3232
featureExecLogsPolicy
3333
featureProjectSourceNamespaces
34+
featureMultipleApplicationSources
3435
)
3536

3637
var featureVersionConstraintsMap = map[int]*semver.Version{
@@ -45,6 +46,7 @@ var featureVersionConstraintsMap = map[int]*semver.Version{
4546
featureApplicationHelmSkipCrds: semver.MustParse("2.3.0"),
4647
featureExecLogsPolicy: semver.MustParse("2.4.4"),
4748
featureProjectSourceNamespaces: semver.MustParse("2.5.0"),
49+
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
4850
}
4951

5052
type ServerInterface struct {

argocd/provider_test.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
package argocd
22

33
import (
4+
"fmt"
45
"os"
56
"testing"
67

78
"github.com/Masterminds/semver"
9+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest"
10+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
811
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
912
)
1013

@@ -26,6 +29,26 @@ func TestProvider(t *testing.T) {
2629
}
2730
}
2831

32+
func TestProvider_headers(t *testing.T) {
33+
t.Parallel()
34+
35+
resource.Test(t, resource.TestCase{
36+
PreCheck: func() { testAccPreCheck(t) },
37+
ProviderFactories: testAccProviders,
38+
Steps: []resource.TestStep{
39+
{
40+
Config: fmt.Sprintf("%s %s", `
41+
provider "argocd" {
42+
headers = [
43+
"Hello: HiThere",
44+
]
45+
}`, testAccArgoCDApplicationSimple(acctest.RandomWithPrefix("test-acc"), "9.4.1", false),
46+
),
47+
},
48+
},
49+
})
50+
}
51+
2952
func testAccPreCheck(t *testing.T) {
3053
if v := os.Getenv("ARGOCD_AUTH_USERNAME"); v == "" {
3154
t.Fatal("ARGOCD_AUTH_USERNAME must be set for acceptance tests")

argocd/resource_argocd_application.go

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,31 @@ func resourceArgoCDApplicationCreate(ctx context.Context, d *schema.ResourceData
181181
}
182182
}
183183

184+
featureMultipleApplicationSourcesSupported, err := si.isFeatureSupported(featureMultipleApplicationSources)
185+
if err != nil {
186+
return []diag.Diagnostic{
187+
{
188+
Severity: diag.Error,
189+
Summary: "feature not supported",
190+
Detail: err.Error(),
191+
},
192+
}
193+
} else if !featureMultipleApplicationSourcesSupported {
194+
if len(spec.Sources) > 1 {
195+
return []diag.Diagnostic{
196+
{
197+
Severity: diag.Error,
198+
Summary: fmt.Sprintf(
199+
"multiple application sources is only supported from ArgoCD %s onwards",
200+
featureVersionConstraintsMap[featureMultipleApplicationSources].String()),
201+
},
202+
}
203+
}
204+
205+
spec.Source = &spec.Sources[0]
206+
spec.Sources = nil
207+
}
208+
184209
featureApplicationHelmSkipCrdsSupported, err := si.isFeatureSupported(featureApplicationHelmSkipCrds)
185210
if err != nil {
186211
return []diag.Diagnostic{
@@ -410,6 +435,31 @@ func resourceArgoCDApplicationUpdate(ctx context.Context, d *schema.ResourceData
410435
}
411436
}
412437

438+
featureMultipleApplicationSourcesSupported, err := si.isFeatureSupported(featureMultipleApplicationSources)
439+
if err != nil {
440+
return []diag.Diagnostic{
441+
{
442+
Severity: diag.Error,
443+
Summary: "feature not supported",
444+
Detail: err.Error(),
445+
},
446+
}
447+
} else if !featureMultipleApplicationSourcesSupported {
448+
if len(spec.Sources) > 1 {
449+
return []diag.Diagnostic{
450+
{
451+
Severity: diag.Error,
452+
Summary: fmt.Sprintf(
453+
"multiple application sources is only supported from ArgoCD %s onwards",
454+
featureVersionConstraintsMap[featureMultipleApplicationSources].String()),
455+
},
456+
}
457+
}
458+
459+
spec.Source = &spec.Sources[0]
460+
spec.Sources = nil
461+
}
462+
413463
featureApplicationHelmSkipCrdsSupported, err := si.isFeatureSupported(featureApplicationHelmSkipCrds)
414464
if err != nil {
415465
return []diag.Diagnostic{

0 commit comments

Comments
 (0)