Skip to content

Commit bc08799

Browse files
add billing project id support to firewall endpoint resource (#10122) (#7124)
* add billing project support * removed description field due to API issue * test updated and fixed for ADC support * added ADC warning * removing ADC [upstream:8f3a9892f4cfeddbaf4dc8457849e30e6ac49b8e] Signed-off-by: Modular Magician <[email protected]>
1 parent 6da4d23 commit bc08799

File tree

4 files changed

+72
-22
lines changed

4 files changed

+72
-22
lines changed

.changelog/10122.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:breaking-change
2+
networksecurity: added required field `billing_project_id` to `google_network_security_firewall_endpoint` resource. Any configuration without `billing_project_id` specified will cause resource creation fail (beta)
3+
```

google-beta/services/networksecurity/resource_network_security_firewall_endpoint.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,11 @@ func ResourceNetworkSecurityFirewallEndpoint() *schema.Resource {
5353
),
5454

5555
Schema: map[string]*schema.Schema{
56+
"billing_project_id": {
57+
Type: schema.TypeString,
58+
Required: true,
59+
Description: `Project to bill on endpoint uptime usage.`,
60+
},
5661
"location": {
5762
Type: schema.TypeString,
5863
Required: true,
@@ -145,6 +150,12 @@ func resourceNetworkSecurityFirewallEndpointCreate(d *schema.ResourceData, meta
145150
}
146151

147152
obj := make(map[string]interface{})
153+
billingProjectIdProp, err := expandNetworkSecurityFirewallEndpointBillingProjectId(d.Get("billing_project_id"), d, config)
154+
if err != nil {
155+
return err
156+
} else if v, ok := d.GetOkExists("billing_project_id"); !tpgresource.IsEmptyValue(reflect.ValueOf(billingProjectIdProp)) && (ok || !reflect.DeepEqual(v, billingProjectIdProp)) {
157+
obj["billingProjectId"] = billingProjectIdProp
158+
}
148159
labelsProp, err := expandNetworkSecurityFirewallEndpointEffectiveLabels(d.Get("effective_labels"), d, config)
149160
if err != nil {
150161
return err
@@ -251,6 +262,9 @@ func resourceNetworkSecurityFirewallEndpointRead(d *schema.ResourceData, meta in
251262
if err := d.Set("state", flattenNetworkSecurityFirewallEndpointState(res["state"], d, config)); err != nil {
252263
return fmt.Errorf("Error reading FirewallEndpoint: %s", err)
253264
}
265+
if err := d.Set("billing_project_id", flattenNetworkSecurityFirewallEndpointBillingProjectId(res["billingProjectId"], d, config)); err != nil {
266+
return fmt.Errorf("Error reading FirewallEndpoint: %s", err)
267+
}
254268
if err := d.Set("terraform_labels", flattenNetworkSecurityFirewallEndpointTerraformLabels(res["labels"], d, config)); err != nil {
255269
return fmt.Errorf("Error reading FirewallEndpoint: %s", err)
256270
}
@@ -272,6 +286,12 @@ func resourceNetworkSecurityFirewallEndpointUpdate(d *schema.ResourceData, meta
272286
billingProject := ""
273287

274288
obj := make(map[string]interface{})
289+
billingProjectIdProp, err := expandNetworkSecurityFirewallEndpointBillingProjectId(d.Get("billing_project_id"), d, config)
290+
if err != nil {
291+
return err
292+
} else if v, ok := d.GetOkExists("billing_project_id"); !tpgresource.IsEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, billingProjectIdProp)) {
293+
obj["billingProjectId"] = billingProjectIdProp
294+
}
275295
labelsProp, err := expandNetworkSecurityFirewallEndpointEffectiveLabels(d.Get("effective_labels"), d, config)
276296
if err != nil {
277297
return err
@@ -287,6 +307,10 @@ func resourceNetworkSecurityFirewallEndpointUpdate(d *schema.ResourceData, meta
287307
log.Printf("[DEBUG] Updating FirewallEndpoint %q: %#v", d.Id(), obj)
288308
updateMask := []string{}
289309

310+
if d.HasChange("billing_project_id") {
311+
updateMask = append(updateMask, "billingProjectId")
312+
}
313+
290314
if d.HasChange("effective_labels") {
291315
updateMask = append(updateMask, "labels")
292316
}
@@ -437,6 +461,10 @@ func flattenNetworkSecurityFirewallEndpointState(v interface{}, d *schema.Resour
437461
return v
438462
}
439463

464+
func flattenNetworkSecurityFirewallEndpointBillingProjectId(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
465+
return v
466+
}
467+
440468
func flattenNetworkSecurityFirewallEndpointTerraformLabels(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
441469
if v == nil {
442470
return v
@@ -456,6 +484,10 @@ func flattenNetworkSecurityFirewallEndpointEffectiveLabels(v interface{}, d *sch
456484
return v
457485
}
458486

487+
func expandNetworkSecurityFirewallEndpointBillingProjectId(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
488+
return v, nil
489+
}
490+
459491
func expandNetworkSecurityFirewallEndpointEffectiveLabels(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (map[string]string, error) {
460492
if v == nil {
461493
return map[string]string{}, nil

google-beta/services/networksecurity/resource_network_security_firewall_endpoint_test.go

Lines changed: 27 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ func TestAccNetworkSecurityFirewallEndpoints_basic(t *testing.T) {
2020
acctest.SkipIfVcr(t)
2121
t.Parallel()
2222

23+
billingProjectId := envvar.GetTestProjectFromEnv()
2324
orgId := envvar.GetTestOrgFromEnv(t)
2425
randomSuffix := acctest.RandString(t, 10)
2526

@@ -29,7 +30,7 @@ func TestAccNetworkSecurityFirewallEndpoints_basic(t *testing.T) {
2930
CheckDestroy: testAccCheckNetworkSecurityFirewallEndpointDestroyProducer(t),
3031
Steps: []resource.TestStep{
3132
{
32-
Config: testAccNetworkSecurityFirewallEndpoints_basic(orgId, randomSuffix),
33+
Config: testAccNetworkSecurityFirewallEndpoints_basic(orgId, billingProjectId, randomSuffix),
3334
},
3435
{
3536
ResourceName: "google_network_security_firewall_endpoint.foobar",
@@ -38,7 +39,7 @@ func TestAccNetworkSecurityFirewallEndpoints_basic(t *testing.T) {
3839
ImportStateVerifyIgnore: []string{"labels", "terraform_labels"},
3940
},
4041
{
41-
Config: testAccNetworkSecurityFirewallEndpoints_update(orgId, randomSuffix),
42+
Config: testAccNetworkSecurityFirewallEndpoints_update(orgId, billingProjectId, randomSuffix),
4243
},
4344
{
4445
ResourceName: "google_network_security_firewall_endpoint.foobar",
@@ -50,34 +51,38 @@ func TestAccNetworkSecurityFirewallEndpoints_basic(t *testing.T) {
5051
})
5152
}
5253

53-
func testAccNetworkSecurityFirewallEndpoints_basic(orgId string, randomSuffix string) string {
54+
func testAccNetworkSecurityFirewallEndpoints_basic(orgId string, billingProjectId string, randomSuffix string) string {
5455
return fmt.Sprintf(`
5556
resource "google_network_security_firewall_endpoint" "foobar" {
56-
provider = google-beta
57-
name = "tf-test-my-firewall-endpoint%s"
58-
parent = "organizations/%s"
59-
location = "us-central1-a"
60-
61-
labels = {
62-
foo = "bar"
63-
}
57+
provider = google-beta
58+
59+
name = "tf-test-my-firewall-endpoint%[1]s"
60+
parent = "organizations/%[2]s"
61+
location = "us-central1-a"
62+
billing_project_id = "%[3]s"
63+
64+
labels = {
65+
foo = "bar"
66+
}
6467
}
65-
`, randomSuffix, orgId)
68+
`, randomSuffix, orgId, billingProjectId)
6669
}
6770

