Skip to content
This repository has been archived by the owner on Nov 27, 2024. It is now read-only.

make one of the source_ parameters required for ingress firewall #336

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions converters/google/resources/compute_firewall.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,28 @@ func resourceComputeFirewallEnableLoggingCustomizeDiff(_ context.Context, diff *
return nil
}

// Per https://github.com/hashicorp/terraform-provider-google/issues/2924
// Make one of the source_ parameters Required in ingress google_compute_firewall
func resourceComputeFirewallSourceFieldsCustomizeDiff(_ context.Context, diff *schema.ResourceDiff, v interface{}) error {
direction := diff.Get("direction").(string)

if direction != "EGRESS" {
_, tagsOk := diff.GetOk("source_tags")
_, rangesOk := diff.GetOk("source_ranges")
_, sasOk := diff.GetOk("source_service_accounts")

_, tagsExist := diff.GetOkExists("source_tags")
// ranges is computed, but this is what we're trying to avoid, so we're not going to check this
_, sasExist := diff.GetOkExists("source_service_accounts")

if !tagsOk && !rangesOk && !sasOk && !tagsExist && !sasExist {
return fmt.Errorf("one of source_tags, source_ranges, or source_service_accounts must be defined")
}
}

return nil
}

const ComputeFirewallAssetType string = "compute.googleapis.com/Firewall"

func resourceConverterComputeFirewall() ResourceConverter {
Expand Down