@@ -21,26 +21,28 @@ var (
2121 _ resource.ResourceWithImportState = & aclMappingResource {}
2222)
2323
24- func NewAclMappingResource () resource.Resource {
25- return & aclMappingResource {}
26- }
24+ type (
25+ aclMappingResource struct {
26+ client * dtrack.Client
27+ semver * Semver
28+ }
2729
28- type aclMappingResource struct {
29- client * dtrack.Client
30- semver * Semver
31- }
30+ aclMappingResourceModel struct {
31+ ID types.String `tfsdk:"id"`
32+ Team types.String `tfsdk:"team"`
33+ Project types.String `tfsdk:"project"`
34+ }
35+ )
3236
33- type aclMappingResourceModel struct {
34- ID types.String `tfsdk:"id"`
35- Team types.String `tfsdk:"team"`
36- Project types.String `tfsdk:"project"`
37+ func NewACLMappingResource () resource.Resource {
38+ return & aclMappingResource {}
3739}
3840
39- func (r * aclMappingResource ) Metadata (_ context.Context , req resource.MetadataRequest , resp * resource.MetadataResponse ) {
41+ func (* aclMappingResource ) Metadata (_ context.Context , req resource.MetadataRequest , resp * resource.MetadataResponse ) {
4042 resp .TypeName = req .ProviderTypeName + "_acl_mapping"
4143}
4244
43- func (r * aclMappingResource ) Schema (_ context.Context , _ resource.SchemaRequest , resp * resource.SchemaResponse ) {
45+ func (* aclMappingResource ) Schema (_ context.Context , _ resource.SchemaRequest , resp * resource.SchemaResponse ) {
4446 resp .Schema = schema.Schema {
4547 Description : "Manages an ACL mapping to grant a Team access to a Project" ,
4648 Attributes : map [string ]schema.Attribute {
@@ -124,19 +126,19 @@ func (r *aclMappingResource) Create(ctx context.Context, req resource.CreateRequ
124126}
125127
126128func (r * aclMappingResource ) Read (ctx context.Context , req resource.ReadRequest , resp * resource.ReadResponse ) {
127- // Fetch state
129+ // Fetch state.
128130 var state aclMappingResourceModel
129131 diags := req .State .Get (ctx , & state )
130132 resp .Diagnostics .Append (diags ... )
131133 if resp .Diagnostics .HasError () {
132134 return
133135 }
134- // Refresh
135- team , diag := TryParseUUID (state .Team , LifecycleRead , path .Root ("team" ))
136+ // Refresh.
137+ teamID , diag := TryParseUUID (state .Team , LifecycleRead , path .Root ("team" ))
136138 if diag != nil {
137139 resp .Diagnostics .Append (diag )
138140 }
139- projectId , diag := TryParseUUID (state .Project , LifecycleRead , path .Root ("project" ))
141+ projectID , diag := TryParseUUID (state .Project , LifecycleRead , path .Root ("project" ))
140142 if diag != nil {
141143 resp .Diagnostics .Append (diag )
142144 }
@@ -146,29 +148,29 @@ func (r *aclMappingResource) Read(ctx context.Context, req resource.ReadRequest,
146148
147149 tflog .Debug (ctx , "Reading Project ACL Mapping" , map [string ]any {
148150 "id" : state .ID .ValueString (),
149- "team" : team .String (),
150- "project" : projectId .String (),
151+ "team" : teamID .String (),
152+ "project" : projectID .String (),
151153 })
152154 project , err := FindPaged (func (po dtrack.PageOptions ) (dtrack.Page [dtrack.Project ], error ) {
153- return r .client .ACL .GetAllProjects (ctx , team , po )
155+ return r .client .ACL .GetAllProjects (ctx , teamID , po )
154156 }, func (project dtrack.Project ) bool {
155- return project .UUID == projectId
157+ return project .UUID == projectID
156158 })
157159
158160 if err != nil {
159161 resp .Diagnostics .AddError (
160162 "Unable to get ACL mapping within Read" ,
161- "Error with reading acl mapping for team: " + team .String ()+ ", and project: " + projectId .String ()+ ", in original error: " + err .Error (),
163+ "Error with reading acl mapping for team: " + teamID .String ()+ ", and project: " + projectID .String ()+ ", in original error: " + err .Error (),
162164 )
163165 return
164166 }
165167 state = aclMappingResourceModel {
166- ID : types .StringValue (fmt .Sprintf ("%s/%s" , team .String (), project .UUID .String ())),
167- Team : types .StringValue (team .String ()),
168+ ID : types .StringValue (fmt .Sprintf ("%s/%s" , teamID .String (), project .UUID .String ())),
169+ Team : types .StringValue (teamID .String ()),
168170 Project : types .StringValue (project .UUID .String ()),
169171 }
170172
171- // Update state
173+ // Update state.
172174 diags = resp .State .Set (ctx , & state )
173175 resp .Diagnostics .Append (diags ... )
174176 if resp .Diagnostics .HasError () {
@@ -181,9 +183,9 @@ func (r *aclMappingResource) Read(ctx context.Context, req resource.ReadRequest,
181183 })
182184}
183185
184- func (r * aclMappingResource ) Update (ctx context.Context , req resource.UpdateRequest , resp * resource.UpdateResponse ) {
185- // Nothing to Update. This resource only has Create, Delete actions
186- // Get State
186+ func (* aclMappingResource ) Update (ctx context.Context , req resource.UpdateRequest , resp * resource.UpdateResponse ) {
187+ // Nothing to Update. This resource only has Create, Delete actions.
188+ // Get State.
187189 var plan aclMappingResourceModel
188190 diags := req .Plan .Get (ctx , & plan )
189191 resp .Diagnostics .Append (diags ... )
@@ -209,7 +211,7 @@ func (r *aclMappingResource) Update(ctx context.Context, req resource.UpdateRequ
209211 Project : types .StringValue (project .String ()),
210212 }
211213
212- // Update State
214+ // Update State.
213215 diags = resp .State .Set (ctx , plan )
214216 resp .Diagnostics .Append (diags ... )
215217 if resp .Diagnostics .HasError () {
@@ -223,15 +225,15 @@ func (r *aclMappingResource) Update(ctx context.Context, req resource.UpdateRequ
223225}
224226
225227func (r * aclMappingResource ) Delete (ctx context.Context , req resource.DeleteRequest , resp * resource.DeleteResponse ) {
226- // Load state
228+ // Load state.
227229 var state aclMappingResourceModel
228230 diags := req .State .Get (ctx , & state )
229231 resp .Diagnostics .Append (diags ... )
230232 if resp .Diagnostics .HasError () {
231233 return
232234 }
233235
234- // Map TF to SDK
236+ // Map TF to SDK.
235237 team , diag := TryParseUUID (state .Team , LifecycleDelete , path .Root ("team" ))
236238 if diag != nil {
237239 resp .Diagnostics .Append (diag )
@@ -244,7 +246,7 @@ func (r *aclMappingResource) Delete(ctx context.Context, req resource.DeleteRequ
244246 return
245247 }
246248
247- // Execute
249+ // Execute.
248250 tflog .Debug (ctx , "Deleting Project ACL Mapping" , map [string ]any {
249251 "id" : state .ID .ValueString (),
250252 "team" : team .String (),
@@ -265,7 +267,7 @@ func (r *aclMappingResource) Delete(ctx context.Context, req resource.DeleteRequ
265267 })
266268}
267269
268- func (r * aclMappingResource ) ImportState (ctx context.Context , req resource.ImportStateRequest , resp * resource.ImportStateResponse ) {
270+ func (* aclMappingResource ) ImportState (ctx context.Context , req resource.ImportStateRequest , resp * resource.ImportStateResponse ) {
269271 idParts := strings .Split (req .ID , "/" )
270272 if len (idParts ) != 2 || idParts [0 ] == "" || idParts [1 ] == "" {
271273 resp .Diagnostics .AddError (
@@ -274,28 +276,28 @@ func (r *aclMappingResource) ImportState(ctx context.Context, req resource.Impor
274276 )
275277 return
276278 }
277- teamIdString := idParts [0 ]
278- projectIdString := idParts [1 ]
279+ teamIDString := idParts [0 ]
280+ projectIDString := idParts [1 ]
279281 tflog .Debug (ctx , "Importing Project ACL Mapping" , map [string ]any {
280- "team" : teamIdString ,
281- "project" : projectIdString ,
282+ "team" : teamIDString ,
283+ "project" : projectIDString ,
282284 })
283285
284- teamId , diag := TryParseUUID (types .StringValue (teamIdString ), LifecycleImport , path .Root ("team" ))
286+ teamID , diag := TryParseUUID (types .StringValue (teamIDString ), LifecycleImport , path .Root ("team" ))
285287 if diag != nil {
286288 resp .Diagnostics .Append (diag )
287289 }
288- projectId , diag := TryParseUUID (types .StringValue (projectIdString ), LifecycleImport , path .Root ("project" ))
290+ projectID , diag := TryParseUUID (types .StringValue (projectIDString ), LifecycleImport , path .Root ("project" ))
289291 if diag != nil {
290292 resp .Diagnostics .Append (diag )
291293 }
292294 if resp .Diagnostics .HasError () {
293295 return
294296 }
295297 aclMappingState := aclMappingResourceModel {
296- ID : types .StringValue (fmt .Sprintf ("%s/%s" , teamId .String (), projectId .String ())),
297- Team : types .StringValue (teamId .String ()),
298- Project : types .StringValue (projectId .String ()),
298+ ID : types .StringValue (fmt .Sprintf ("%s/%s" , teamID .String (), projectID .String ())),
299+ Team : types .StringValue (teamID .String ()),
300+ Project : types .StringValue (projectID .String ()),
299301 }
300302 diags := resp .State .Set (ctx , aclMappingState )
301303 resp .Diagnostics .Append (diags ... )
@@ -313,7 +315,7 @@ func (r *aclMappingResource) Configure(_ context.Context, req resource.Configure
313315 if req .ProviderData == nil {
314316 return
315317 }
316- clientInfo , ok := req .ProviderData .(clientInfo )
318+ clientInfoData , ok := req .ProviderData .(clientInfo )
317319
318320 if ! ok {
319321 resp .Diagnostics .AddError (
@@ -322,6 +324,6 @@ func (r *aclMappingResource) Configure(_ context.Context, req resource.Configure
322324 )
323325 return
324326 }
325- r .client = clientInfo .client
326- r .semver = clientInfo .semver
327+ r .client = clientInfoData .client
328+ r .semver = clientInfoData .semver
327329}
0 commit comments