Skip to content

Commit 664fce2

Browse files
kigesuiMeng YangSirGitsalot
authored
adding feedback resource (#15886)
Co-authored-by: Meng Yang <[email protected]> Co-authored-by: Chris Hawk <[email protected]>
1 parent 0e36f17 commit 664fce2

File tree

4 files changed

+308
-0
lines changed

4 files changed

+308
-0
lines changed
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
# Copyright 2024 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: 'SecurityFeedback'
16+
description: |
17+
Represents a feedback report from an Advanced API Security customer.
18+
Manages customer feedback about ML models.
19+
references:
20+
guides:
21+
'Create a SecurityFeedback': 'https://docs.cloud.google.com/apigee/docs/api-security/abuse-detection#exclude-traffic-from-abuse-detection'
22+
api: 'https://cloud.google.com/apigee/docs/reference/apis/apigee/rest/v1/organizations.securityFeedback/create'
23+
base_url: '{{org_id}}/securityFeedback'
24+
self_link: '{{org_id}}/securityFeedback/{{feedback_id}}'
25+
create_url: '{{org_id}}/securityFeedback?security_feedback_id={{feedback_id}}'
26+
update_verb: 'PATCH'
27+
import_format:
28+
- '{{org_id}}/securityFeedback/{{feedback_id}}'
29+
- '{{org_id}}/{{feedback_id}}'
30+
custom_code:
31+
custom_import: "templates/terraform/custom_import/apigee_security_feedback.go.tmpl"
32+
examples:
33+
- name: 'apigee_security_feedback_basic'
34+
vars:
35+
security_feedback_id: 'my-feedback'
36+
exclude_test: true
37+
- name: 'apigee_security_feedback_basic_test'
38+
primary_resource_id: 'security_feedback'
39+
test_env_vars:
40+
org_id: 'ORG_ID'
41+
billing_account: 'BILLING_ACCT'
42+
exclude_docs: true
43+
external_providers: ["time"]
44+
parameters:
45+
- name: 'orgId'
46+
type: String
47+
description: |
48+
The Apigee Organization associated with the Apigee Security Feedback,
49+
in the format `organizations/{{org_name}}`.
50+
url_param_only: true
51+
required: true
52+
immutable: true
53+
- name: 'feedbackId'
54+
type: String
55+
description: |
56+
Resource ID of the security feedback.
57+
required: true
58+
immutable: true
59+
url_param_only: true
60+
properties:
61+
- name: 'name'
62+
type: String
63+
description: |
64+
Name of the security feedback resource,
65+
in the format `organizations/{{org_name}}/securityFeedback/{{feedback_id}}`.
66+
output: true
67+
- name: 'displayName'
68+
type: String
69+
description: The display name of the feedback.
70+
- name: 'feedbackContexts'
71+
type: Array
72+
description: |
73+
One or more attribute/value pairs for constraining the feedback.
74+
required: true
75+
item_type:
76+
type: NestedObject
77+
properties:
78+
- name: attribute
79+
type: Enum
80+
description: |
81+
The attribute the user is providing feedback about.
82+
required: true
83+
enum_values:
84+
- 'ATTRIBUTE_ENVIRONMENTS'
85+
- 'ATTRIBUTE_IP_ADDRESS_RANGES'
86+
- name: values
87+
type: Array
88+
description: |
89+
The values of the attribute the user is providing feedback about, separated by commas.
90+
required: true
91+
item_type:
92+
type: String
93+
- name: 'feedbackType'
94+
type: Enum
95+
description: The type of feedback being submitted.
96+
required: true
97+
enum_values:
98+
- 'EXCLUDED_DETECTION'
99+
- name: 'createTime'
100+
type: String
101+
description: The time when this specific feedback id was created.
102+
output: true
103+
- name: 'updateTime'
104+
type: String
105+
description: The time when this specific feedback id was updated.
106+
output: true
107+
- name: 'reason'
108+
type: Enum
109+
description: The reason for the feedback.
110+
enum_values:
111+
- 'INTERNAL_SYSTEM'
112+
- 'NON_RISK_CLIENT'
113+
- 'NAT'
114+
- 'PENETRATION_TEST'
115+
- 'OTHER'
116+
- name: 'comment'
117+
type: String
118+
description: Optional text the user can provide for additional, unstructured context.
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
config := meta.(*transport_tpg.Config)
2+
3+
// current import_formats cannot import fields with forward slashes in their value
4+
if err := tpgresource.ParseImportId([]string{"(?P<name>.+)"}, d, config); err != nil {
5+
return nil, err
6+
}
7+
8+
nameParts := strings.Split(d.Get("name").(string), "/")
9+
if len(nameParts) == 4 {
10+
// `organizations/{{"{{"}}org_name{{"}}"}}/securityFeedback/{{"{{"}}feedback_id{{"}}"}}`
11+
orgId := fmt.Sprintf("organizations/%s", nameParts[1])
12+
if err := d.Set("org_id", orgId); err != nil {
13+
return nil, fmt.Errorf("Error setting org_id: %s", err)
14+
}
15+
if err := d.Set("feedback_id", nameParts[3]); err != nil {
16+
return nil, fmt.Errorf("Error setting feedback_id: %s", err)
17+
}
18+
} else {
19+
return nil, fmt.Errorf(
20+
"Saw %s when the name is expected to have shape %s",
21+
d.Get("name"),
22+
"organizations/{{"{{"}}org_name{{"}}"}}/securityFeedback/{{"{{"}}name{{"}}"}}")
23+
}
24+
25+
// Replace import id for the resource id
26+
id, err := tpgresource.ReplaceVars(d, config, "{{"{{"}}org_id{{"}}"}}/securityFeedback/{{"{{"}}feedback_id{{"}}"}}")
27+
if err != nil {
28+
return nil, fmt.Errorf("Error constructing id: %s", err)
29+
}
30+
d.SetId(id)
31+
32+
return []*schema.ResourceData{d}, nil
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
data "google_client_config" "current" {}
2+
3+
resource "google_compute_network" "apigee_network" {
4+
name = "apigee-network"
5+
}
6+
7+
resource "google_compute_global_address" "apigee_range" {
8+
name = "apigee-range"
9+
purpose = "VPC_PEERING"
10+
address_type = "INTERNAL"
11+
prefix_length = 16
12+
network = google_compute_network.apigee_network.id
13+
}
14+
15+
resource "google_service_networking_connection" "apigee_vpc_connection" {
16+
network = google_compute_network.apigee_network.id
17+
service = "servicenetworking.googleapis.com"
18+
reserved_peering_ranges = [google_compute_global_address.apigee_range.name]
19+
}
20+
21+
resource "google_apigee_organization" "apigee_org" {
22+
analytics_region = "us-central1"
23+
project_id = data.google_client_config.current.project
24+
authorized_network = google_compute_network.apigee_network.id
25+
depends_on = [google_service_networking_connection.apigee_vpc_connection]
26+
}
27+
28+
resource "google_apigee_addons_config" "apigee_org_security_addons_config" {
29+
org = google_apigee_organization.apigee_org.name
30+
addons_config {
31+
api_security_config {
32+
enabled = true
33+
}
34+
}
35+
}
36+
37+
resource "google_apigee_security_feedback" "security_feedback" {
38+
feedback_id = "{{index $.Vars "security_feedback_id"}}"
39+
org_id = google_apigee_organization.apigee_org.id
40+
display_name = "terraform test display name"
41+
feedback_type = "EXCLUDED_DETECTION"
42+
reason = "INTERNAL_SYSTEM"
43+
comment = "terraform test comment"
44+
feedback_contexts {
45+
attribute = "ATTRIBUTE_ENVIRONMENTS"
46+
values = [google_apigee_environment.apigee_environment.name]
47+
}
48+
feedback_contexts {
49+
attribute = "ATTRIBUTE_IP_ADDRESS_RANGES"
50+
values = ["10.0.0.0", "172.16.0.0/12"]
51+
}
52+
depends_on = [
53+
google_apigee_addons_config.apigee_org_security_addons_config
54+
]
55+
}
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
resource "google_project" "project" {
2+
project_id = "tf-test%{random_suffix}"
3+
name = "tf-test%{random_suffix}"
4+
org_id = "{{index $.TestEnvVars "org_id"}}"
5+
billing_account = "{{index $.TestEnvVars "billing_account"}}"
6+
deletion_policy = "DELETE"
7+
}
8+
9+
resource "time_sleep" "wait_60_seconds" {
10+
create_duration = "60s"
11+
depends_on = [google_project.project]
12+
}
13+
14+
resource "google_project_service" "apigee" {
15+
project = google_project.project.project_id
16+
service = "apigee.googleapis.com"
17+
depends_on = [time_sleep.wait_60_seconds]
18+
}
19+
20+
resource "google_project_service" "servicenetworking" {
21+
project = google_project.project.project_id
22+
service = "servicenetworking.googleapis.com"
23+
depends_on = [google_project_service.apigee]
24+
}
25+
resource "time_sleep" "wait_120_seconds" {
26+
create_duration = "120s"
27+
depends_on = [google_project_service.servicenetworking]
28+
}
29+
resource "google_project_service" "compute" {
30+
project = google_project.project.project_id
31+
service = "compute.googleapis.com"
32+
depends_on = [google_project_service.servicenetworking]
33+
}
34+
35+
resource "google_compute_network" "apigee_network" {
36+
name = "apigee-network"
37+
project = google_project.project.project_id
38+
depends_on = [google_project_service.compute, time_sleep.wait_120_seconds]
39+
}
40+
41+
resource "google_compute_global_address" "apigee_range" {
42+
name = "apigee-range"
43+
purpose = "VPC_PEERING"
44+
address_type = "INTERNAL"
45+
prefix_length = 16
46+
network = google_compute_network.apigee_network.id
47+
project = google_project.project.project_id
48+
}
49+
50+
resource "google_service_networking_connection" "apigee_vpc_connection" {
51+
network = google_compute_network.apigee_network.id
52+
service = "servicenetworking.googleapis.com"
53+
reserved_peering_ranges = [google_compute_global_address.apigee_range.name]
54+
depends_on = [google_project_service.servicenetworking]
55+
}
56+
57+
resource "google_apigee_organization" "apigee_org" {
58+
analytics_region = "us-central1"
59+
project_id = google_project.project.project_id
60+
authorized_network = google_compute_network.apigee_network.id
61+
depends_on = [
62+
google_service_networking_connection.apigee_vpc_connection,
63+
google_project_service.apigee,
64+
]
65+
}
66+
67+
resource "google_apigee_environment" "apigee_environment" {
68+
org_id = google_apigee_organization.apigee_org.id
69+
name = "tf-test-env-%{random_suffix}"
70+
description = "Apigee Environment"
71+
display_name = "environment-1"
72+
}
73+
74+
resource "google_apigee_addons_config" "apigee_org_security_addons_config" {
75+
org = google_apigee_organization.apigee_org.name
76+
addons_config {
77+
api_security_config {
78+
enabled = true
79+
}
80+
}
81+
}
82+
83+
resource "google_apigee_security_feedback" "{{$.PrimaryResourceId}}" {
84+
org_id = google_apigee_organization.apigee_org.id
85+
feedback_id = "tf-test-feedback-id"
86+
display_name = "Exclude internal test systems"
87+
feedback_type = "EXCLUDED_DETECTION"
88+
reason = "INTERNAL_SYSTEM"
89+
comment = "Excluding IP ranges and environments used by internal QA."
90+
91+
feedback_contexts {
92+
attribute = "ATTRIBUTE_ENVIRONMENTS"
93+
values = [google_apigee_environment.apigee_environment.name]
94+
}
95+
feedback_contexts {
96+
attribute = "ATTRIBUTE_IP_ADDRESS_RANGES"
97+
values = ["10.0.0.0", "172.16.0.0/12"]
98+
}
99+
100+
depends_on = [
101+
google_apigee_addons_config.apigee_org_security_addons_config
102+
]
103+
}

0 commit comments

Comments
 (0)