@@ -72,7 +72,6 @@ func resourceGitlabGroupLabelCreate(ctx context.Context, d *schema.ResourceData,
72
72
}
73
73
74
74
d .SetId (label .Name )
75
-
76
75
return resourceGitlabGroupLabelRead (ctx , d , meta )
77
76
}
78
77
@@ -82,27 +81,18 @@ func resourceGitlabGroupLabelRead(ctx context.Context, d *schema.ResourceData, m
82
81
labelName := d .Id ()
83
82
log .Printf ("[DEBUG] read gitlab group label %s/%s" , group , labelName )
84
83
85
- page := 1
86
- labelsLen := 0
87
- for page == 1 || labelsLen != 0 {
88
- labels , _ , err := client .GroupLabels .ListGroupLabels (group , & gitlab.ListGroupLabelsOptions {ListOptions : gitlab.ListOptions {Page : page }}, gitlab .WithContext (ctx ))
89
- if err != nil {
90
- return diag .FromErr (err )
91
- }
92
- for _ , label := range labels {
93
- if label .Name == labelName {
94
- d .Set ("description" , label .Description )
95
- d .Set ("color" , label .Color )
96
- d .Set ("name" , label .Name )
97
- return nil
98
- }
84
+ label , _ , err := client .GroupLabels .GetGroupLabel (group , labelName , gitlab .WithContext (ctx ))
85
+ if err != nil {
86
+ if is404 (err ) {
87
+ log .Printf ("[DEBUG] failed to read gitlab label %s/%s, removing from state" , group , labelName )
88
+ d .SetId ("" )
89
+ return nil
99
90
}
100
- labelsLen = len (labels )
101
- page = page + 1
91
+ return diag .FromErr (err )
102
92
}
103
-
104
- log . Printf ( "[DEBUG] failed to read gitlab label %s/%s " , group , labelName )
105
- d .SetId ( "" )
93
+ d . Set ( "description" , label . Description )
94
+ d . Set ( "color " , label . Color )
95
+ d .Set ( "name" , label . Name )
106
96
return nil
107
97
}
108
98
0 commit comments