Skip to content

Commit 8513ae0

Browse files
apigee: add access_logging_config support for google_apigee_instance (#14410) (#23522)
[upstream:2cd585e56bba61bf072a843e3ebeee26b90f7639] Signed-off-by: Modular Magician <magic-modules@google.com>
1 parent fb4c9e8 commit 8513ae0

File tree

5 files changed

+134
-0
lines changed

5 files changed

+134
-0
lines changed

.changelog/14410.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:enhancement
2+
apigee: add `access_logging_config` field to `google_apigee_instance`
3+
```

google/services/apigee/resource_apigee_instance.go

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,30 @@ func ResourceApigeeInstance() *schema.Resource {
9595
Description: `The Apigee Organization associated with the Apigee instance,
9696
in the format 'organizations/{{org_name}}'.`,
9797
},
98+
"access_logging_config": {
99+
Type: schema.TypeList,
100+
Optional: true,
101+
Description: `Access logging configuration enables the access logging feature at the instance.
102+
Apigee customers can enable access logging to ship the access logs to their own project's cloud logging.`,
103+
MaxItems: 1,
104+
Elem: &schema.Resource{
105+
Schema: map[string]*schema.Schema{
106+
"enabled": {
107+
Type: schema.TypeBool,
108+
Required: true,
109+
Description: `Boolean flag that specifies whether the customer access log feature is enabled.`,
110+
},
111+
"filter": {
112+
Type: schema.TypeString,
113+
Optional: true,
114+
Description: `Ship the access log entries that match the statusCode defined in the filter.
115+
The statusCode is the only expected/supported filter field. (Ex: statusCode)
116+
The filter will parse it to the Common Expression Language semantics for expression
117+
evaluation to build the filter condition. (Ex: "filter": statusCode >= 200 && statusCode < 300 )`,
118+
},
119+
},
120+
},
121+
},
98122
"consumer_accept_list": {
99123
Type: schema.TypeList,
100124
Computed: true,
@@ -225,6 +249,12 @@ func resourceApigeeInstanceCreate(d *schema.ResourceData, meta interface{}) erro
225249
} else if v, ok := d.GetOkExists("consumer_accept_list"); !tpgresource.IsEmptyValue(reflect.ValueOf(consumerAcceptListProp)) && (ok || !reflect.DeepEqual(v, consumerAcceptListProp)) {
226250
obj["consumerAcceptList"] = consumerAcceptListProp
227251
}
252+
accessLoggingConfigProp, err := expandApigeeInstanceAccessLoggingConfig(d.Get("access_logging_config"), d, config)
253+
if err != nil {
254+
return err
255+
} else if v, ok := d.GetOkExists("access_logging_config"); !tpgresource.IsEmptyValue(reflect.ValueOf(accessLoggingConfigProp)) && (ok || !reflect.DeepEqual(v, accessLoggingConfigProp)) {
256+
obj["accessLoggingConfig"] = accessLoggingConfigProp
257+
}
228258

229259
lockName, err := tpgresource.ReplaceVars(d, config, "{{org_id}}/apigeeInstances")
230260
if err != nil {
@@ -347,6 +377,9 @@ func resourceApigeeInstanceRead(d *schema.ResourceData, meta interface{}) error
347377
if err := d.Set("service_attachment", flattenApigeeInstanceServiceAttachment(res["serviceAttachment"], d, config)); err != nil {
348378
return fmt.Errorf("Error reading Instance: %s", err)
349379
}
380+
if err := d.Set("access_logging_config", flattenApigeeInstanceAccessLoggingConfig(res["accessLoggingConfig"], d, config)); err != nil {
381+
return fmt.Errorf("Error reading Instance: %s", err)
382+
}
350383

351384
return nil
352385
}
@@ -367,6 +400,12 @@ func resourceApigeeInstanceUpdate(d *schema.ResourceData, meta interface{}) erro
367400
} else if v, ok := d.GetOkExists("consumer_accept_list"); !tpgresource.IsEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, consumerAcceptListProp)) {
368401
obj["consumerAcceptList"] = consumerAcceptListProp
369402
}
403+
accessLoggingConfigProp, err := expandApigeeInstanceAccessLoggingConfig(d.Get("access_logging_config"), d, config)
404+
if err != nil {
405+
return err
406+
} else if v, ok := d.GetOkExists("access_logging_config"); !tpgresource.IsEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, accessLoggingConfigProp)) {
407+
obj["accessLoggingConfig"] = accessLoggingConfigProp
408+
}
370409

