Skip to content

Commit 2d9277b

Browse files
committed
Remove excessive commentary
1 parent 43164c6 commit 2d9277b

File tree

1 file changed

+3
-33
lines changed

1 file changed

+3
-33
lines changed

internal/service/ec2/stop_instance_action_test.go

Lines changed: 3 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,10 @@ func TestAccEC2StopInstanceAction_basic(t *testing.T) {
4242
},
4343
{
4444
PreConfig: func() {
45-
// Get the instance ID and invoke the action programmatically
4645
if v.InstanceId == nil {
4746
t.Fatal("Instance ID is nil")
4847
}
4948

50-
// Invoke the action programmatically with force=true
5149
if err := invokeStopInstanceAction(ctx, t, *v.InstanceId, true); err != nil {
5250
t.Fatalf("Failed to invoke stop instance action: %v", err)
5351
}
@@ -86,7 +84,6 @@ func TestAccEC2StopInstanceAction_trigger(t *testing.T) {
8684
})
8785
}
8886

89-
// testAccCheckInstanceExistsLocal checks that an instance exists and populates the instance variable
9087
func testAccCheckInstanceExistsLocal(ctx context.Context, n string, v *awstypes.Instance) resource.TestCheckFunc {
9188
return func(s *terraform.State) error {
9289
rs, ok := s.RootModule().Resources[n]
@@ -111,7 +108,6 @@ func testAccCheckInstanceExistsLocal(ctx context.Context, n string, v *awstypes.
111108
}
112109
}
113110

114-
// testAccCheckInstanceState checks that an instance is in the expected state
115111
func testAccCheckInstanceState(ctx context.Context, n string, expectedState awstypes.InstanceStateName) resource.TestCheckFunc {
116112
return func(s *terraform.State) error {
117113
rs, ok := s.RootModule().Resources[n]
@@ -200,44 +196,31 @@ resource "terraform_data" "trigger" {
200196
func providerWithActions(ctx context.Context, t *testing.T) tfprotov5.ProviderServerWithActions { //nolint:staticcheck // SA1019: Working in alpha situation
201197
t.Helper()
202198

203-
// Use the existing configured provider factories that handle muxing
204199
factories := acctest.ProtoV5ProviderFactories
205-
206-
// Get the AWS provider factory
207200
providerFactory, exists := factories["aws"]
208201
if !exists {
209202
t.Fatal("AWS provider factory not found in ProtoV5ProviderFactories")
210203
}
211204

212-
// Create the provider server
213205
providerServer, err := providerFactory()
214206
if err != nil {
215207
t.Fatalf("Failed to create provider server: %v", err)
216208
}
217209

218-
// Cast to ProviderServerWithActions
219210
providerWithActions, ok := providerServer.(tfprotov5.ProviderServerWithActions) //nolint:staticcheck // SA1019: Working in alpha situation
220211
if !ok {
221212
t.Fatal("Provider does not implement ProviderServerWithActions")
222213
}
223214

224-
// Initialize the provider similar to what Terraform core would do
225-
// This mimics the external provider example
226-
227-
// 1. Get the provider schema
228215
schemaResp, err := providerWithActions.GetProviderSchema(ctx, &tfprotov5.GetProviderSchemaRequest{})
229216
if err != nil {
230217
t.Fatalf("Failed to get provider schema: %v", err)
231218
}
232219

233-
// Verify we have action schemas
234220
if len(schemaResp.ActionSchemas) == 0 {
235221
t.Fatal("Expected to find action schemas but didn't find any!")
236222
}
237223

238-
// 2. Configure the provider - this is the key step that was missing!
239-
// Build a minimal configuration that satisfies the schema
240-
// We'll set all attributes to null and let them pick up from environment variables
241224
providerConfigValue, err := buildProviderConfiguration(t, schemaResp.Provider)
242225
if err != nil {
243226
t.Fatalf("Failed to build provider configuration: %v", err)
@@ -266,21 +249,15 @@ func providerWithActions(ctx context.Context, t *testing.T) tfprotov5.ProviderSe
266249
func buildProviderConfiguration(t *testing.T, providerSchema *tfprotov5.Schema) (*tfprotov5.DynamicValue, error) {
267250
t.Helper()
268251

269-
// Extract the provider schema type
270252
providerType := providerSchema.Block.ValueType()
271-
272-
// Build a configuration with all attributes set to null
273-
// This allows the provider to pick up values from environment variables
274253
configMap := make(map[string]tftypes.Value)
275254

276-
// Iterate through all attributes in the schema and set them to null
277255
if objType, ok := providerType.(tftypes.Object); ok {
278256
for attrName, attrType := range objType.AttributeTypes {
279257
configMap[attrName] = tftypes.NewValue(attrType, nil)
280258
}
281259
}
282260

283-
// Create the dynamic value with all attributes present but set to null
284261
configValue, err := tfprotov5.NewDynamicValue(
285262
providerType,
286263
tftypes.NewValue(providerType, configMap),
@@ -294,21 +271,20 @@ func buildProviderConfiguration(t *testing.T, providerSchema *tfprotov5.Schema)
294271

295272
// Step 2: Build action configuration
296273
func buildStopInstanceActionConfig(instanceID string, force bool) (tftypes.Type, map[string]tftypes.Value) {
297-
// This matches the schema from stop_instance_action.go
298274
configType := tftypes.Object{
299275
AttributeTypes: map[string]tftypes.Type{
300276
names.AttrInstanceID: tftypes.String,
301277
"force": tftypes.Bool,
302278
names.AttrTimeout: tftypes.Number,
303-
names.AttrRegion: tftypes.String, // Added missing region attribute
279+
names.AttrRegion: tftypes.String,
304280
},
305281
}
306282

307283
config := map[string]tftypes.Value{
308284
names.AttrInstanceID: tftypes.NewValue(tftypes.String, instanceID),
309285
"force": tftypes.NewValue(tftypes.Bool, force),
310-
names.AttrTimeout: tftypes.NewValue(tftypes.Number, nil), // Optional
311-
names.AttrRegion: tftypes.NewValue(tftypes.String, nil), // Optional, will be injected by framework
286+
names.AttrTimeout: tftypes.NewValue(tftypes.Number, nil),
287+
names.AttrRegion: tftypes.NewValue(tftypes.String, nil),
312288
}
313289

314290
return configType, config
@@ -318,15 +294,10 @@ func buildStopInstanceActionConfig(instanceID string, force bool) (tftypes.Type,
318294
func invokeStopInstanceAction(ctx context.Context, t *testing.T, instanceID string, force bool) error {
319295
t.Helper()
320296

321-
// Get the provider
322297
p := providerWithActions(ctx, t)
323-
324-
// Build configuration
325298
configType, configMap := buildStopInstanceActionConfig(instanceID, force)
326-
327299
actionTypeName := "aws_ec2_stop_instance"
328300

329-
// Create dynamic value for config
330301
testConfig, err := tfprotov5.NewDynamicValue(
331302
configType,
332303
tftypes.NewValue(configType, configMap),
@@ -335,7 +306,6 @@ func invokeStopInstanceAction(ctx context.Context, t *testing.T, instanceID stri
335306
return fmt.Errorf("failed to create config: %w", err)
336307
}
337308

338-
// Step 3: Invoke the action directly (provider should already be configured)
339309
invokeResp, err := p.InvokeAction(ctx, &tfprotov5.InvokeActionRequest{
340310
ActionType: actionTypeName,
341311
Config: &testConfig,

0 commit comments

Comments
 (0)