Skip to content

Commit 20d5bdc

Browse files
committed
clean up comments
1 parent e6625c9 commit 20d5bdc

File tree

5 files changed

+12
-37
lines changed

5 files changed

+12
-37
lines changed

internal/provider/provider_test.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,22 +82,21 @@ func muxedProvidersWithDefaultOrganization(defaultOrgName string) map[string]fun
8282
"tfe": func() (tfprotov6.ProviderServer, error) {
8383
ctx := context.Background()
8484

85-
// Framework provider with Protocol 6
8685
nextProvider := providerserver.NewProtocol6(NewFrameworkProviderWithDefaultOrg(defaultOrgName))
8786

88-
// SDK provider upgraded to Protocol 6
8987
sdkProvider := Provider()
9088
sdkProvider.ConfigureContextFunc = func(ctx context.Context, rd *schema.ResourceData) (interface{}, diag.Diagnostics) {
9189
client, err := getClientUsingEnv()
9290
cc := ConfiguredClient{
9391
Client: client,
9492
Organization: defaultOrgName,
9593
}
94+
95+
// Save a reference to the configured client instance for use in tests.
9696
testAccConfiguredClient = &cc
9797
return cc, diag.FromErr(err)
9898
}
9999

100-
// Explicitly upgrade the SDK provider to Protocol 6
101100
upgradedSDKProvider, err := tf5to6server.UpgradeServer(
102101
ctx,
103102
sdkProvider.GRPCProvider,
@@ -106,7 +105,6 @@ func muxedProvidersWithDefaultOrganization(defaultOrgName string) map[string]fun
106105
return nil, err
107106
}
108107

109-
// Create mux with both providers using Protocol 6
110108
mux, err := tf6muxserver.NewMuxServer(
111109
ctx,
112110
[]func() tfprotov6.ProviderServer{

internal/provider/resource_tfe_opa_version.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ var (
2424
_ resource.Resource = &OPAVersionResource{}
2525
_ resource.ResourceWithConfigure = &OPAVersionResource{}
2626
_ resource.ResourceWithImportState = &OPAVersionResource{}
27-
// _ resource.ResourceWithValidateConfig = &OPAVersionResource{}
2827
)
2928

3029
type OPAVersionResource struct {
@@ -121,8 +120,8 @@ func (r *OPAVersionResource) Schema(ctx context.Context, req resource.SchemaRequ
121120
Computed: true,
122121
Optional: true,
123122
PlanModifiers: []planmodifier.Set{
124-
setplanmodifier.UseStateForUnknown(), // This ensures that we don't show a warning for invisible changes in updates when using refresh-only mode
125-
PreserveAMD64ArchsOnChange(), // This ensures that we update the amd64 archs when top level url/sha are updated
123+
setplanmodifier.UseStateForUnknown(),
124+
PreserveAMD64ArchsOnChange(),
126125
},
127126
},
128127
},

internal/provider/resource_tfe_sentinel_version.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,6 @@ func (r *sentinelVersionResource) Create(ctx context.Context, req resource.Creat
226226
}
227227
sentinelVersion.Archs = convertAPIArchsToFrameworkSet(v.Archs)
228228

229-
// Set state
230229
resp.Diagnostics.Append(resp.State.Set(ctx, &sentinelVersion)...)
231230
}
232231

internal/provider/resource_tfe_terraform_version.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,10 @@ func (r *terraformVersionResource) Create(ctx context.Context, req resource.Crea
191191
"version": tfVersion.Version.ValueString(),
192192
})
193193

194+
tflog.Debug(ctx, "Terraform version create options", map[string]interface{}{
195+
"options": opts,
196+
})
197+
194198
v, err := r.config.Client.Admin.TerraformVersions.Create(ctx, opts)
195199
if err != nil {
196200
tflog.Debug(ctx, "Error creating Terraform version", map[string]interface{}{
@@ -226,7 +230,6 @@ func (r *terraformVersionResource) Create(ctx context.Context, req resource.Crea
226230
}
227231
tfVersion.Archs = convertAPIArchsToFrameworkSet(v.Archs)
228232

229-
// Set state
230233
resp.Diagnostics.Append(resp.State.Set(ctx, &tfVersion)...)
231234
}
232235

@@ -289,7 +292,6 @@ func (r *terraformVersionResource) Update(ctx context.Context, req resource.Upda
289292
return
290293
}
291294

292-
// Use the ID from the state
293295
tfVersion.ID = state.ID
294296

295297
tflog.Debug(ctx, "Updating Terraform version resource", map[string]interface{}{

internal/provider/tool_helpers.go

Lines changed: 4 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ func stringOrNil(s string) *string {
157157
// ToolArchitecture represents the common architecture structure for all tool versions
158158
type ToolArchitecture struct {
159159
URL types.String `tfsdk:"url"`
160-
Sha types.String `tfsdk:"sha"` // Standardized to lowercase field name
160+
Sha types.String `tfsdk:"sha"`
161161
OS types.String `tfsdk:"os"`
162162
Arch types.String `tfsdk:"arch"`
163163
}
@@ -218,7 +218,7 @@ func convertToToolVersionArchitectures(ctx context.Context, archs types.Set) ([]
218218
for _, model := range archModels {
219219
result = append(result, &tfe.ToolVersionArchitecture{
220220
URL: model.URL.ValueString(),
221-
Sha: model.Sha.ValueString(), // Consistent lowercase field name
221+
Sha: model.Sha.ValueString(),
222222
OS: model.OS.ValueString(),
223223
Arch: model.Arch.ValueString(),
224224
})
@@ -233,15 +233,12 @@ func PreserveAMD64ArchsOnChange() planmodifier.Set {
233233
return &preserveAMD64ArchsModifier{}
234234
}
235235

236-
// Implement the plan modifier interface
237236
type preserveAMD64ArchsModifier struct{}
238237

239-
// Description provides a plain text description of the plan modifier
240238
func (m *preserveAMD64ArchsModifier) Description(ctx context.Context) string {
241239
return "Preserves AMD64 architecture entries when top-level URL or SHA changes"
242240
}
243241

244-
// MarkdownDescription provides markdown documentation
245242
func (m *preserveAMD64ArchsModifier) MarkdownDescription(ctx context.Context) string {
246243
return "Preserves AMD64 architecture entries when top-level URL or SHA changes"
247244
}
@@ -260,13 +257,11 @@ func (m *preserveAMD64ArchsModifier) PlanModifySet(ctx context.Context, req plan
260257

261258
var configURL, stateURL, configSHA, stateSHA types.String
262259

263-
// Get values from state and plan
264260
req.Config.GetAttribute(ctx, path.Root("url"), &configURL)
265261
req.State.GetAttribute(ctx, path.Root("url"), &stateURL)
266262
req.Config.GetAttribute(ctx, path.Root("sha"), &configSHA)
267263
req.State.GetAttribute(ctx, path.Root("sha"), &stateSHA)
268264

269-
// Check if values are changing
270265
urlChanged := !configURL.Equal(stateURL)
271266
shaChanged := !configSHA.Equal(stateSHA)
272267

@@ -276,18 +271,15 @@ func (m *preserveAMD64ArchsModifier) PlanModifySet(ctx context.Context, req plan
276271
return
277272
}
278273

279-
// Extract state archs and plan archs
280274
stateArchs := req.StateValue
281275
planArchs := req.PlanValue
282276

283-
// Extract archs from state
284277
var stateArchsList []ToolArchitecture
285278
diags := stateArchs.ElementsAs(ctx, &stateArchsList, false)
286279
if diags.HasError() {
287280
return
288281
}
289282

290-
// we need to update the plan amd url and sha to match the top level values
291283
var planArchsList []ToolArchitecture
292284
diags = planArchs.ElementsAs(ctx, &planArchsList, false)
293285
if diags.HasError() {
@@ -307,7 +299,7 @@ func (m *preserveAMD64ArchsModifier) PlanModifySet(ctx context.Context, req plan
307299
"stateSHA": configSHA,
308300
"planSHA": stateSHA,
309301
})
310-
// Check if AMD64 is already in the plan
302+
311303
for _, arch := range planArchsList {
312304
if arch.Arch.ValueString() == "amd64" {
313305
tflog.Debug(ctx, "Found AMD64 architecture in plan", map[string]interface{}{
@@ -316,8 +308,7 @@ func (m *preserveAMD64ArchsModifier) PlanModifySet(ctx context.Context, req plan
316308
"os": arch.OS.ValueString(),
317309
"arch": arch.Arch.ValueString(),
318310
})
319-
// If we found AMD64, update its URL and SHA if they are changing
320-
// If URL or SHA is changing, update the AMD64 arch to match
311+
321312
if urlChanged {
322313
arch.URL = configURL
323314
}
@@ -354,15 +345,12 @@ func SyncTopLevelURLSHAWithAMD64() planmodifier.String {
354345
return &SyncTopLevelURLSHAWithAMD64Modifier{}
355346
}
356347

357-
// Implement the plan modifier interface
358348
type SyncTopLevelURLSHAWithAMD64Modifier struct{}
359349

360-
// Description provides a plain text description of the plan modifier
361350
func (m *SyncTopLevelURLSHAWithAMD64Modifier) Description(ctx context.Context) string {
362351
return "Combines top-level URL/SHA with AMD64 architecture"
363352
}
364353

365-
// MarkdownDescription provides markdown documentation
366354
func (m *SyncTopLevelURLSHAWithAMD64Modifier) MarkdownDescription(ctx context.Context) string {
367355
return "Combines top-level URL/SHA with AMD64 architecture"
368356
}
@@ -380,9 +368,6 @@ func (m *SyncTopLevelURLSHAWithAMD64Modifier) PlanModifyString(ctx context.Conte
380368
return
381369
}
382370

383-
// if config archs is not set we will not modify the plan
384-
// get the config archs
385-
386371
var configArchs types.Set
387372
diags := req.Config.GetAttribute(ctx, path.Root("archs"), &configArchs)
388373
if diags.HasError() {
@@ -397,13 +382,9 @@ func (m *SyncTopLevelURLSHAWithAMD64Modifier) PlanModifyString(ctx context.Conte
397382
return
398383
}
399384

400-
// we do not know the name of the attibute
401-
// we are modifying, so we will use the path to get the attribute name
402385
segments := req.Path.String()
403386
attributeName := segments[strings.LastIndex(segments, ".")+1:]
404387

405-
// get the archs from the plan
406-
// get the amd arch from the configArchs
407388
var amd64Arch ToolArchitecture
408389
var configArchsList []ToolArchitecture
409390
diags = configArchs.ElementsAs(ctx, &configArchsList, false)
@@ -422,18 +403,14 @@ func (m *SyncTopLevelURLSHAWithAMD64Modifier) PlanModifyString(ctx context.Conte
422403
}
423404

424405
if amd64Arch.Arch.IsNull() || amd64Arch.Arch.IsUnknown() {
425-
// set the plan's top level URL/SHA to null
426406
resp.PlanValue = types.StringNull()
427407
return
428408
}
429409

430-
// Get the value of the attributeName from the amd64 arch
431410
switch attributeName {
432411
case "url":
433-
// set the plan value to the URL of the AMD64 arch
434412
resp.PlanValue = types.StringValue(amd64Arch.URL.ValueString())
435413
case "sha":
436-
// set the plan value to the SHA of the AMD64 arch
437414
resp.PlanValue = types.StringValue(amd64Arch.Sha.ValueString())
438415
default:
439416
tflog.Debug(ctx, "Unsupported attribute for AMD64 combination", map[string]interface{}{

0 commit comments

Comments
 (0)