|
| 1 | +// Copyright (c) HashiCorp, Inc. |
| 2 | +// SPDX-License-Identifier: MPL-2.0 |
| 3 | +// ---------------------------------------------------------------------------- |
| 4 | +// |
| 5 | +// *** AUTO GENERATED CODE *** Type: Handwritten *** |
| 6 | +// |
| 7 | +// ---------------------------------------------------------------------------- |
| 8 | +// |
| 9 | +// This code is generated by Magic Modules using the following: |
| 10 | +// |
| 11 | +// Source file: https://github.com/GoogleCloudPlatform/magic-modules/tree/main/mmv1/third_party/terraform/services/accesscontextmanager/data_source_access_context_manager_supported_service.go |
| 12 | +// |
| 13 | +// DO NOT EDIT this file directly. Any changes made to this file will be |
| 14 | +// overwritten during the next generation cycle. |
| 15 | +// |
| 16 | +// ---------------------------------------------------------------------------- |
| 17 | +package accesscontextmanager |
| 18 | + |
| 19 | +import ( |
| 20 | + "fmt" |
| 21 | + "net/http" |
| 22 | + |
| 23 | + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" |
| 24 | + "github.com/hashicorp/terraform-provider-google/google/tpgresource" |
| 25 | + transport_tpg "github.com/hashicorp/terraform-provider-google/google/transport" |
| 26 | +) |
| 27 | + |
| 28 | +func DataSourceAccessContextManagerSupportedService() *schema.Resource { |
| 29 | + return &schema.Resource{ |
| 30 | + Read: dataSourceAccessContextManagerSupportedServiceRead, |
| 31 | + Schema: map[string]*schema.Schema{ |
| 32 | + "service_name": { |
| 33 | + Type: schema.TypeString, |
| 34 | + Required: true, |
| 35 | + Description: "The name of the service to get information about. The names must be in the same format as used in defining a service perimeter, for example, `storage.googleapis.com`.", |
| 36 | + }, |
| 37 | + "title": { |
| 38 | + Type: schema.TypeString, |
| 39 | + Computed: true, |
| 40 | + Description: "The name of the supported product, such as 'Cloud Storage'.", |
| 41 | + }, |
| 42 | + "support_stage": { |
| 43 | + Type: schema.TypeString, |
| 44 | + Computed: true, |
| 45 | + Description: "The support stage of the service.", |
| 46 | + }, |
| 47 | + "available_on_restricted_vip": { |
| 48 | + Type: schema.TypeBool, |
| 49 | + Computed: true, |
| 50 | + Description: "True if the service is available on the restricted VIP. Services on the restricted VIP typically either support VPC Service Controls or are core infrastructure services required for the functioning of Google Cloud.", |
| 51 | + }, |
| 52 | + "known_limitations": { |
| 53 | + Type: schema.TypeBool, |
| 54 | + Computed: true, |
| 55 | + Description: "True if the service is supported with some limitations. Check documentation for details.", |
| 56 | + }, |
| 57 | + "service_support_stage": { |
| 58 | + Type: schema.TypeString, |
| 59 | + Computed: true, |
| 60 | + Description: "The support stage of the service. Values are `GA`, `PREVIEW`, and `DEPRECATED`.", |
| 61 | + }, |
| 62 | + "supported_methods": { |
| 63 | + Type: schema.TypeList, |
| 64 | + Computed: true, |
| 65 | + Description: "The list of supported methods for this service.", |
| 66 | + Elem: &schema.Resource{ |
| 67 | + Schema: map[string]*schema.Schema{ |
| 68 | + "method": { |
| 69 | + Type: schema.TypeString, |
| 70 | + Computed: true, |
| 71 | + Description: "A valid method name for the respective request mode. Must be a fully qualified name, for example, `storage.googleapis.com/BucketService.GetBucket`.", |
| 72 | + }, |
| 73 | + "permission": { |
| 74 | + Type: schema.TypeString, |
| 75 | + Computed: true, |
| 76 | + Description: "A valid Cloud IAM permission for the respective request mode, for example, `storage.buckets.get`.", |
| 77 | + }, |
| 78 | + }, |
| 79 | + }, |
| 80 | + }, |
| 81 | + }, |
| 82 | + } |
| 83 | +} |
| 84 | + |
| 85 | +func dataSourceAccessContextManagerSupportedServiceRead(d *schema.ResourceData, meta interface{}) error { |
| 86 | + config := meta.(*transport_tpg.Config) |
| 87 | + userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) |
| 88 | + if err != nil { |
| 89 | + return err |
| 90 | + } |
| 91 | + |
| 92 | + serviceName := d.Get("service_name").(string) |
| 93 | + urlRequest := fmt.Sprintf("%sservices/%s", config.AccessContextManagerBasePath, serviceName) |
| 94 | + |
| 95 | + headers := make(http.Header) |
| 96 | + res, err := transport_tpg.SendRequest(transport_tpg.SendRequestOptions{ |
| 97 | + Config: config, |
| 98 | + Method: "GET", |
| 99 | + RawURL: urlRequest, |
| 100 | + UserAgent: userAgent, |
| 101 | + Headers: headers, |
| 102 | + }) |
| 103 | + if err != nil { |
| 104 | + return fmt.Errorf("error reading Access Context Manager supported service %q: %s", serviceName, err) |
| 105 | + } |
| 106 | + |
| 107 | + getString := func(m map[string]interface{}, key string) string { |
| 108 | + if v, ok := m[key].(string); ok { |
| 109 | + return v |
| 110 | + } |
| 111 | + return "" |
| 112 | + } |
| 113 | + |
| 114 | + getBool := func(m map[string]interface{}, key string) bool { |
| 115 | + if v, ok := m[key].(bool); ok { |
| 116 | + return v |
| 117 | + } |
| 118 | + return false |
| 119 | + } |
| 120 | + |
| 121 | + if err := d.Set("title", getString(res, "title")); err != nil { |
| 122 | + return fmt.Errorf("error setting title: %s", err) |
| 123 | + } |
| 124 | + if err := d.Set("support_stage", getString(res, "supportStage")); err != nil { |
| 125 | + return fmt.Errorf("error setting support_stage: %s", err) |
| 126 | + } |
| 127 | + if err := d.Set("available_on_restricted_vip", getBool(res, "availableOnRestrictedVip")); err != nil { |
| 128 | + return fmt.Errorf("error setting available_on_restricted_vip: %s", err) |
| 129 | + } |
| 130 | + if err := d.Set("known_limitations", getBool(res, "knownLimitations")); err != nil { |
| 131 | + return fmt.Errorf("error setting known_limitations: %s", err) |
| 132 | + } |
| 133 | + if err := d.Set("service_support_stage", getString(res, "serviceSupportStage")); err != nil { |
| 134 | + return fmt.Errorf("error setting service_support_stage: %s", err) |
| 135 | + } |
| 136 | + |
| 137 | + supportedMethods := make([]map[string]interface{}, 0) |
| 138 | + if rawMethods, ok := res["supportedMethods"].([]interface{}); ok { |
| 139 | + for _, item := range rawMethods { |
| 140 | + method, ok := item.(map[string]interface{}) |
| 141 | + if !ok { |
| 142 | + continue |
| 143 | + } |
| 144 | + supportedMethods = append(supportedMethods, map[string]interface{}{ |
| 145 | + "method": getString(method, "method"), |
| 146 | + "permission": getString(method, "permission"), |
| 147 | + }) |
| 148 | + } |
| 149 | + } |
| 150 | + |
| 151 | + if err := d.Set("supported_methods", supportedMethods); err != nil { |
| 152 | + return fmt.Errorf("error setting supported_methods: %s", err) |
| 153 | + } |
| 154 | + |
| 155 | + d.SetId(fmt.Sprintf("accessContextManager/services/%s", serviceName)) |
| 156 | + |
| 157 | + return nil |
| 158 | +} |
0 commit comments