@@ -59,6 +59,17 @@ type ScanConfigurationInput struct {
5959 EventScanTriggers * []* AWSEventPatternInput `tfsdk:"event_scan_triggers"`
6060 // (Optional.)
6161 Ec2ScanOptions * Ec2ScanOptionsInput `tfsdk:"ec2_scan_options"`
62+ // (Optional.)
63+ VpcConfiguration * VPCConfigurationInput `tfsdk:"vpc_configuration"`
64+ }
65+
66+ type VPCConfigurationInput struct {
67+ // (Optional.)
68+ UseDefaultVPC types.Bool `tfsdk:"use_default_vpc"`
69+ // (Optional.)
70+ UseMondooVPC types.Bool `tfsdk:"use_mondoo_vpc"`
71+ // (Optional.)
72+ CIDR types.String `tfsdk:"cidr_block"`
6273}
6374
6475type AWSEventPatternInput struct {
@@ -144,6 +155,11 @@ func (m integrationAwsServerlessResourceModel) GetConfigurationOptions() *mondoo
144155 IsOrganization : mondoov1 .NewBooleanPtr (mondoov1 .Boolean (m .IsOrganization .ValueBool ())),
145156 AccountIDs : & accountIDs ,
146157 ScanConfiguration : mondoov1.ScanConfigurationInput {
158+ VpcConfiguration : & mondoov1.VPCConfigurationInput {
159+ UseDefaultVPC : mondoov1 .NewBooleanPtr (mondoov1 .Boolean (m .ScanConfiguration .VpcConfiguration .UseDefaultVPC .ValueBool ())),
160+ UseMondooVPC : mondoov1 .NewBooleanPtr (mondoov1 .Boolean (m .ScanConfiguration .VpcConfiguration .UseMondooVPC .ValueBool ())),
161+ CIDR : mondoov1 .NewStringPtr (mondoov1 .String (m .ScanConfiguration .VpcConfiguration .CIDR .ValueString ())),
162+ },
147163 Ec2Scan : mondoov1 .NewBooleanPtr (mondoov1 .Boolean (m .ScanConfiguration .Ec2Scan .ValueBool ())),
148164 EcrScan : mondoov1 .NewBooleanPtr (mondoov1 .Boolean (m .ScanConfiguration .EcrScan .ValueBool ())),
149165 EcsScan : mondoov1 .NewBooleanPtr (mondoov1 .Boolean (m .ScanConfiguration .EcsScan .ValueBool ())),
@@ -228,6 +244,23 @@ func (r *integrationAwsServerlessResource) Schema(ctx context.Context, req resou
228244 MarkdownDescription : "Cron scan in hours." ,
229245 Optional : true ,
230246 },
247+ "vpc_configuration" : schema.SingleNestedAttribute {
248+ Optional : true ,
249+ Attributes : map [string ]schema.Attribute {
250+ "use_default_vpc" : schema.BoolAttribute {
251+ MarkdownDescription : "Use default VPC." ,
252+ Optional : true ,
253+ },
254+ "use_mondoo_vpc" : schema.BoolAttribute {
255+ MarkdownDescription : "Use Mondoo VPC." ,
256+ Optional : true ,
257+ },
258+ "cidr_block" : schema.StringAttribute {
259+ MarkdownDescription : "CIDR block for the Mondoo VPC." ,
260+ Optional : true ,
261+ },
262+ },
263+ },
231264 "ec2_scan_options" : schema.SingleNestedAttribute {
232265 Required : true ,
233266 Attributes : map [string ]schema.Attribute {
@@ -305,6 +338,43 @@ func (r *integrationAwsServerlessResource) Schema(ctx context.Context, req resou
305338 }
306339}
307340
341+ func (r integrationAwsServerlessResource ) ValidateConfig (ctx context.Context , req resource.ValidateConfigRequest , resp * resource.ValidateConfigResponse ) {
342+ var data integrationAwsServerlessResourceModel
343+ resp .Diagnostics .Append (req .Config .Get (ctx , & data )... )
344+
345+ if resp .Diagnostics .HasError () {
346+ return
347+ }
348+
349+ // user has provided both default or mondoo vpc
350+ if ! data .ScanConfiguration .VpcConfiguration .UseDefaultVPC .IsNull () && ! data .ScanConfiguration .VpcConfiguration .UseMondooVPC .IsNull () {
351+ defaultVpc := data .ScanConfiguration .VpcConfiguration .UseDefaultVPC .ValueBool ()
352+ mondooVpc := data .ScanConfiguration .VpcConfiguration .UseMondooVPC .ValueBool ()
353+ if defaultVpc && mondooVpc {
354+ resp .Diagnostics .AddError (
355+ "ConflictingAttributesError" ,
356+ "Cannot set both use_default_vpc and use_mondoo_vpc to true at the same time." ,
357+ )
358+ }
359+
360+ if ! defaultVpc && ! mondooVpc {
361+ resp .Diagnostics .AddError (
362+ "ConflictingAttributesError" ,
363+ "Cannot set both use_default_vpc and use_mondoo_vpc to false at the same time." ,
364+ )
365+ }
366+ }
367+ // user has provided mondoo vpc only
368+ if mondooVpc := data .ScanConfiguration .VpcConfiguration .UseMondooVPC .ValueBool (); mondooVpc {
369+ if cidr := data .ScanConfiguration .VpcConfiguration .CIDR .ValueString (); cidr == "" {
370+ resp .Diagnostics .AddError (
371+ "MissingAttributeError" ,
372+ "Attribute cidr_block must not be empty when use_mondoo_vpc is set to true." ,
373+ )
374+ }
375+ }
376+ }
377+
308378func (r * integrationAwsServerlessResource ) Configure (ctx context.Context , req resource.ConfigureRequest , resp * resource.ConfigureResponse ) {
309379 // Prevent panic if the provider has not been configured.
310380 if req .ProviderData == nil {
0 commit comments