Skip to content

Commit e6c249a

Browse files
Add StateReason to NCC Spoke (#13666) (#22525)
[upstream:7ffd4a868fbfc897396ea284edcbb20a48c8e5fb] Signed-off-by: Modular Magician <[email protected]>
1 parent 449ca27 commit e6c249a

File tree

4 files changed

+83
-0
lines changed

4 files changed

+83
-0
lines changed

.changelog/13666.txt

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:enhancement
2+
networkconnectivity: added `state_reason` field to `spoke` resource
3+
```

google/services/networkconnectivity/resource_network_connectivity_spoke.go

+59
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,30 @@ The only allowed value for now is "ALL_IPV4_RANGES".`,
309309
Description: `All of labels (key/value pairs) present on the resource in GCP, including the labels configured through Terraform, other clients and services.`,
310310
Elem: &schema.Schema{Type: schema.TypeString},
311311
},
312+
"reasons": {
313+
Type: schema.TypeList,
314+
Computed: true,
315+
Description: `The reasons for the current state in the lifecycle`,
316+
Elem: &schema.Resource{
317+
Schema: map[string]*schema.Schema{
318+
"code": {
319+
Type: schema.TypeString,
320+
Optional: true,
321+
Description: `The code associated with this reason.`,
322+
},
323+
"message": {
324+
Type: schema.TypeString,
325+
Optional: true,
326+
Description: `Human-readable details about this reason.`,
327+
},
328+
"user_details": {
329+
Type: schema.TypeString,
330+
Optional: true,
331+
Description: `Additional information provided by the user in the RejectSpoke call.`,
332+
},
333+
},
334+
},
335+
},
312336
"state": {
313337
Type: schema.TypeString,
314338
Computed: true,
@@ -552,6 +576,9 @@ func resourceNetworkConnectivitySpokeRead(d *schema.ResourceData, meta interface
552576
if err := d.Set("state", flattenNetworkConnectivitySpokeState(res["state"], d, config)); err != nil {
553577
return fmt.Errorf("Error reading Spoke: %s", err)
554578
}
579+
if err := d.Set("reasons", flattenNetworkConnectivitySpokeReasons(res["reasons"], d, config)); err != nil {
580+
return fmt.Errorf("Error reading Spoke: %s", err)
581+
}
555582
if err := d.Set("terraform_labels", flattenNetworkConnectivitySpokeTerraformLabels(res["labels"], d, config)); err != nil {
556583
return fmt.Errorf("Error reading Spoke: %s", err)
557584
}
@@ -987,6 +1014,38 @@ func flattenNetworkConnectivitySpokeState(v interface{}, d *schema.ResourceData,
9871014
return v
9881015
}
9891016

1017+
func flattenNetworkConnectivitySpokeReasons(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
1018+
if v == nil {
1019+
return v
1020+
}
1021+
l := v.([]interface{})
1022+
transformed := make([]interface{}, 0, len(l))
1023+
for _, raw := range l {
1024+
original := raw.(map[string]interface{})
1025+
if len(original) < 1 {
1026+
// Do not include empty json objects coming back from the api
1027+
continue
1028+
}
1029+
transformed = append(transformed, map[string]interface{}{
1030+
"code": flattenNetworkConnectivitySpokeReasonsCode(original["code"], d, config),
1031+
"message": flattenNetworkConnectivitySpokeReasonsMessage(original["message"], d, config),
1032+
"user_details": flattenNetworkConnectivitySpokeReasonsUserDetails(original["userDetails"], d, config),
1033+
})
1034+
}
1035+
return transformed
1036+
}
1037+
func flattenNetworkConnectivitySpokeReasonsCode(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
1038+
return v
1039+
}
1040+
1041+
func flattenNetworkConnectivitySpokeReasonsMessage(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
1042+
return v
1043+
}
1044+
1045+
func flattenNetworkConnectivitySpokeReasonsUserDetails(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
1046+
return v
1047+
}
1048+
9901049
func flattenNetworkConnectivitySpokeTerraformLabels(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
9911050
if v == nil {
9921051
return v

google/services/networkconnectivity/resource_network_connectivity_spoke_generated_meta.yaml

+3
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ fields:
3333
- field: 'location'
3434
provider_only: true
3535
- field: 'name'
36+
- field: 'reasons.code'
37+
- field: 'reasons.message'
38+
- field: 'reasons.user_details'
3639
- field: 'state'
3740
- field: 'terraform_labels'
3841
provider_only: true

website/docs/r/network_connectivity_spoke.html.markdown

+18
Original file line numberDiff line numberDiff line change
@@ -707,6 +707,10 @@ In addition to the arguments listed above, the following computed attributes are
707707
* `state` -
708708
Output only. The current lifecycle state of this spoke.
709709

710+
* `reasons` -
711+
The reasons for the current state in the lifecycle
712+
Structure is [documented below](#nested_reasons).
713+
710714
* `terraform_labels` -
711715
The combination of labels configured directly on the resource
712716
and default labels configured on the provider.
@@ -715,6 +719,20 @@ In addition to the arguments listed above, the following computed attributes are
715719
All of labels (key/value pairs) present on the resource in GCP, including the labels configured through Terraform, other clients and services.
716720

717721

722+
<a name="nested_reasons"></a>The `reasons` block contains:
723+
724+
* `code` -
725+
(Optional)
726+
The code associated with this reason.
727+
728+
* `message` -
729+
(Optional)
730+
Human-readable details about this reason.
731+
732+
* `user_details` -
733+
(Optional)
734+
Additional information provided by the user in the RejectSpoke call.
735+
718736
## Timeouts
719737

720738
This resource provides the following

0 commit comments

Comments
 (0)