Skip to content

Commit ee1a0a9

Browse files
committed
Add WithoutInternetAccess() and WithInternetAccess() VM options
Add two new VMOption functions to ec2/vmargs.go: - WithoutInternetAccess(): replaces the default security groups with the no-internet ones (existing feature, now with a proper VM-level option) - WithInternetAccess(): the explicit opt-in counterpart — overrides any no-internet default set by a provisioner Both options manipulate the same withoutInternetAccess bool on vmArgs. No behavior change: neither function is called by any provisioner default yet.
1 parent 44a9fcf commit ee1a0a9

1 file changed

Lines changed: 25 additions & 0 deletions

File tree

  • test/e2e-framework/scenarios/aws/ec2

test/e2e-framework/scenarios/aws/ec2/vmargs.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import (
2626
// - [WithHostID]
2727
// - [WithTenancy]
2828
// - [WithVolumeThroughput]
29+
// - [WithoutInternetAccess]
2930
// - [WithPulumiResourceOptions]
3031
//
3132
// [Functional options pattern]: https://dave.cheney.net/2014/10/17/functional-options-for-friendly-apis
@@ -40,6 +41,7 @@ type vmArgs struct {
4041
tenancy string
4142
hostID string
4243

44+
withoutInternetAccess bool
4345
httpTokensRequired bool
4446
volumeThroughput int // GP3 volume throughput in MiB/s (125-1000, default 125)
4547
pulumiResourceOptions []pulumi.ResourceOption
@@ -147,3 +149,26 @@ func WithVolumeThroughput(throughput int) VMOption {
147149
return nil
148150
}
149151
}
152+
153+
// WithoutInternetAccess replaces the account's default security groups with the ones
154+
// configured to block internet access (see aws.Environment.NoInternetSecurityGroupNames).
155+
// These security groups must already exist and be configured accordingly, since AWS
156+
// security group rules are additive across all groups attached to an instance: attaching
157+
// a restrictive group in addition to the permissive defaults would not restrict anything.
158+
func WithoutInternetAccess() VMOption {
159+
return func(p *vmArgs) error {
160+
p.withoutInternetAccess = true
161+
return nil
162+
}
163+
}
164+
165+
// WithInternetAccess explicitly opts the VM into internet access, overriding any
166+
// no-internet default set by the provisioner. Tests that need to reach external
167+
// hosts (e.g. to download packages, pull images, or contact external APIs) must
168+
// call this option explicitly.
169+
func WithInternetAccess() VMOption {
170+
return func(p *vmArgs) error {
171+
p.withoutInternetAccess = false
172+
return nil
173+
}
174+
}

0 commit comments

Comments
 (0)