Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use schema.TypeSet for application sync_policy #228

Merged
merged 5 commits into from
Jan 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion GNUmakefile
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ release: clean linux windows darwin freebsd
for f in $(shell ls bin/); do zip bin/$${f}.zip bin/$${f}; done

clean:
git clean -fXd -e \!vendor -e \!vendor/**/*
git clean -fXd -e \!vendor -e \!vendor/**/* -e \!.vscode

test: fmtcheck
go test $(TEST) -timeout=30s -parallel=4
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ resource "argocd_application" "kustomize" {
}

sync_policy {
automated = {
automated {
prune = true
self_heal = true
}
Expand Down
2 changes: 1 addition & 1 deletion argocd/provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,6 @@ func testAccPreCheckFeatureNotSupported(t *testing.T, feature int) {
t.Fatal("feature constraint is not handled by the provider")
}
if i := versionConstraint.Compare(serverVersion); i != 1 {
t.Skipf("not running test if feature is already supported (v%s)", v)
t.Skipf("not running test if feature is already supported (%s)", v)
}
}
9 changes: 7 additions & 2 deletions argocd/resource_argocd_application.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func resourceArgoCDApplication() *schema.Resource {
},
Schema: map[string]*schema.Schema{
"metadata": metadataSchema("applications.argoproj.io"),
"spec": applicationSpecSchemaV3(),
"spec": applicationSpecSchemaV4(),
"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.",
Expand All @@ -41,7 +41,7 @@ func resourceArgoCDApplication() *schema.Resource {
Default: true,
},
},
SchemaVersion: 3,
SchemaVersion: 4,
StateUpgraders: []schema.StateUpgrader{
{
Type: resourceArgoCDApplicationV0().CoreConfigSchema().ImpliedType(),
Expand All @@ -58,6 +58,11 @@ func resourceArgoCDApplication() *schema.Resource {
Upgrade: resourceArgoCDApplicationStateUpgradeV2,
Version: 2,
},
{
Type: resourceArgoCDApplicationV3().CoreConfigSchema().ImpliedType(),
Upgrade: resourceArgoCDApplicationStateUpgradeV3,
Version: 3,
},
},
Timeouts: &schema.ResourceTimeout{
Create: schema.DefaultTimeout(5 * time.Minute),
Expand Down
60 changes: 32 additions & 28 deletions argocd/resource_argocd_application_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,7 @@ ingress:
),
},
{
Config: testAccArgoCDApplicationSimpleWait(commonName),
ExpectNonEmptyPlan: true,
Config: testAccArgoCDApplicationSimpleWait(commonName),
Check: resource.TestCheckResourceAttr(
"argocd_application.simple",
"wait",
Expand Down Expand Up @@ -206,32 +205,32 @@ ingress:
),
resource.TestCheckResourceAttr(
"argocd_application.sync_policy",
"spec.0.sync_policy.0.automated.prune",
"spec.0.sync_policy.0.automated.0.prune",
"true",
),
resource.TestCheckResourceAttr(
"argocd_application.sync_policy",
"spec.0.sync_policy.0.automated.self_heal",
"spec.0.sync_policy.0.automated.0.self_heal",
"true",
),
resource.TestCheckResourceAttr(
"argocd_application.sync_policy",
"spec.0.sync_policy.0.automated.allow_empty",
"spec.0.sync_policy.0.automated.0.allow_empty",
"true",
),
resource.TestCheckResourceAttr(
"argocd_application.sync_policy",
"spec.0.sync_policy.0.retry.0.backoff.duration",
"spec.0.sync_policy.0.retry.0.backoff.0.duration",
"30s",
),
resource.TestCheckResourceAttr(
"argocd_application.sync_policy",
"spec.0.sync_policy.0.retry.0.backoff.max_duration",
"spec.0.sync_policy.0.retry.0.backoff.0.max_duration",
"2m",
),
resource.TestCheckResourceAttr(
"argocd_application.sync_policy",
"spec.0.sync_policy.0.retry.0.backoff.factor",
"spec.0.sync_policy.0.retry.0.backoff.0.factor",
"2",
),
resource.TestCheckResourceAttr(
Expand Down Expand Up @@ -332,11 +331,11 @@ func TestAccArgoCDApplication_NoSyncPolicyBlock(t *testing.T) {
),
resource.TestCheckNoResourceAttr(
"argocd_application.simple",
"spec.0.sync_policy.0.retry.0.backoff.duration",
"spec.0.sync_policy.0.retry.0.backoff.0.duration",
),
resource.TestCheckNoResourceAttr(
"argocd_application.simple",
"spec.0.sync_policy.0.automated.prune",
"spec.0.sync_policy.0.automated.0.prune",
),
),
},
Expand All @@ -361,7 +360,7 @@ func TestAccArgoCDApplication_Recurse(t *testing.T) {
),
resource.TestCheckNoResourceAttr(
"argocd_application.directory",
"spec.0.source.0.directory.0.jsonnet",
"spec.0.source.0.directory.0.jsonnet.0",
),
),
},
Expand Down Expand Up @@ -389,7 +388,7 @@ func TestAccArgoCDApplication_Recurse(t *testing.T) {
),
resource.TestCheckNoResourceAttr(
"argocd_application.directory",
"spec.0.source.0.directory.0.jsonnet",
"spec.0.source.0.directory.0.jsonnet.0",
),
),
},
Expand All @@ -403,7 +402,7 @@ func TestAccArgoCDApplication_Recurse(t *testing.T) {
),
resource.TestCheckNoResourceAttr(
"argocd_application.directory",
"spec.0.source.0.directory.0.jsonnet",
"spec.0.source.0.directory.0.jsonnet.0",
),
),
},
Expand All @@ -416,7 +415,7 @@ func TestAccArgoCDApplication_Recurse(t *testing.T) {
),
resource.TestCheckNoResourceAttr(
"argocd_application.directory",
"spec.0.source.0.directory.0.jsonnet",
"spec.0.source.0.directory.0.jsonnet.0",
),
),
},
Expand All @@ -438,11 +437,11 @@ func TestAccArgoCDApplication_EmptySyncPolicyBlock(t *testing.T) {
),
resource.TestCheckNoResourceAttr(
"argocd_application.simple",
"spec.0.sync_policy.0.retry.0.backoff.duration",
"spec.0.sync_policy.0.retry.0.backoff.0.duration",
),
resource.TestCheckNoResourceAttr(
"argocd_application.simple",
"spec.0.sync_policy.0.automated.prune",
"spec.0.sync_policy.0.automated.0.prune",
),
),
},
Expand All @@ -464,11 +463,11 @@ func TestAccArgoCDApplication_NoAutomatedBlock(t *testing.T) {
),
resource.TestCheckResourceAttrSet(
"argocd_application.simple",
"spec.0.sync_policy.0.retry.0.backoff.duration",
"spec.0.sync_policy.0.retry.0.backoff.0.duration",
),
resource.TestCheckNoResourceAttr(
"argocd_application.simple",
"spec.0.sync_policy.0.automated.prune",
"spec.0.sync_policy.0.automated.0.prune",
),
),
},
Expand All @@ -488,9 +487,13 @@ func TestAccArgoCDApplication_EmptyAutomatedBlock(t *testing.T) {
"argocd_application.simple",
"metadata.0.uid",
),
resource.TestCheckResourceAttrSet(
"argocd_application.simple",
"spec.0.sync_policy.0.automated.#",
),
resource.TestCheckNoResourceAttr(
"argocd_application.simple",
"spec.0.sync_policy.0.automated.prune",
"spec.0.sync_policy.0.automated.0.prune",
),
),
},
Expand Down Expand Up @@ -645,7 +648,7 @@ func TestAccArgoCDApplication_Info(t *testing.T) {
),
resource.TestCheckNoResourceAttr(
"argocd_application.info",
"spec.0.info",
"spec.0.info.0",
),
),
},
Expand All @@ -659,7 +662,7 @@ func TestAccArgoCDApplication_Info(t *testing.T) {
),
resource.TestCheckNoResourceAttr(
"argocd_application.info",
"spec.0.info",
"spec.0.info.0",
),
),
},
Expand Down Expand Up @@ -908,9 +911,10 @@ resource "argocd_application" "simple" {
}
}
sync_policy {
automated = {
prune = true
self_heal = true
automated {
prune = true
self_heal = true
allow_empty = false
}
}
destination {
Expand Down Expand Up @@ -1210,14 +1214,14 @@ resource "argocd_application" "sync_policy" {
}

sync_policy {
automated = {
automated {
prune = true
self_heal = true
allow_empty = true
}
retry {
limit = "5"
backoff = {
backoff {
duration = "30s"
max_duration = "2m"
factor = "2"
Expand Down Expand Up @@ -1386,7 +1390,7 @@ resource "argocd_application" "simple" {
sync_policy {
retry {
limit = "5"
backoff = {
backoff {
duration = "30s"
max_duration = "2m"
factor = "2"
Expand Down Expand Up @@ -1419,7 +1423,7 @@ resource "argocd_application" "simple" {
}
}
sync_policy {
automated = {}
automated {}
}
destination {
server = "https://kubernetes.default.svc"
Expand Down
4 changes: 2 additions & 2 deletions argocd/resource_argocd_cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ func TestAccArgoCDCluster_metadata(t *testing.T) {
Check: resource.ComposeTestCheckFunc(
resource.TestCheckNoResourceAttr(
"argocd_cluster.cluster_metadata",
"metadata",
"metadata.0",
),
),
},
Expand Down Expand Up @@ -253,7 +253,7 @@ func TestAccArgoCDCluster_metadata(t *testing.T) {
Check: resource.ComposeTestCheckFunc(
resource.TestCheckNoResourceAttr(
"argocd_cluster.cluster_metadata",
"metadata.0.labels",
"metadata.0.labels.test",
),
resource.TestCheckResourceAttr(
"argocd_cluster.cluster_metadata",
Expand Down
Loading