Skip to content

Commit 9fd482b

Browse files
VPCFlowLogs - Add Organization Support (#14885)
1 parent 78ad34e commit 9fd482b

File tree

3 files changed

+235
-0
lines changed

3 files changed

+235
-0
lines changed
Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
# Copyright 2025 Google Inc.
2+
# Licensed under the Apache License, Version 2.0 (the "License");
3+
# you may not use this file except in compliance with the License.
4+
# You may obtain a copy of the License at
5+
#
6+
# http://www.apache.org/licenses/LICENSE-2.0
7+
#
8+
# Unless required by applicable law or agreed to in writing, software
9+
# distributed under the License is distributed on an "AS IS" BASIS,
10+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
# See the License for the specific language governing permissions and
12+
# limitations under the License.
13+
14+
---
15+
name: 'OrganizationVpcFlowLogsConfig'
16+
description:
17+
VPC Flow Logs Config is a resource that lets you configure
18+
Flow Logs for Organization.
19+
min_version: beta
20+
id_format: 'organizations/{{organization}}/locations/{{location}}/vpcFlowLogsConfigs/{{vpc_flow_logs_config_id}}'
21+
base_url: 'organizations/{{organization}}/locations/{{location}}/vpcFlowLogsConfigs'
22+
self_link: 'organizations/{{organization}}/locations/{{location}}/vpcFlowLogsConfigs/{{vpc_flow_logs_config_id}}'
23+
create_url: 'organizations/{{organization}}/locations/{{location}}/vpcFlowLogsConfigs?vpcFlowLogsConfigId={{vpc_flow_logs_config_id}}'
24+
update_verb: 'PATCH'
25+
update_mask: true
26+
import_format:
27+
- 'organizations/{{organization}}/locations/{{location}}/vpcFlowLogsConfigs/{{vpc_flow_logs_config_id}}'
28+
timeouts:
29+
insert_minutes: 20
30+
update_minutes: 20
31+
delete_minutes: 20
32+
autogen_async: true
33+
async:
34+
actions: ['create', 'delete', 'update']
35+
type: 'OpAsync'
36+
operation:
37+
base_url: '{{op_id}}'
38+
result:
39+
resource_inside_response: true
40+
include_project: true
41+
custom_code:
42+
sweeper:
43+
url_substitutions:
44+
- parent: "organizations/${ORG_ID}"
45+
- region: "global"
46+
examples:
47+
- name: 'network_management_org_vpc_flow_logs_config_basic'
48+
primary_resource_id: 'org-test'
49+
min_version: 'beta'
50+
vars:
51+
vpc_flow_logs_config_id: 'basic-org-test-id'
52+
test_env_vars:
53+
org_id: 'ORG_ID'
54+
parameters:
55+
- name: 'organization'
56+
type: String
57+
description: Resource ID segment making up resource `name`. It identifies the resource within its parent collection as described in https://google.aip.dev/122.
58+
immutable: true
59+
url_param_only: true
60+
required: true
61+
- name: 'location'
62+
type: String
63+
description: |
64+
Resource ID segment making up resource `name`. It identifies the resource
65+
within its parent collection as described in https://google.aip.dev/122. See documentation
66+
for resource type `networkmanagement.googleapis.com/VpcFlowLogsConfig`.
67+
url_param_only: true
68+
required: true
69+
immutable: true
70+
- name: 'vpcFlowLogsConfigId'
71+
type: String
72+
description: |
73+
Required. ID of the `VpcFlowLogsConfig`.
74+
url_param_only: true
75+
required: true
76+
immutable: true
77+
properties:
78+
- name: 'name'
79+
type: String
80+
description: |
81+
Identifier. Unique name of the configuration using the form: `organizations/{org_id}/locations/global/vpcFlowLogsConfigs/{vpc_flow_logs_config_id}`
82+
output: true
83+
- name: 'description'
84+
type: String
85+
description: |
86+
Optional. The user-supplied description of the VPC Flow Logs configuration. Maximum
87+
of 512 characters.
88+
- name: 'state'
89+
type: String
90+
default_from_api: true
91+
description: |
92+
Optional. The state of the VPC Flow Log configuration. Default value
93+
is ENABLED. When creating a new configuration, it must be enabled.
94+
Possible values: ENABLED DISABLED
95+
- name: 'aggregationInterval'
96+
type: String
97+
default_from_api: true
98+
description: |
99+
Optional. The aggregation interval for the logs. Default value is
100+
INTERVAL_5_SEC. Possible values: INTERVAL_5_SEC INTERVAL_30_SEC INTERVAL_1_MIN INTERVAL_5_MIN INTERVAL_10_MIN INTERVAL_15_MIN
101+
- name: 'flowSampling'
102+
type: Double
103+
default_from_api: true
104+
description: |
105+
Optional. The value of the field must be in (0, 1]. The sampling rate
106+
of VPC Flow Logs where 1.0 means all collected logs are reported. Setting the
107+
sampling rate to 0.0 is not allowed. If you want to disable VPC Flow Logs, use
108+
the state field instead. Default value is 1.0.
109+
- name: 'metadata'
110+
type: String
111+
default_from_api: true
112+
description: |
113+
Optional. Configures whether all, none or a subset of metadata fields
114+
should be added to the reported VPC flow logs. Default value is INCLUDE_ALL_METADATA.
115+
Possible values: METADATA_UNSPECIFIED INCLUDE_ALL_METADATA EXCLUDE_ALL_METADATA CUSTOM_METADATA
116+
- name: 'metadataFields'
117+
type: Array
118+
description: |
119+
Optional. Custom metadata fields to include in the reported VPC flow
120+
logs. Can only be specified if \"metadata\" was set to CUSTOM_METADATA.
121+
item_type:
122+
type: String
123+
- name: 'filterExpr'
124+
type: String
125+
description: |
126+
Optional. Export filter used to define which VPC Flow Logs should be logged.
127+
- name: 'labels'
128+
type: KeyValueLabels
129+
description: |
130+
Optional. Resource labels to represent the user-provided metadata.
131+
- name: 'createTime'
132+
type: String
133+
description: |
134+
Output only. The time the config was created.
135+
output: true
136+
- name: 'updateTime'
137+
type: String
138+
description: |
139+
Output only. The time the config was updated.
140+
output: true
141+
- name: 'crossProjectMetadata'
142+
type: Enum
143+
default_from_api: true
144+
description: |-
145+
Determines whether to include cross project annotations in the logs.
146+
This field is available only for organization configurations. If not
147+
specified in org configs will be set to CROSS_PROJECT_METADATA_ENABLED.
148+
Possible values:
149+
CROSS_PROJECT_METADATA_ENABLED
150+
CROSS_PROJECT_METADATA_DISABLED
151+
enum_values:
152+
- CROSS_PROJECT_METADATA_ENABLED
153+
- CROSS_PROJECT_METADATA_DISABLED
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
resource "google_network_management_organization_vpc_flow_logs_config" "{{$.PrimaryResourceId}}" {
2+
provider = google-beta
3+
vpc_flow_logs_config_id = "{{index $.Vars "vpc_flow_logs_config_id"}}"
4+
location = "global"
5+
organization = "{{index $.TestEnvVars "org_id"}}"
6+
}
7+
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
package networkmanagement_test
2+
3+
{{ if ne $.TargetVersionName "ga" -}}
4+
import (
5+
"testing"
6+
7+
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
8+
"github.com/hashicorp/terraform-provider-google/google/acctest"
9+
"github.com/hashicorp/terraform-provider-google/google/envvar"
10+
)
11+
12+
func TestAccNetworkManagementOrganizationVpcFlowLogsConfig_update(t *testing.T) {
13+
t.Parallel()
14+
15+
context := map[string]interface{}{
16+
"random_suffix": acctest.RandString(t, 10),
17+
"org_id": envvar.GetTestOrgFromEnv(t),
18+
}
19+
20+
acctest.VcrTest(t, resource.TestCase{
21+
PreCheck: func() { acctest.AccTestPreCheck(t) },
22+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderBetaFactories(t),
23+
CheckDestroy: testAccCheckNetworkManagementVpcFlowLogsConfigDestroyProducer(t),
24+
Steps: []resource.TestStep{
25+
{
26+
Config: testAccNetworkManagementOrganizationVpcFlowLogsConfig_basic(context),
27+
},
28+
{
29+
ResourceName: "google_network_management_organization_vpc_flow_logs_config.org-test-update",
30+
ImportState: true,
31+
ImportStateVerify: true,
32+
ImportStateVerifyIgnore: []string{"organization", "location", "vpc_flow_logs_config_id"},
33+
},
34+
{
35+
Config: testAccNetworkManagementOrganizationVpcFlowLogsConfig_update(context),
36+
},
37+
{
38+
ResourceName: "google_network_management_organization_vpc_flow_logs_config.org-test-update",
39+
ImportState: true,
40+
ImportStateVerify: true,
41+
ImportStateVerifyIgnore: []string{"organization", "location", "vpc_flow_logs_config_id"},
42+
},
43+
},
44+
})
45+
}
46+
47+
func testAccNetworkManagementOrganizationVpcFlowLogsConfig_basic(context map[string]interface{}) string {
48+
return acctest.Nprintf(`
49+
resource "google_network_management_organization_vpc_flow_logs_config" "org-test-update" {
50+
provider = google-beta
51+
vpc_flow_logs_config_id = "tf-test-update-org-id-%{random_suffix}"
52+
organization = "%{org_id}"
53+
location = "global"
54+
}
55+
`, context)
56+
}
57+
58+
func testAccNetworkManagementOrganizationVpcFlowLogsConfig_update(context map[string]interface{}) string {
59+
return acctest.Nprintf(`
60+
resource "google_network_management_organization_vpc_flow_logs_config" "org-test-update" {
61+
provider = google-beta
62+
vpc_flow_logs_config_id = "tf-test-update-org-id-%{random_suffix}"
63+
organization = "%{org_id}"
64+
location = "global"
65+
66+
state = "DISABLED"
67+
aggregation_interval = "INTERVAL_30_SEC"
68+
description = "This is an updated description"
69+
flow_sampling = 0.5
70+
metadata = "EXCLUDE_ALL_METADATA"
71+
cross_project_metadata = "CROSS_PROJECT_METADATA_DISABLED"
72+
}
73+
`, context)
74+
}
75+
{{ end }}

0 commit comments

Comments
 (0)