Skip to content

Commit 2dbefb5

Browse files
Extend valid resources for project-scoped role policy (#207)
* build(deps): bump argo-cd to v2.4.12 from v2.3.0 Support for `ksonnet` was dropped in ArgoCD 2.4. As such, this has been removed from the `argocd_application` resource in this provider as well. * tests: bump default Kubernetes version to `1.23.12` `1.19` is long past EOL so we should upgrade the default cluster version. I did consider `1.22` but as this is approaching EOL in 1 month (https://kubernetes.io/releases/), I figured we may as well jump straight to `1.23`. * tests: bump default ArgoCD version to `2.1.10` Aligns with the minimum version run by the GitHub Actions. * feat: extend valid resources for project-scope role policy Ensures that role policy can be provisioned for clusters, repositories, exec and logs. * build(deps): bump `go` to `1.17` from `1.16` Resolves following build error resulting from dependency updates: ``` ../../../go/pkg/mod/github.com/argoproj/argo-cd/[email protected]/pkg/apiclient/apiclient.go:53:2: //go:build comment without // +build comment ``` * build: bump `codeql` actions to `v2` Spotted a warning at https://github.com/oboukili/terraform-provider-argocd/actions/runs/3151063925/jobs/5124563560 and have upgraded as per https://github.blog/changelog/2022-04-27-code-scanning-deprecation-of-codeql-action-v1/ * build: drop tests for ArgoCD `2.1` and `2.2` Minimum supported version is now `2.3.x` as per ArgoCD itself. * tests: add tests for migration of application schema to v2 * chore: update scripts/testacc_prepare_env.sh Co-authored-by: Olivier Boukili <[email protected]> * refactor: use `rbacpolicy` for policy action/resource names Co-authored-by: Olivier Boukili <[email protected]>
1 parent 8d03743 commit 2dbefb5

16 files changed

+1111
-464
lines changed

.github/workflows/codeql-analysis.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ jobs:
4343

4444
# Initializes the CodeQL tools for scanning.
4545
- name: Initialize CodeQL
46-
uses: github/codeql-action/init@v1
46+
uses: github/codeql-action/init@v2
4747
with:
4848
languages: ${{ matrix.language }}
4949
# If you wish to specify custom queries, you can do so here or in a config file.
@@ -54,7 +54,7 @@ jobs:
5454
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
5555
# If this step fails, then you should remove it and run the build manually (see below)
5656
- name: Autobuild
57-
uses: github/codeql-action/autobuild@v1
57+
uses: github/codeql-action/autobuild@v2
5858

5959
# ℹ️ Command-line programs to run using the OS shell.
6060
# 📚 https://git.io/JvXDl
@@ -68,4 +68,4 @@ jobs:
6868
# make release
6969

7070
- name: Perform CodeQL Analysis
71-
uses: github/codeql-action/analyze@v1
71+
uses: github/codeql-action/analyze@v2

.github/workflows/release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ jobs:
1717
- name: Set up Go
1818
uses: actions/setup-go@v2
1919
with:
20-
go-version: 1.16
20+
go-version: 1.17
2121

2222
- name: Import GPG key
2323
id: import_gpg

.github/workflows/tests.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@ jobs:
1414
strategy:
1515
fail-fast: false
1616
matrix:
17-
argocd_version: ["v2.3.0", "v2.2.5", "v2.1.10"]
17+
argocd_version: ["v2.4.12", "v2.3.9"]
1818
steps:
1919
- uses: actions/checkout@v2
2020
- uses: actions/setup-go@v1
2121
with:
22-
go-version: 1.16
22+
go-version: 1.17
2323
id: go
2424
- name: Restore Go cache
2525
uses: actions/cache@v1

argocd/features.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,20 +28,20 @@ const (
2828
featureClusterMetadata
2929
featureRepositoryCertificates
3030
featureApplicationHelmSkipCrds
31+
featureExecLogsPolicy
3132
)
3233

33-
var (
34-
featureVersionConstraintsMap = map[int]*semver.Version{
35-
featureApplicationLevelSyncOptions: semver.MustParse("1.5.0"),
36-
featureIgnoreDiffJQPathExpressions: semver.MustParse("2.1.0"),
37-
featureRepositoryGet: semver.MustParse("1.6.0"),
38-
featureTokenIDs: semver.MustParse("1.5.3"),
39-
featureProjectScopedClusters: semver.MustParse("2.2.0"),
40-
featureClusterMetadata: semver.MustParse("2.2.0"),
41-
featureRepositoryCertificates: semver.MustParse("1.2.0"),
42-
featureApplicationHelmSkipCrds: semver.MustParse("2.3.0"),
43-
}
44-
)
34+
var featureVersionConstraintsMap = map[int]*semver.Version{
35+
featureApplicationLevelSyncOptions: semver.MustParse("1.5.0"),
36+
featureIgnoreDiffJQPathExpressions: semver.MustParse("2.1.0"),
37+
featureRepositoryGet: semver.MustParse("1.6.0"),
38+
featureTokenIDs: semver.MustParse("1.5.3"),
39+
featureProjectScopedClusters: semver.MustParse("2.2.0"),
40+
featureClusterMetadata: semver.MustParse("2.2.0"),
41+
featureRepositoryCertificates: semver.MustParse("1.2.0"),
42+
featureApplicationHelmSkipCrds: semver.MustParse("2.3.0"),
43+
featureExecLogsPolicy: semver.MustParse("2.4.0"),
44+
}
4545

4646
type ServerInterface struct {
4747
ApiClient *apiclient.Client

argocd/resource_argocd_application.go

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ func resourceArgoCDApplication() *schema.Resource {
2727
},
2828
Schema: map[string]*schema.Schema{
2929
"metadata": metadataSchema("applications.argoproj.io"),
30-
"spec": applicationSpecSchemaV1(),
30+
"spec": applicationSpecSchemaV2(),
3131
"wait": {
3232
Type: schema.TypeBool,
3333
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.",
@@ -41,13 +41,18 @@ func resourceArgoCDApplication() *schema.Resource {
4141
Default: true,
4242
},
4343
},
44-
SchemaVersion: 1,
44+
SchemaVersion: 2,
4545
StateUpgraders: []schema.StateUpgrader{
4646
{
4747
Type: resourceArgoCDApplicationV0().CoreConfigSchema().ImpliedType(),
4848
Upgrade: resourceArgoCDApplicationStateUpgradeV0,
4949
Version: 0,
5050
},
51+
{
52+
Type: resourceArgoCDApplicationV1().CoreConfigSchema().ImpliedType(),
53+
Upgrade: resourceArgoCDApplicationStateUpgradeV1,
54+
Version: 1,
55+
},
5156
},
5257
Timeouts: &schema.ResourceTimeout{
5358
Create: schema.DefaultTimeout(5 * time.Minute),
@@ -174,8 +179,7 @@ func resourceArgoCDApplicationCreate(ctx context.Context, d *schema.ResourceData
174179
}
175180

176181
app, err = c.Create(ctx, &applicationClient.ApplicationCreateRequest{
177-
Application: application.Application{
178-
182+
Application: &application.Application{
179183
ObjectMeta: objectMeta,
180184
Spec: spec,
181185
TypeMeta: metav1.TypeMeta{
@@ -299,7 +303,8 @@ func resourceArgoCDApplicationUpdate(ctx context.Context, d *schema.ResourceData
299303
Kind: "Application",
300304
APIVersion: "argoproj.io/v1alpha1",
301305
},
302-
}}
306+
},
307+
}
303308

304309
featureApplicationLevelSyncOptionsSupported, err := server.isFeatureSupported(featureApplicationLevelSyncOptions)
305310
if err != nil {

argocd/resource_argocd_cluster_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ func TestAccArgoCDCluster(t *testing.T) {
3434
resource.TestCheckResourceAttr(
3535
"argocd_cluster.simple",
3636
"info.0.server_version",
37-
"1.19",
37+
"1.23",
3838
),
3939
resource.TestCheckResourceAttr(
4040
"argocd_cluster.simple",
@@ -48,7 +48,7 @@ func TestAccArgoCDCluster(t *testing.T) {
4848
),
4949
),
5050
},
51-
//TODO: not working on CI every time
51+
// TODO: not working on CI every time
5252
// {
5353
// ResourceName: "argocd_cluster.simple",
5454
// ImportState: true,
@@ -66,7 +66,7 @@ func TestAccArgoCDCluster(t *testing.T) {
6666
resource.TestCheckResourceAttr(
6767
"argocd_cluster.tls",
6868
"info.0.server_version",
69-
"1.19",
69+
"1.23",
7070
),
7171
resource.TestCheckResourceAttr(
7272
"argocd_cluster.tls",
@@ -104,7 +104,7 @@ func TestAccArgoCDCluster_projectScope(t *testing.T) {
104104
),
105105
),
106106
},
107-
//TODO: not working on CI every time
107+
// TODO: not working on CI every time
108108
// {
109109
// ResourceName: "argocd_cluster.project_scope",
110110
// ImportState: true,

argocd/resource_argocd_project_test.go

Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,56 @@ func TestAccArgoCDProjectUpdateAddRole(t *testing.T) {
172172
})
173173
}
174174

175+
func TestAccArgoCDProjectWithClustersRepositoriesRolePolicy(t *testing.T) {
176+
name := acctest.RandomWithPrefix("test-acc")
177+
178+
resource.Test(t, resource.TestCase{
179+
PreCheck: func() { testAccPreCheck(t); testAccPreCheckFeatureSupported(t, featureProjectScopedClusters) },
180+
ProviderFactories: testAccProviders,
181+
Steps: []resource.TestStep{
182+
{
183+
Config: testAccArgoCDProjectWithClustersRepositoriesRolePolicy(name),
184+
Check: resource.ComposeTestCheckFunc(
185+
resource.TestCheckResourceAttrSet(
186+
"argocd_project.simple",
187+
"metadata.0.uid",
188+
),
189+
),
190+
},
191+
{
192+
ResourceName: "argocd_project.simple",
193+
ImportState: true,
194+
ImportStateVerify: true,
195+
},
196+
},
197+
})
198+
}
199+
200+
func TestAccArgoCDProjectWithLogsExecRolePolicy(t *testing.T) {
201+
name := acctest.RandomWithPrefix("test-acc")
202+
203+
resource.Test(t, resource.TestCase{
204+
PreCheck: func() { testAccPreCheck(t); testAccPreCheckFeatureSupported(t, featureExecLogsPolicy) },
205+
ProviderFactories: testAccProviders,
206+
Steps: []resource.TestStep{
207+
{
208+
Config: testAccArgoCDProjectWithExecLogsRolePolicy(name),
209+
Check: resource.ComposeTestCheckFunc(
210+
resource.TestCheckResourceAttrSet(
211+
"argocd_project.simple",
212+
"metadata.0.uid",
213+
),
214+
),
215+
},
216+
{
217+
ResourceName: "argocd_project.simple",
218+
ImportState: true,
219+
ImportStateVerify: true,
220+
},
221+
},
222+
})
223+
}
224+
175225
func testAccArgoCDProjectSimple(name string) string {
176226
return fmt.Sprintf(`
177227
resource "argocd_project" "simple" {
@@ -583,3 +633,87 @@ func testAccArgoCDProjectSimpleWithRole(name string) string {
583633
}
584634
`, name, name, name, name, name)
585635
}
636+
637+
func testAccArgoCDProjectWithClustersRepositoriesRolePolicy(name string) string {
638+
return fmt.Sprintf(`
639+
resource "argocd_project" "simple" {
640+
metadata {
641+
name = "%[1]s"
642+
namespace = "argocd"
643+
labels = {
644+
acceptance = "true"
645+
}
646+
annotations = {
647+
"this.is.a.really.long.nested.key" = "yes, really!"
648+
}
649+
}
650+
651+
spec {
652+
description = "simple project"
653+
source_repos = ["*"]
654+
655+
destination {
656+
name = "anothercluster"
657+
namespace = "bar"
658+
}
659+
orphaned_resources {
660+
warn = true
661+
ignore {
662+
group = "apps/v1"
663+
kind = "Deployment"
664+
name = "ignored1"
665+
}
666+
}
667+
role {
668+
name = "admin"
669+
policies = [
670+
"p, proj:%[1]s:admin, clusters, get, %[1]s/*, allow",
671+
"p, proj:%[1]s:admin, repositories, get, %[1]s/*, allow",
672+
]
673+
}
674+
}
675+
}
676+
`, name)
677+
}
678+
679+
func testAccArgoCDProjectWithExecLogsRolePolicy(name string) string {
680+
return fmt.Sprintf(`
681+
resource "argocd_project" "simple" {
682+
metadata {
683+
name = "%[1]s"
684+
namespace = "argocd"
685+
labels = {
686+
acceptance = "true"
687+
}
688+
annotations = {
689+
"this.is.a.really.long.nested.key" = "yes, really!"
690+
}
691+
}
692+
693+
spec {
694+
description = "simple project"
695+
source_repos = ["*"]
696+
697+
destination {
698+
name = "anothercluster"
699+
namespace = "bar"
700+
}
701+
orphaned_resources {
702+
warn = true
703+
ignore {
704+
group = "apps/v1"
705+
kind = "Deployment"
706+
name = "ignored1"
707+
}
708+
}
709+
role {
710+
name = "admin"
711+
policies = [
712+
"p, proj:%[1]s:admin, exec, create, %[1]s/*, allow",
713+
"p, proj:%[1]s:admin, logs, get, %[1]s/*, allow",
714+
]
715+
}
716+
}
717+
}
718+
`, name)
719+
}

0 commit comments

Comments
 (0)