|
| 1 | +package controlcenter |
| 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 | + controlcenterv20230110 "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/controlcenter/v20230110" |
| 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 DataSourceTencentCloudControlcenterAccountFactoryBaselineItems() *schema.Resource { |
| 15 | + return &schema.Resource{ |
| 16 | + Read: dataSourceTencentCloudControlcenterAccountFactoryBaselineItemsRead, |
| 17 | + Schema: map[string]*schema.Schema{ |
| 18 | + "baseline_items": { |
| 19 | + Type: schema.TypeList, |
| 20 | + Computed: true, |
| 21 | + Description: "Account factory baseline list.", |
| 22 | + Elem: &schema.Resource{ |
| 23 | + Schema: map[string]*schema.Schema{ |
| 24 | + "identifier": { |
| 25 | + Type: schema.TypeString, |
| 26 | + Computed: true, |
| 27 | + Description: "Specifies the unique identifier for account factory baseline item, can only contain `english letters`, `digits`, and `@,._[]-:()()[]+=.`, with a length of 2-128 characters.", |
| 28 | + }, |
| 29 | + "name": { |
| 30 | + Type: schema.TypeString, |
| 31 | + Computed: true, |
| 32 | + Description: "Baseline item name. specifies a unique name for the feature item. supports a combination of english letters, numbers, chinese characters, and symbols @, &, _, [, ], -. valid values: 1-25 chinese or english characters.", |
| 33 | + }, |
| 34 | + "name_en": { |
| 35 | + Type: schema.TypeString, |
| 36 | + Computed: true, |
| 37 | + Description: "Baseline item english name. specifies a unique name for the baseline item. supports a combination of english letters, digits, spaces, and symbols @, &, _, [], -. valid values: 1-64 english characters.", |
| 38 | + }, |
| 39 | + "weight": { |
| 40 | + Type: schema.TypeInt, |
| 41 | + Computed: true, |
| 42 | + Description: "Baseline item weight. the smaller the value, the higher the weight. value range equal to or greater than 0.", |
| 43 | + }, |
| 44 | + "required": { |
| 45 | + Type: schema.TypeInt, |
| 46 | + Computed: true, |
| 47 | + Description: "Specifies whether the baseline item is required (1: required; 0: optional).", |
| 48 | + }, |
| 49 | + "depends_on": { |
| 50 | + Type: schema.TypeList, |
| 51 | + Computed: true, |
| 52 | + Description: "Baseline item dependency. value range of N depends on the count of other baseline items it relies on.", |
| 53 | + Elem: &schema.Resource{ |
| 54 | + Schema: map[string]*schema.Schema{ |
| 55 | + "type": { |
| 56 | + Type: schema.TypeString, |
| 57 | + Computed: true, |
| 58 | + Description: "Dependency type. valid values: LandingZoneSetUp or AccountFactorySetUp. LandingZoneSetUp refers to the dependency of landingZone. AccountFactorySetUp refers to the dependency of account factory.", |
| 59 | + }, |
| 60 | + "identifier": { |
| 61 | + Type: schema.TypeString, |
| 62 | + Computed: true, |
| 63 | + Description: "Specifies the unique identifier for the feature item, can only contain `english letters`, `digits`, and `@,._[]-:()()[]+=.`, with a length of 2-128 characters.", |
| 64 | + }, |
| 65 | + }, |
| 66 | + }, |
| 67 | + }, |
| 68 | + "description": { |
| 69 | + Type: schema.TypeString, |
| 70 | + Computed: true, |
| 71 | + Description: "Baseline description, with a length of 2 to 256 english or chinese characters. it is empty by default.", |
| 72 | + }, |
| 73 | + "description_en": { |
| 74 | + Type: schema.TypeString, |
| 75 | + Computed: true, |
| 76 | + Description: "Baseline item english description, with a length of 2 to 1024 english characters. it is empty by default.", |
| 77 | + }, |
| 78 | + "classify": { |
| 79 | + Type: schema.TypeString, |
| 80 | + Computed: true, |
| 81 | + Description: "Baseline classification. length: 2-32 english or chinese characters. values cannot be empty.", |
| 82 | + }, |
| 83 | + "classify_en": { |
| 84 | + Type: schema.TypeString, |
| 85 | + Computed: true, |
| 86 | + Description: "Baseline english classification, with a length of 2-64 english characters. cannot be empty.", |
| 87 | + }, |
| 88 | + }, |
| 89 | + }, |
| 90 | + }, |
| 91 | + |
| 92 | + "result_output_file": { |
| 93 | + Type: schema.TypeString, |
| 94 | + Optional: true, |
| 95 | + Description: "Used to save results.", |
| 96 | + }, |
| 97 | + }, |
| 98 | + } |
| 99 | +} |
| 100 | + |
| 101 | +func dataSourceTencentCloudControlcenterAccountFactoryBaselineItemsRead(d *schema.ResourceData, meta interface{}) error { |
| 102 | + defer tccommon.LogElapsed("data_source.tencentcloud_controlcenter_account_factory_baseline_items.read")() |
| 103 | + defer tccommon.InconsistentCheck(d, meta)() |
| 104 | + |
| 105 | + var ( |
| 106 | + logId = tccommon.GetLogId(nil) |
| 107 | + ctx = tccommon.NewResourceLifeCycleHandleFuncContext(context.Background(), logId, d, meta) |
| 108 | + service = ControlcenterService{client: meta.(tccommon.ProviderMeta).GetAPIV3Conn()} |
| 109 | + ) |
| 110 | + |
| 111 | + paramMap := make(map[string]interface{}) |
| 112 | + var respData []*controlcenterv20230110.AccountFactoryItem |
| 113 | + reqErr := resource.Retry(tccommon.ReadRetryTimeout, func() *resource.RetryError { |
| 114 | + result, e := service.DescribeControlcenterAccountFactoryBaselineItemsByFilter(ctx, paramMap) |
| 115 | + if e != nil { |
| 116 | + return tccommon.RetryError(e) |
| 117 | + } |
| 118 | + |
| 119 | + respData = result |
| 120 | + return nil |
| 121 | + }) |
| 122 | + |
| 123 | + if reqErr != nil { |
| 124 | + return reqErr |
| 125 | + } |
| 126 | + |
| 127 | + baselineItemsList := make([]map[string]interface{}, 0, len(respData)) |
| 128 | + if respData != nil { |
| 129 | + for _, baselineItems := range respData { |
| 130 | + baselineItemsMap := map[string]interface{}{} |
| 131 | + if baselineItems.Identifier != nil { |
| 132 | + baselineItemsMap["identifier"] = baselineItems.Identifier |
| 133 | + } |
| 134 | + |
| 135 | + if baselineItems.Name != nil { |
| 136 | + baselineItemsMap["name"] = baselineItems.Name |
| 137 | + } |
| 138 | + |
| 139 | + if baselineItems.NameEn != nil { |
| 140 | + baselineItemsMap["name_en"] = baselineItems.NameEn |
| 141 | + } |
| 142 | + |
| 143 | + if baselineItems.Weight != nil { |
| 144 | + baselineItemsMap["weight"] = baselineItems.Weight |
| 145 | + } |
| 146 | + |
| 147 | + if baselineItems.Required != nil { |
| 148 | + baselineItemsMap["required"] = baselineItems.Required |
| 149 | + } |
| 150 | + |
| 151 | + dependsOnList := make([]map[string]interface{}, 0, len(baselineItems.DependsOn)) |
| 152 | + if baselineItems.DependsOn != nil { |
| 153 | + for _, dependsOn := range baselineItems.DependsOn { |
| 154 | + dependsOnMap := map[string]interface{}{} |
| 155 | + if dependsOn.Type != nil { |
| 156 | + dependsOnMap["type"] = dependsOn.Type |
| 157 | + } |
| 158 | + |
| 159 | + if dependsOn.Identifier != nil { |
| 160 | + dependsOnMap["identifier"] = dependsOn.Identifier |
| 161 | + } |
| 162 | + |
| 163 | + dependsOnList = append(dependsOnList, dependsOnMap) |
| 164 | + } |
| 165 | + |
| 166 | + baselineItemsMap["depends_on"] = dependsOnList |
| 167 | + } |
| 168 | + |
| 169 | + if baselineItems.Description != nil { |
| 170 | + baselineItemsMap["description"] = baselineItems.Description |
| 171 | + } |
| 172 | + |
| 173 | + if baselineItems.DescriptionEn != nil { |
| 174 | + baselineItemsMap["description_en"] = baselineItems.DescriptionEn |
| 175 | + } |
| 176 | + |
| 177 | + if baselineItems.Classify != nil { |
| 178 | + baselineItemsMap["classify"] = baselineItems.Classify |
| 179 | + } |
| 180 | + |
| 181 | + if baselineItems.ClassifyEn != nil { |
| 182 | + baselineItemsMap["classify_en"] = baselineItems.ClassifyEn |
| 183 | + } |
| 184 | + |
| 185 | + baselineItemsList = append(baselineItemsList, baselineItemsMap) |
| 186 | + } |
| 187 | + |
| 188 | + _ = d.Set("baseline_items", baselineItemsList) |
| 189 | + } |
| 190 | + |
| 191 | + d.SetId(helper.BuildToken()) |
| 192 | + output, ok := d.GetOk("result_output_file") |
| 193 | + if ok && output.(string) != "" { |
| 194 | + if e := tccommon.WriteToFile(output.(string), baselineItemsList); e != nil { |
| 195 | + return e |
| 196 | + } |
| 197 | + } |
| 198 | + |
| 199 | + return nil |
| 200 | +} |
0 commit comments