Skip to content

Commit 662dbd6

Browse files
chore: migrate project and project tokens (#707)
Signed-off-by: Blake Pettersson <[email protected]>
1 parent a4cda13 commit 662dbd6

26 files changed

+3494
-2347
lines changed

argocd/provider.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,6 @@ var tokenMutexConfiguration = &sync.RWMutex{}
2020
// Used to handle concurrent access to ArgoCD clusters
2121
var tokenMutexClusters = &sync.RWMutex{}
2222

23-
// Used to handle concurrent access to each ArgoCD project
24-
var tokenMutexProjectMap = make(map[string]*sync.RWMutex, 0)
25-
2623
// Used to handle concurrent access to ArgoCD secrets
2724
var tokenMutexSecrets = &sync.RWMutex{}
2825

@@ -148,8 +145,6 @@ func Provider() *schema.Provider {
148145
"argocd_application": resourceArgoCDApplication(),
149146
"argocd_application_set": resourceArgoCDApplicationSet(),
150147
"argocd_cluster": resourceArgoCDCluster(),
151-
"argocd_project": resourceArgoCDProject(),
152-
"argocd_project_token": resourceArgoCDProjectToken(),
153148
},
154149
ConfigureContextFunc: func(ctx context.Context, d *schema.ResourceData) (interface{}, diag.Diagnostics) {
155150
config, diags := argoCDProviderConfigFromResourceData(ctx, d)

argocd/resource_argocd_account_token_test.go

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"time"
99

1010
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
11+
"github.com/hashicorp/terraform-plugin-testing/terraform"
1112
"github.com/stretchr/testify/assert"
1213
)
1314

@@ -241,3 +242,101 @@ resource "argocd_account_token" "renew_after" {
241242
}
242243
`, renewAfter)
243244
}
245+
246+
func testCheckTokenIssuedAt(resourceName string) resource.TestCheckFunc {
247+
return func(s *terraform.State) error {
248+
rs, ok := s.RootModule().Resources[resourceName]
249+
if !ok {
250+
return fmt.Errorf("not found: %s", resourceName)
251+
}
252+
253+
if rs.Primary.ID == "" {
254+
return fmt.Errorf("token ID is not set")
255+
}
256+
257+
_issuedAt, ok := rs.Primary.Attributes["issued_at"]
258+
if !ok {
259+
return fmt.Errorf("testCheckTokenIssuedAt: issued_at is not set")
260+
}
261+
262+
_, err := convertStringToInt64(_issuedAt)
263+
if err != nil {
264+
return fmt.Errorf("testCheckTokenIssuedAt: string attribute 'issued_at' stored in state cannot be converted to int64: %s", err)
265+
}
266+
267+
return nil
268+
}
269+
}
270+
271+
func testCheckTokenExpiresAt(resourceName string, expiresIn int64) resource.TestCheckFunc {
272+
return func(s *terraform.State) error {
273+
rs, ok := s.RootModule().Resources[resourceName]
274+
if !ok {
275+
return fmt.Errorf("not found: %s", resourceName)
276+
}
277+
278+
if rs.Primary.ID == "" {
279+
return fmt.Errorf("token ID is not set")
280+
}
281+
282+
_expiresAt, ok := rs.Primary.Attributes["expires_at"]
283+
if !ok {
284+
return fmt.Errorf("expires_at is not set")
285+
}
286+
287+
_issuedAt, ok := rs.Primary.Attributes["issued_at"]
288+
if !ok {
289+
return fmt.Errorf("testCheckTokenExpiresAt: issued_at is not set")
290+
}
291+
292+
expiresAt, err := convertStringToInt64(_expiresAt)
293+
if err != nil {
294+
return fmt.Errorf("testCheckTokenExpiresAt: string attribute 'expires_at' stored in state cannot be converted to int64: %s", err)
295+
}
296+
297+
issuedAt, err := convertStringToInt64(_issuedAt)
298+
if err != nil {
299+
return fmt.Errorf("testCheckTokenExpiresAt: string attribute 'issued_at' stored in state cannot be converted to int64: %s", err)
300+
}
301+
302+
if issuedAt+expiresIn != expiresAt {
303+
return fmt.Errorf("testCheckTokenExpiresAt: issuedAt + expiresIn != expiresAt : %d + %d != %d", issuedAt, expiresIn, expiresAt)
304+
}
305+
306+
return nil
307+
}
308+
}
309+
310+
func testTokenIssuedAtSet(name string, count int) resource.TestCheckFunc {
311+
return func(s *terraform.State) error {
312+
key := "issued_at"
313+
314+
for i := 0; i < count; i++ {
315+
ms := s.RootModule()
316+
_name := fmt.Sprintf("%s.%d", name, i)
317+
318+
rs, ok := ms.Resources[_name]
319+
if !ok {
320+
return fmt.Errorf("not found: %s in %s", _name, ms.Path)
321+
}
322+
323+
is := rs.Primary
324+
if is == nil {
325+
return fmt.Errorf("no primary instance: %s in %s", _name, ms.Path)
326+
}
327+
328+
if val, ok := is.Attributes[key]; !ok || val == "" {
329+
return fmt.Errorf("%s: Attribute '%s' expected to be set", _name, key)
330+
}
331+
}
332+
333+
return nil
334+
}
335+
}
336+
337+
func testDelay(seconds int) resource.TestCheckFunc {
338+
return func(s *terraform.State) error {
339+
time.Sleep(time.Duration(seconds) * time.Second)
340+
return nil
341+
}
342+
}

argocd/resource_argocd_application_set_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1049,8 +1049,8 @@ func TestAccArgoCDApplicationSet_CustomNamespace(t *testing.T) {
10491049
name := acctest.RandomWithPrefix("appset-ns")
10501050

10511051
resource.ParallelTest(t, resource.TestCase{
1052-
PreCheck: func() { testAccPreCheck(t); testAccPreCheckFeatureSupported(t, features.ApplicationSet) },
1053-
ProviderFactories: testAccProviders,
1052+
PreCheck: func() { testAccPreCheck(t); testAccPreCheckFeatureSupported(t, features.ApplicationSet) },
1053+
ProtoV6ProviderFactories: testAccProtoV6ProviderFactories,
10541054
Steps: []resource.TestStep{
10551055
{
10561056
Config: testAccArgoCDApplicationSetCustomNamespace(name),

argocd/resource_argocd_application_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1038,8 +1038,8 @@ func TestAccArgoCDApplication_CustomNamespace(t *testing.T) {
10381038
name := acctest.RandomWithPrefix("test-acc")
10391039

10401040
resource.ParallelTest(t, resource.TestCase{
1041-
PreCheck: func() { testAccPreCheck(t); testAccPreCheckFeatureSupported(t, features.ProjectSourceNamespaces) },
1042-
ProviderFactories: testAccProviders,
1041+
PreCheck: func() { testAccPreCheck(t); testAccPreCheckFeatureSupported(t, features.ProjectSourceNamespaces) },
1042+
ProtoV6ProviderFactories: testAccProtoV6ProviderFactories,
10431043
Steps: []resource.TestStep{
10441044
{
10451045
Config: testAccArgoCDApplicationCustomNamespace(name),

0 commit comments

Comments
 (0)