|
| 1 | +/* |
| 2 | +Use this data source to query detailed information of cam oidc_config |
| 3 | +
|
| 4 | +Example Usage |
| 5 | +
|
| 6 | +```hcl |
| 7 | +data "tencentcloud_cam_oidc_config" "oidc_config" { |
| 8 | + name = "cls-kzilgv5m" |
| 9 | +} |
| 10 | +
|
| 11 | +output "identity_key" { |
| 12 | + value = data.tencentcloud_cam_oidc_config.oidc_config.identity_key |
| 13 | +} |
| 14 | +
|
| 15 | +output "identity_url" { |
| 16 | + value = data.tencentcloud_cam_oidc_config.oidc_config.identity_url |
| 17 | +} |
| 18 | +
|
| 19 | +``` |
| 20 | +*/ |
| 21 | +package tencentcloud |
| 22 | + |
| 23 | +import ( |
| 24 | + "log" |
| 25 | + |
| 26 | + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" |
| 27 | + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" |
| 28 | + cam "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cam/v20190116" |
| 29 | + "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/internal/helper" |
| 30 | +) |
| 31 | + |
| 32 | +func dataSourceTencentCloudCamOidcConfig() *schema.Resource { |
| 33 | + return &schema.Resource{ |
| 34 | + Read: dataSourceTencentCloudCamOidcConfigRead, |
| 35 | + Schema: map[string]*schema.Schema{ |
| 36 | + "name": { |
| 37 | + Required: true, |
| 38 | + Type: schema.TypeString, |
| 39 | + Description: "Name.", |
| 40 | + }, |
| 41 | + |
| 42 | + "provider_type": { |
| 43 | + Computed: true, |
| 44 | + Type: schema.TypeInt, |
| 45 | + Description: "IdP type. 11: Role IdP.", |
| 46 | + }, |
| 47 | + |
| 48 | + "identity_url": { |
| 49 | + Computed: true, |
| 50 | + Type: schema.TypeString, |
| 51 | + Description: "IdP URL.", |
| 52 | + }, |
| 53 | + |
| 54 | + "identity_key": { |
| 55 | + Computed: true, |
| 56 | + Type: schema.TypeString, |
| 57 | + Description: "Public key for signature.", |
| 58 | + }, |
| 59 | + |
| 60 | + "client_id": { |
| 61 | + Computed: true, |
| 62 | + Type: schema.TypeSet, |
| 63 | + Elem: &schema.Schema{ |
| 64 | + Type: schema.TypeString, |
| 65 | + }, |
| 66 | + Description: "Client ID.", |
| 67 | + }, |
| 68 | + |
| 69 | + "status": { |
| 70 | + Computed: true, |
| 71 | + Type: schema.TypeInt, |
| 72 | + Description: "Status. 0: Not set; 2: Disabled; 11: Enabled.", |
| 73 | + }, |
| 74 | + |
| 75 | + "description": { |
| 76 | + Computed: true, |
| 77 | + Type: schema.TypeString, |
| 78 | + Description: "Description.", |
| 79 | + }, |
| 80 | + |
| 81 | + "result_output_file": { |
| 82 | + Type: schema.TypeString, |
| 83 | + Optional: true, |
| 84 | + Description: "Used to save results.", |
| 85 | + }, |
| 86 | + }, |
| 87 | + } |
| 88 | +} |
| 89 | + |
| 90 | +func dataSourceTencentCloudCamOidcConfigRead(d *schema.ResourceData, meta interface{}) error { |
| 91 | + defer logElapsed("data_source.tencentcloud_cam_oidc_config.read")() |
| 92 | + defer inconsistentCheck(d, meta)() |
| 93 | + |
| 94 | + logId := getLogId(contextNil) |
| 95 | + var name string |
| 96 | + result := make(map[string]interface{}) |
| 97 | + |
| 98 | + request := cam.NewDescribeOIDCConfigRequest() |
| 99 | + |
| 100 | + if v, ok := d.GetOk("name"); ok { |
| 101 | + name = v.(string) |
| 102 | + request.Name = helper.String(v.(string)) |
| 103 | + } |
| 104 | + |
| 105 | + var response *cam.DescribeOIDCConfigResponse |
| 106 | + err := resource.Retry(readRetryTimeout, func() *resource.RetryError { |
| 107 | + result, e := meta.(*TencentCloudClient).apiV3Conn.UseCamClient().DescribeOIDCConfig(request) |
| 108 | + if e != nil { |
| 109 | + return retryError(e) |
| 110 | + } |
| 111 | + response = result |
| 112 | + return nil |
| 113 | + }) |
| 114 | + if err != nil { |
| 115 | + log.Printf("[CRITAL]%s read CAM role SSO failed, reason:%s\n", logId, err.Error()) |
| 116 | + return err |
| 117 | + } |
| 118 | + |
| 119 | + if response.Response.ProviderType != nil { |
| 120 | + _ = d.Set("provider_type", response.Response.ProviderType) |
| 121 | + result["provider_type"] = response.Response.ProviderType |
| 122 | + } |
| 123 | + |
| 124 | + if response.Response.IdentityUrl != nil { |
| 125 | + _ = d.Set("identity_url", response.Response.IdentityUrl) |
| 126 | + result["identity_url"] = response.Response.IdentityUrl |
| 127 | + } |
| 128 | + |
| 129 | + if response.Response.IdentityKey != nil { |
| 130 | + _ = d.Set("identity_key", response.Response.IdentityKey) |
| 131 | + result["identity_key"] = response.Response.IdentityKey |
| 132 | + } |
| 133 | + |
| 134 | + if response.Response.ClientId != nil { |
| 135 | + _ = d.Set("client_id", response.Response.ClientId) |
| 136 | + result["client_id"] = response.Response.ClientId |
| 137 | + } |
| 138 | + |
| 139 | + if response.Response.Status != nil { |
| 140 | + _ = d.Set("status", response.Response.Status) |
| 141 | + result["status"] = response.Response.Status |
| 142 | + } |
| 143 | + |
| 144 | + if response.Response.Description != nil { |
| 145 | + _ = d.Set("description", response.Response.Description) |
| 146 | + result["description"] = response.Response.Description |
| 147 | + } |
| 148 | + |
| 149 | + d.SetId(name) |
| 150 | + output, ok := d.GetOk("result_output_file") |
| 151 | + if ok && output.(string) != "" { |
| 152 | + if e := writeToFile(output.(string), result); e != nil { |
| 153 | + return e |
| 154 | + } |
| 155 | + } |
| 156 | + return nil |
| 157 | +} |
0 commit comments