|
| 1 | +package tco |
| 2 | + |
| 3 | +import ( |
| 4 | + "context" |
| 5 | + |
| 6 | + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" |
| 7 | + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" |
| 8 | + organization "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/organization/v20210331" |
| 9 | + |
| 10 | + tccommon "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/common" |
| 11 | + "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/internal/helper" |
| 12 | +) |
| 13 | + |
| 14 | +func DataSourceTencentCloudRoleConfigurationProvisionings() *schema.Resource { |
| 15 | + return &schema.Resource{ |
| 16 | + Read: dataSourceTencentCloudRoleConfigurationProvisioningsRead, |
| 17 | + Schema: map[string]*schema.Schema{ |
| 18 | + "zone_id": { |
| 19 | + Type: schema.TypeString, |
| 20 | + Required: true, |
| 21 | + Description: "Space ID.", |
| 22 | + }, |
| 23 | + |
| 24 | + "role_configuration_id": { |
| 25 | + Type: schema.TypeString, |
| 26 | + Optional: true, |
| 27 | + Description: "Permission configuration ID.", |
| 28 | + }, |
| 29 | + |
| 30 | + "target_type": { |
| 31 | + Type: schema.TypeString, |
| 32 | + Optional: true, |
| 33 | + Description: "Type of the synchronized target account of the Tencent Cloud Organization. ManagerUin: admin account; MemberUin: member account.", |
| 34 | + }, |
| 35 | + |
| 36 | + "target_uin": { |
| 37 | + Type: schema.TypeInt, |
| 38 | + Optional: true, |
| 39 | + Description: "UIN of the synchronized target account of the Tencent Cloud Organization.", |
| 40 | + }, |
| 41 | + |
| 42 | + "deployment_status": { |
| 43 | + Type: schema.TypeString, |
| 44 | + Optional: true, |
| 45 | + Description: "Deployed: Deployment succeeded; DeployedRequired: Redeployment required; DeployFailed: Deployment failed.", |
| 46 | + }, |
| 47 | + |
| 48 | + "filter": { |
| 49 | + Type: schema.TypeString, |
| 50 | + Optional: true, |
| 51 | + Description: "Search by configuration name is supported.", |
| 52 | + }, |
| 53 | + |
| 54 | + "role_configuration_provisionings": { |
| 55 | + Type: schema.TypeList, |
| 56 | + Computed: true, |
| 57 | + Description: "Department member account list.", |
| 58 | + Elem: &schema.Resource{ |
| 59 | + Schema: map[string]*schema.Schema{ |
| 60 | + "deployment_status": { |
| 61 | + Type: schema.TypeString, |
| 62 | + Optional: true, |
| 63 | + Description: "Deployed: Deployment succeeded; DeployedRequired: Redeployment required; DeployFailed: Deployment failed.", |
| 64 | + }, |
| 65 | + "role_configuration_id": { |
| 66 | + Type: schema.TypeString, |
| 67 | + Optional: true, |
| 68 | + Description: "Permission configuration ID.", |
| 69 | + }, |
| 70 | + "role_configuration_name": { |
| 71 | + Type: schema.TypeString, |
| 72 | + Optional: true, |
| 73 | + Description: "Permission configuration name.", |
| 74 | + }, |
| 75 | + "target_uin": { |
| 76 | + Type: schema.TypeInt, |
| 77 | + Optional: true, |
| 78 | + Description: "UIN of the target account of the Tencent Cloud Organization.", |
| 79 | + }, |
| 80 | + "target_name": { |
| 81 | + Type: schema.TypeString, |
| 82 | + Optional: true, |
| 83 | + Description: "Name of the target account of the Tencent Cloud Organization.", |
| 84 | + }, |
| 85 | + "create_time": { |
| 86 | + Type: schema.TypeString, |
| 87 | + Optional: true, |
| 88 | + Description: "Creation time.", |
| 89 | + }, |
| 90 | + "update_time": { |
| 91 | + Type: schema.TypeString, |
| 92 | + Optional: true, |
| 93 | + Description: "Modification time.", |
| 94 | + }, |
| 95 | + "target_type": { |
| 96 | + Type: schema.TypeString, |
| 97 | + Optional: true, |
| 98 | + Description: "Type of the synchronized target account of the Tencent Cloud Organization. ManagerUin: admin account; MemberUin: member account.", |
| 99 | + }, |
| 100 | + }, |
| 101 | + }, |
| 102 | + }, |
| 103 | + |
| 104 | + "result_output_file": { |
| 105 | + Type: schema.TypeString, |
| 106 | + Optional: true, |
| 107 | + Description: "Used to save results.", |
| 108 | + }, |
| 109 | + }, |
| 110 | + } |
| 111 | +} |
| 112 | + |
| 113 | +func dataSourceTencentCloudRoleConfigurationProvisioningsRead(d *schema.ResourceData, meta interface{}) error { |
| 114 | + defer tccommon.LogElapsed("data_source.tencentcloud_role_configuration_provisionings.read")() |
| 115 | + defer tccommon.InconsistentCheck(d, meta)() |
| 116 | + |
| 117 | + logId := tccommon.GetLogId(nil) |
| 118 | + ctx := tccommon.NewResourceLifeCycleHandleFuncContext(context.Background(), logId, d, meta) |
| 119 | + |
| 120 | + service := OrganizationService{client: meta.(tccommon.ProviderMeta).GetAPIV3Conn()} |
| 121 | + |
| 122 | + paramMap := make(map[string]interface{}) |
| 123 | + if v, ok := d.GetOk("zone_id"); ok { |
| 124 | + paramMap["ZoneId"] = helper.String(v.(string)) |
| 125 | + } |
| 126 | + |
| 127 | + if v, ok := d.GetOk("role_configuration_id"); ok { |
| 128 | + paramMap["RoleConfigurationId"] = helper.String(v.(string)) |
| 129 | + } |
| 130 | + |
| 131 | + if v, ok := d.GetOk("target_type"); ok { |
| 132 | + paramMap["TargetType"] = helper.String(v.(string)) |
| 133 | + } |
| 134 | + |
| 135 | + if v, ok := d.GetOkExists("target_uin"); ok { |
| 136 | + paramMap["TargetUin"] = helper.IntInt64(v.(int)) |
| 137 | + } |
| 138 | + |
| 139 | + if v, ok := d.GetOk("deployment_status"); ok { |
| 140 | + paramMap["DeploymentStatus"] = helper.String(v.(string)) |
| 141 | + } |
| 142 | + |
| 143 | + if v, ok := d.GetOk("filter"); ok { |
| 144 | + paramMap["Filter"] = helper.String(v.(string)) |
| 145 | + } |
| 146 | + |
| 147 | + var roleConfigurationProvisionings []*organization.RoleConfigurationProvisionings |
| 148 | + err := resource.Retry(tccommon.ReadRetryTimeout, func() *resource.RetryError { |
| 149 | + result, e := service.DescribeRoleConfigurationProvisioningsByFilter(ctx, paramMap) |
| 150 | + if e != nil { |
| 151 | + return tccommon.RetryError(e) |
| 152 | + } |
| 153 | + roleConfigurationProvisionings = result |
| 154 | + return nil |
| 155 | + }) |
| 156 | + if err != nil { |
| 157 | + return err |
| 158 | + } |
| 159 | + |
| 160 | + var ids []string |
| 161 | + roleConfigurationProvisioningsList := make([]map[string]interface{}, 0, len(roleConfigurationProvisionings)) |
| 162 | + if roleConfigurationProvisionings != nil { |
| 163 | + for _, roleConfigurationProvisionings := range roleConfigurationProvisionings { |
| 164 | + roleConfigurationProvisioningsMap := map[string]interface{}{} |
| 165 | + |
| 166 | + var roleConfigurationId string |
| 167 | + if roleConfigurationProvisionings.DeploymentStatus != nil { |
| 168 | + roleConfigurationProvisioningsMap["deployment_status"] = roleConfigurationProvisionings.DeploymentStatus |
| 169 | + } |
| 170 | + |
| 171 | + if roleConfigurationProvisionings.RoleConfigurationId != nil { |
| 172 | + roleConfigurationProvisioningsMap["role_configuration_id"] = roleConfigurationProvisionings.RoleConfigurationId |
| 173 | + roleConfigurationId = *roleConfigurationProvisionings.RoleConfigurationId |
| 174 | + } |
| 175 | + |
| 176 | + if roleConfigurationProvisionings.RoleConfigurationName != nil { |
| 177 | + roleConfigurationProvisioningsMap["role_configuration_name"] = roleConfigurationProvisionings.RoleConfigurationName |
| 178 | + } |
| 179 | + |
| 180 | + if roleConfigurationProvisionings.TargetUin != nil { |
| 181 | + roleConfigurationProvisioningsMap["target_uin"] = roleConfigurationProvisionings.TargetUin |
| 182 | + } |
| 183 | + |
| 184 | + if roleConfigurationProvisionings.TargetName != nil { |
| 185 | + roleConfigurationProvisioningsMap["target_name"] = roleConfigurationProvisionings.TargetName |
| 186 | + } |
| 187 | + |
| 188 | + if roleConfigurationProvisionings.CreateTime != nil { |
| 189 | + roleConfigurationProvisioningsMap["create_time"] = roleConfigurationProvisionings.CreateTime |
| 190 | + } |
| 191 | + |
| 192 | + if roleConfigurationProvisionings.UpdateTime != nil { |
| 193 | + roleConfigurationProvisioningsMap["update_time"] = roleConfigurationProvisionings.UpdateTime |
| 194 | + } |
| 195 | + |
| 196 | + if roleConfigurationProvisionings.TargetType != nil { |
| 197 | + roleConfigurationProvisioningsMap["target_type"] = roleConfigurationProvisionings.TargetType |
| 198 | + } |
| 199 | + |
| 200 | + ids = append(ids, roleConfigurationId) |
| 201 | + roleConfigurationProvisioningsList = append(roleConfigurationProvisioningsList, roleConfigurationProvisioningsMap) |
| 202 | + } |
| 203 | + |
| 204 | + _ = d.Set("role_configuration_provisionings", roleConfigurationProvisioningsList) |
| 205 | + } |
| 206 | + |
| 207 | + d.SetId(helper.DataResourceIdsHash(ids)) |
| 208 | + |
| 209 | + output, ok := d.GetOk("result_output_file") |
| 210 | + if ok && output.(string) != "" { |
| 211 | + if e := tccommon.WriteToFile(output.(string), d); e != nil { |
| 212 | + return e |
| 213 | + } |
| 214 | + } |
| 215 | + |
| 216 | + return nil |
| 217 | +} |
0 commit comments