371410
lockName, err := tpgresource.ReplaceVars(d, config, "{{org_id}}/apigeeInstances")
372411
if err != nil {
@@ -387,6 +426,10 @@ func resourceApigeeInstanceUpdate(d *schema.ResourceData, meta interface{}) erro
387426
if d.HasChange("consumer_accept_list") {
388427
updateMask = append(updateMask, "consumerAcceptList")
389428
}
429+
430+
if d.HasChange("access_logging_config") {
431+
updateMask = append(updateMask, "accessLoggingConfig")
432+
}
390433
// updateMask is a URL parameter but not present in the schema, so ReplaceVars
391434
// won't set it
392435
url, err = transport_tpg.AddQueryParams(url, map[string]string{"updateMask": strings.Join(updateMask, ",")})
@@ -574,6 +617,29 @@ func flattenApigeeInstanceServiceAttachment(v interface{}, d *schema.ResourceDat
574617
return v
575618
}
576619

620+
func flattenApigeeInstanceAccessLoggingConfig(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
621+
if v == nil {
622+
return nil
623+
}
624+
original := v.(map[string]interface{})
625+
if len(original) == 0 {
626+
return nil
627+
}
628+
transformed := make(map[string]interface{})
629+
transformed["enabled"] =
630+
flattenApigeeInstanceAccessLoggingConfigEnabled(original["enabled"], d, config)
631+
transformed["filter"] =
632+
flattenApigeeInstanceAccessLoggingConfigFilter(original["filter"], d, config)
633+
return []interface{}{transformed}
634+
}
635+
func flattenApigeeInstanceAccessLoggingConfigEnabled(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
636+
return v
637+
}
638+
639+
func flattenApigeeInstanceAccessLoggingConfigFilter(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
640+
return v
641+
}
642+
577643
func expandApigeeInstanceName(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
578644
return v, nil
579645
}
@@ -605,3 +671,37 @@ func expandApigeeInstanceDiskEncryptionKeyName(v interface{}, d tpgresource.Terr
605671
func expandApigeeInstanceConsumerAcceptList(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
606672
return v, nil
607673
}
674+
675+
func expandApigeeInstanceAccessLoggingConfig(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
676+
l := v.([]interface{})
677+
if len(l) == 0 || l[0] == nil {
678+
return nil, nil
679+
}
680+
raw := l[0]
681+
original := raw.(map[string]interface{})
682+
transformed := make(map[string]interface{})
683+
684+
transformedEnabled, err := expandApigeeInstanceAccessLoggingConfigEnabled(original["enabled"], d, config)
685+
if err != nil {
686+
return nil, err
687+
} else if val := reflect.ValueOf(transformedEnabled); val.IsValid() && !tpgresource.IsEmptyValue(val) {
688+
transformed["enabled"] = transformedEnabled
689+
}
690+
691+
transformedFilter, err := expandApigeeInstanceAccessLoggingConfigFilter(original["filter"], d, config)
692+
if err != nil {
693+
return nil, err
694+
} else if val := reflect.ValueOf(transformedFilter); val.IsValid() && !tpgresource.IsEmptyValue(val) {
695+
transformed["filter"] = transformedFilter
696+
}
697+
698+
return transformed, nil
699+
}
700+
701+
func expandApigeeInstanceAccessLoggingConfigEnabled(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
702+
return v, nil
703+
}
704+
705+
func expandApigeeInstanceAccessLoggingConfigFilter(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
706+
return v, nil
707+
}

google/services/apigee/resource_apigee_instance_generated_meta.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ api_service_name: 'apigee.googleapis.com'
55
api_version: 'v1'
66
api_resource_type_kind: 'Instance'
77
fields:
8+
- field: 'access_logging_config.enabled'
9+
- field: 'access_logging_config.filter'
810
- field: 'consumer_accept_list'
911
- field: 'description'
1012
- field: 'disk_encryption_key_name'

google/services/apigee/resource_apigee_instance_update_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,11 @@ resource "google_apigee_instance" "apigee_instance" {
136136
consumer_accept_list = [
137137
google_project.project1.project_id,
138138
]
139+
140+
access_logging_config {
141+
enabled = false,
142+
filter = "status_code >= 0 && status_code < 600"
143+
}
139144
}
140145
`, context)
141146
}
@@ -220,6 +225,11 @@ resource "google_apigee_instance" "apigee_instance" {
220225
google_project.project1.project_id,
221226
google_project.project2.project_id,
222227
]
228+
229+
access_logging_config {
230+
enabled = true,
231+
filter = "status_code >= 200 && status_code < 300"
232+
}
223233
}
224234
`, context)
225235
}

website/docs/r/apigee_instance.html.markdown

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,26 @@ The following arguments are supported:
272272
which the customers can provide during the instance creation. By default, the customer
273273
project associated with the Apigee organization will be included to the list.
274274

275+
* `access_logging_config` -
276+
(Optional)
277+
Access logging configuration enables the access logging feature at the instance.
278+
Apigee customers can enable access logging to ship the access logs to their own project's cloud logging.
279+
Structure is [documented below](#nested_access_logging_config).
280+
281+
282+
283+
<a name="nested_access_logging_config"></a>The `access_logging_config` block supports:
275284

285+
* `enabled` -
286+
(Required)
287+
Boolean flag that specifies whether the customer access log feature is enabled.
288+
289+
* `filter` -
290+
(Optional)
291+
Ship the access log entries that match the statusCode defined in the filter.
292+
The statusCode is the only expected/supported filter field. (Ex: statusCode)
293+
The filter will parse it to the Common Expression Language semantics for expression
294+
evaluation to build the filter condition. (Ex: "filter": statusCode >= 200 && statusCode < 300 )
276295

277296
## Attributes Reference
278297

0 commit comments

Comments
 (0)