Skip to content

Commit 3726be4

Browse files
Hierarchical firewall policies (#5090) (#3556)
* Send empty instead of nil array * Adding hierarchical firewall rules * Update firewall policy yamls * Fix test: * Add markdown for hierarchical firewall policies * PR review * Add auto id renaming Signed-off-by: Modular Magician <[email protected]>
1 parent e703983 commit 3726be4

16 files changed

+2079
-1
lines changed

.changelog/5090.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
```release-note:new-resource
2+
google_compute_firewall_policy_rule
3+
```
4+
```release-note:new-resource
5+
google_compute_firewall_policy_association
6+
```
7+
```release-note:new-resource
8+
google_compute_firewall_policy
9+
```

google-beta/expanders.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,10 @@ func expandStringArray(v interface{}) []string {
1313
return convertStringSet(arr)
1414
}
1515

16-
return convertStringArr(v.([]interface{}))
16+
arr = convertStringArr(v.([]interface{}))
17+
if arr == nil {
18+
// Send empty array specifically instead of nil
19+
return make([]string, 0)
20+
}
21+
return arr
1722
}

google-beta/provider.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1267,6 +1267,9 @@ func ResourceMapWithErrors() (map[string]*schema.Resource, error) {
12671267
"google_cloudfunctions_function": resourceCloudFunctionsFunction(),
12681268
"google_composer_environment": resourceComposerEnvironment(),
12691269
"google_compute_attached_disk": resourceComputeAttachedDisk(),
1270+
"google_compute_firewall_policy_association": resourceComputeFirewallPolicyAssociation(),
1271+
"google_compute_firewall_policy": resourceComputeFirewallPolicy(),
1272+
"google_compute_firewall_policy_rule": resourceComputeFirewallPolicyRule(),
12701273
"google_compute_instance": resourceComputeInstance(),
12711274
"google_compute_instance_from_machine_image": resourceComputeInstanceFromMachineImage(),
12721275
"google_compute_instance_from_template": resourceComputeInstanceFromTemplate(),

google-beta/provider_dcl_client_creation.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020

2121
assuredworkloads "github.com/GoogleCloudPlatform/declarative-resource-client-library/services/google/assuredworkloads/beta"
2222
cloudbuild "github.com/GoogleCloudPlatform/declarative-resource-client-library/services/google/cloudbuild/beta"
23+
compute "github.com/GoogleCloudPlatform/declarative-resource-client-library/services/google/compute/beta"
2324
dataproc "github.com/GoogleCloudPlatform/declarative-resource-client-library/services/google/dataproc/beta"
2425
eventarc "github.com/GoogleCloudPlatform/declarative-resource-client-library/services/google/eventarc/beta"
2526
gkehub "github.com/GoogleCloudPlatform/declarative-resource-client-library/services/google/gkehub/beta"
@@ -63,6 +64,25 @@ func NewDCLCloudbuildClient(config *Config, userAgent, billingProject string) *c
6364
return cloudbuild.NewClient(dclConfig)
6465
}
6566

67+
func NewDCLComputeClient(config *Config, userAgent, billingProject string) *compute.Client {
68+
configOptions := []dcl.ConfigOption{
69+
dcl.WithHTTPClient(config.client),
70+
dcl.WithUserAgent(userAgent),
71+
dcl.WithLogger(dclLogger{}),
72+
dcl.WithBasePath(config.ComputeBasePath),
73+
}
74+
75+
if config.UserProjectOverride {
76+
configOptions = append(configOptions, dcl.WithUserProjectOverride())
77+
if billingProject != "" {
78+
configOptions = append(configOptions, dcl.WithBillingProject(billingProject))
79+
}
80+
}
81+
82+
dclConfig := dcl.NewConfig(configOptions...)
83+
return compute.NewClient(dclConfig)
84+
}
85+
6686
func NewDCLDataprocClient(config *Config, userAgent, billingProject string) *dataproc.Client {
6787
configOptions := []dcl.ConfigOption{
6888
dcl.WithHTTPClient(config.client),

google-beta/provider_dcl_endpoints.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,15 @@ var CloudBuildWorkerPoolEndpointEntry = &schema.Schema{
4040
}, ""),
4141
}
4242

43+
var ComputeEndpointEntryKey = "compute_custom_endpoint"
44+
var ComputeEndpointEntry = &schema.Schema{
45+
Type: schema.TypeString,
46+
Optional: true,
47+
DefaultFunc: schema.MultiEnvDefaultFunc([]string{
48+
"GOOGLE_COMPUTE_CUSTOM_ENDPOINT",
49+
}, ""),
50+
}
51+
4352
var EventarcEndpointEntryKey = "eventarc_custom_endpoint"
4453
var EventarcEndpointEntry = &schema.Schema{
4554
Type: schema.TypeString,
@@ -52,14 +61,17 @@ var EventarcEndpointEntry = &schema.Schema{
5261
//Add new values to config.go.erb config object declaration
5362
//AssuredWorkloadsBasePath string
5463
//CloudBuildWorkerPoolBasePath string
64+
//ComputeBasePath string
5565
//EventarcBasePath string
5666

5767
//Add new values to provider.go.erb schema initialization
5868
// AssuredWorkloadsEndpointEntryKey: AssuredWorkloadsEndpointEntry,
5969
// CloudBuildWorkerPoolEndpointEntryKey: CloudBuildWorkerPoolEndpointEntry,
70+
// ComputeEndpointEntryKey: ComputeEndpointEntry,
6071
// EventarcEndpointEntryKey: EventarcEndpointEntry,
6172

6273
//Add new values to provider.go.erb - provider block read
6374
// config.AssuredWorkloadsBasePath = d.Get(AssuredWorkloadsEndpointEntryKey).(string)
6475
// config.CloudBuildWorkerPoolBasePath = d.Get(CloudBuildWorkerPoolEndpointEntryKey).(string)
76+
// config.ComputeBasePath = d.Get(ComputeEndpointEntryKey).(string)
6577
// config.EventarcBasePath = d.Get(EventarcEndpointEntryKey).(string)

0 commit comments

Comments
 (0)