68-
func testAccNetworkSecurityFirewallEndpoints_update(orgId string, randomSuffix string) string {
71+
func testAccNetworkSecurityFirewallEndpoints_update(orgId string, billingProjectId string, randomSuffix string) string {
6972
return fmt.Sprintf(`
7073
resource "google_network_security_firewall_endpoint" "foobar" {
71-
provider = google-beta
72-
name = "tf-test-my-firewall-endpoint%s"
73-
parent = "organizations/%s"
74-
location = "us-central1-a"
75-
76-
labels = {
77-
foo = "bar-updated"
78-
}
74+
provider = google-beta
75+
76+
name = "tf-test-my-firewall-endpoint%[1]s"
77+
parent = "organizations/%[2]s"
78+
location = "us-central1-a"
79+
billing_project_id = "%[3]s"
80+
81+
labels = {
82+
foo = "bar-updated"
83+
}
7984
}
80-
`, randomSuffix, orgId)
85+
`, randomSuffix, orgId, billingProjectId)
8186
}
8287

8388
func testAccCheckNetworkSecurityFirewallEndpointDestroyProducer(t *testing.T) func(s *terraform.State) error {

website/docs/r/network_security_firewall_endpoint.html.markdown

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,12 @@ To get more information about FirewallEndpoint, see:
3535
* [Firewall endpoint overview](https://cloud.google.com/firewall/docs/about-firewall-endpoints)
3636
* [Create and associate firewall endpoints](https://cloud.google.com/firewall/docs/configure-firewall-endpoints)
3737

38+
~> **Warning:** If you are using User ADCs (Application Default Credentials) with this resource,
39+
you must specify a `billing_project` and set `user_project_override` to true
40+
in the provider configuration. Otherwise the ACM API will return a 403 error.
41+
Your account must have the `serviceusage.services.use` permission on the
42+
`billing_project` you defined.
43+
3844
## Example Usage - Network Security Firewall Endpoint Basic
3945

4046

@@ -56,6 +62,10 @@ resource "google_network_security_firewall_endpoint" "default" {
5662
The following arguments are supported:
5763

5864

65+
* `billing_project_id` -
66+
(Required)
67+
Project to bill on endpoint uptime usage.
68+
5969
* `name` -
6070
(Required)
6171
The name of the firewall endpoint resource.

0 commit comments

Comments
 (0)