diff --git a/.changelog/3290.txt b/.changelog/3290.txt new file mode 100644 index 0000000000..d41b765b45 --- /dev/null +++ b/.changelog/3290.txt @@ -0,0 +1,7 @@ +```release-note:enhancement +resource/tencentcloud_monitor_tmp_exporter_integration: This resource has been deprecated in Terraform TencentCloud provider version `1.81.182`. Please use `tencentcloud_monitor_tmp_exporter_integration_v2` instead. +``` + +```release-note:new-resource +tencentcloud_monitor_tmp_exporter_integration_v2 +``` diff --git a/tencentcloud/provider.go b/tencentcloud/provider.go index 52ac9686dc..9997885b83 100644 --- a/tencentcloud/provider.go +++ b/tencentcloud/provider.go @@ -1517,6 +1517,7 @@ func Provider() *schema.Provider { "tencentcloud_monitor_tmp_cvm_agent": tmp.ResourceTencentCloudMonitorTmpCvmAgent(), "tencentcloud_monitor_tmp_scrape_job": tmp.ResourceTencentCloudMonitorTmpScrapeJob(), "tencentcloud_monitor_tmp_exporter_integration": tmp.ResourceTencentCloudMonitorTmpExporterIntegration(), + "tencentcloud_monitor_tmp_exporter_integration_v2": tmp.ResourceTencentCloudMonitorTmpExporterIntegrationV2(), "tencentcloud_monitor_tmp_alert_rule": tmp.ResourceTencentCloudMonitorTmpAlertRule(), "tencentcloud_monitor_tmp_recording_rule": tmp.ResourceTencentCloudMonitorTmpRecordingRule(), "tencentcloud_monitor_tmp_multiple_writes": tmp.ResourceTencentCloudMonitorTmpMultipleWrites(), diff --git a/tencentcloud/provider.md b/tencentcloud/provider.md index 866af6d5a9..4b8525bc51 100644 --- a/tencentcloud/provider.md +++ b/tencentcloud/provider.md @@ -849,6 +849,7 @@ Resource tencentcloud_monitor_tmp_instance tencentcloud_monitor_tmp_alert_rule tencentcloud_monitor_tmp_exporter_integration +tencentcloud_monitor_tmp_exporter_integration_v2 tencentcloud_monitor_tmp_cvm_agent tencentcloud_monitor_tmp_scrape_job tencentcloud_monitor_tmp_recording_rule diff --git a/tencentcloud/services/monitor/service_tencentcloud_monitor.go b/tencentcloud/services/monitor/service_tencentcloud_monitor.go index 6e222e7338..02b10c2ffe 100644 --- a/tencentcloud/services/monitor/service_tencentcloud_monitor.go +++ b/tencentcloud/services/monitor/service_tencentcloud_monitor.go @@ -544,14 +544,26 @@ func (me *MonitorService) DescribeMonitorTmpExporterIntegration(ctx context.Cont }() ids := strings.Split(tmpExporterIntegrationId, tccommon.FILED_SP) - if ids[0] != "" { - request.Name = &ids[0] + if len(ids) == 5 { + if ids[0] != "" { + request.Name = &ids[0] + } + + request.InstanceId = &ids[1] + kubeType, _ := strconv.Atoi(ids[2]) + request.KubeType = helper.IntInt64(kubeType) + request.ClusterId = &ids[3] + request.Kind = &ids[4] + } else if len(ids) == 3 { + if ids[0] != "" { + request.Name = &ids[0] + } + + request.InstanceId = &ids[1] + request.Kind = &ids[2] + } else { + return nil, fmt.Errorf("id is broken, id is %s", tmpExporterIntegrationId) } - request.InstanceId = &ids[1] - kubeType, _ := strconv.Atoi(ids[2]) - request.KubeType = helper.IntInt64(kubeType) - request.ClusterId = &ids[3] - request.Kind = &ids[4] response, err := me.client.UseMonitorClient().DescribeExporterIntegrations(request) if err != nil { @@ -560,12 +572,14 @@ func (me *MonitorService) DescribeMonitorTmpExporterIntegration(ctx context.Cont errRet = err return } + log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n", logId, request.GetAction(), request.ToJsonString(), response.ToJsonString()) if len(response.Response.IntegrationSet) < 1 { return } + tmpExporterIntegration = response.Response.IntegrationSet[0] return } @@ -576,12 +590,26 @@ func (me *MonitorService) DeleteMonitorTmpExporterIntegrationById(ctx context.Co request := monitor.NewDeleteExporterIntegrationRequest() ids := strings.Split(tmpExporterIntegrationId, tccommon.FILED_SP) - request.Name = &ids[0] - request.InstanceId = &ids[1] - kubeType, _ := strconv.Atoi(ids[2]) - request.KubeType = helper.IntInt64(kubeType) - request.ClusterId = &ids[3] - request.Kind = &ids[4] + if len(ids) == 5 { + if ids[0] != "" { + request.Name = &ids[0] + } + + request.InstanceId = &ids[1] + kubeType, _ := strconv.Atoi(ids[2]) + request.KubeType = helper.IntInt64(kubeType) + request.ClusterId = &ids[3] + request.Kind = &ids[4] + } else if len(ids) == 3 { + if ids[0] != "" { + request.Name = &ids[0] + } + + request.InstanceId = &ids[1] + request.Kind = &ids[2] + } else { + return fmt.Errorf("id is broken, id is %s", tmpExporterIntegrationId) + } defer func() { if errRet != nil { @@ -596,6 +624,7 @@ func (me *MonitorService) DeleteMonitorTmpExporterIntegrationById(ctx context.Co errRet = err return err } + log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n", logId, request.GetAction(), request.ToJsonString(), response.ToJsonString()) diff --git a/tencentcloud/services/tmp/resource_tc_monitor_tmp_exporter_integration.go b/tencentcloud/services/tmp/resource_tc_monitor_tmp_exporter_integration.go index 6a9e69e069..202806de8b 100644 --- a/tencentcloud/services/tmp/resource_tc_monitor_tmp_exporter_integration.go +++ b/tencentcloud/services/tmp/resource_tc_monitor_tmp_exporter_integration.go @@ -19,10 +19,11 @@ import ( func ResourceTencentCloudMonitorTmpExporterIntegration() *schema.Resource { return &schema.Resource{ - Read: resourceTencentCloudMonitorTmpExporterIntegrationRead, - Create: resourceTencentCloudMonitorTmpExporterIntegrationCreate, - Update: resourceTencentCloudMonitorTmpExporterIntegrationUpdate, - Delete: resourceTencentCloudMonitorTmpExporterIntegrationDelete, + DeprecationMessage: "This resource has been deprecated in Terraform TencentCloud provider version 1.81.182. Please use 'tencentcloud_monitor_tmp_exporter_integration_v2' instead.", + Read: resourceTencentCloudMonitorTmpExporterIntegrationRead, + Create: resourceTencentCloudMonitorTmpExporterIntegrationCreate, + Update: resourceTencentCloudMonitorTmpExporterIntegrationUpdate, + Delete: resourceTencentCloudMonitorTmpExporterIntegrationDelete, Schema: map[string]*schema.Schema{ "instance_id": { Type: schema.TypeString, diff --git a/tencentcloud/services/tmp/resource_tc_monitor_tmp_exporter_integration.md b/tencentcloud/services/tmp/resource_tc_monitor_tmp_exporter_integration.md index 086bb73490..d3cb9327ab 100644 --- a/tencentcloud/services/tmp/resource_tc_monitor_tmp_exporter_integration.md +++ b/tencentcloud/services/tmp/resource_tc_monitor_tmp_exporter_integration.md @@ -1,5 +1,7 @@ Provides a resource to create a monitor tmpExporterIntegration +~> **NOTE:** This resource has been deprecated in Terraform TencentCloud provider version `1.81.182`. Please use `tencentcloud_monitor_tmp_exporter_integration_v2` instead. + ~> **NOTE:** If you only want to upgrade the exporter version with same config, you can set `version` under `instanceSpec` with any value to trigger the change. Example Usage diff --git a/tencentcloud/services/tmp/resource_tc_monitor_tmp_exporter_integration_v2.go b/tencentcloud/services/tmp/resource_tc_monitor_tmp_exporter_integration_v2.go new file mode 100644 index 0000000000..3ee7245b7e --- /dev/null +++ b/tencentcloud/services/tmp/resource_tc_monitor_tmp_exporter_integration_v2.go @@ -0,0 +1,312 @@ +package tmp + +import ( + "strconv" + + tccommon "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/common" + svcmonitor "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/services/monitor" + + "context" + "fmt" + "log" + "strings" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + monitor "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/monitor/v20180724" + + "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/internal/helper" +) + +func ResourceTencentCloudMonitorTmpExporterIntegrationV2() *schema.Resource { + return &schema.Resource{ + Create: resourceTencentCloudMonitorTmpExporterIntegrationV2Create, + Read: resourceTencentCloudMonitorTmpExporterIntegrationV2Read, + Update: resourceTencentCloudMonitorTmpExporterIntegrationV2Update, + Delete: resourceTencentCloudMonitorTmpExporterIntegrationV2Delete, + Schema: map[string]*schema.Schema{ + "instance_id": { + Type: schema.TypeString, + Required: true, + Description: "Instance ID.", + }, + + "kind": { + Type: schema.TypeString, + Required: true, + Description: "Type.", + }, + + "content": { + Type: schema.TypeString, + Required: true, + Description: "Integration config.", + }, + + "kube_type": { + Type: schema.TypeInt, + Optional: true, + ValidateFunc: tccommon.ValidateAllowedIntValue([]int{1, 2, 3}), + Description: "Integration config. 1 - TKE; 2 - EKS; 3 - MEKS.", + }, + + "cluster_id": { + Type: schema.TypeString, + Optional: true, + Description: "Cluster ID.", + }, + }, + } +} + +func resourceTencentCloudMonitorTmpExporterIntegrationV2Create(d *schema.ResourceData, meta interface{}) error { + defer tccommon.LogElapsed("resource.tencentcloud_monitor_tmp_exporter_integration_v2.create")() + defer tccommon.InconsistentCheck(d, meta)() + + var ( + logId = tccommon.GetLogId(tccommon.ContextNil) + request = monitor.NewCreateExporterIntegrationRequest() + response = monitor.NewCreateExporterIntegrationResponse() + instanceId string + kubeType int + clusterId string + kind string + hasKubeType bool + hasClusterId bool + ) + + if v, ok := d.GetOk("instance_id"); ok { + request.InstanceId = helper.String(v.(string)) + instanceId = v.(string) + } + + if v, ok := d.GetOk("kind"); ok { + request.Kind = helper.String(v.(string)) + kind = v.(string) + } + + if v, ok := d.GetOk("content"); ok { + request.Content = helper.String(v.(string)) + } + + if v, ok := d.GetOkExists("kube_type"); ok { + request.KubeType = helper.IntInt64(v.(int)) + kubeType = v.(int) + hasKubeType = true + } + + if v, ok := d.GetOk("cluster_id"); ok && v.(string) != "" { + request.ClusterId = helper.String(v.(string)) + clusterId = v.(string) + hasClusterId = true + } + + if hasKubeType != hasClusterId { + return fmt.Errorf("`kube_type` and `cluster_id` can only be set together or not set at all.") + } + + initStatus := monitor.NewDescribePrometheusInstanceInitStatusRequest() + initStatus.InstanceId = &instanceId + err := resource.Retry(8*tccommon.ReadRetryTimeout, func() *resource.RetryError { + results, errRet := meta.(tccommon.ProviderMeta).GetAPIV3Conn().UseMonitorClient().DescribePrometheusInstanceInitStatus(initStatus) + if errRet != nil { + return tccommon.RetryError(errRet, tccommon.InternalError) + } + + status := results.Response.Status + if status == nil { + return resource.NonRetryableError(fmt.Errorf("prometheusInstanceInit status is nil, operate failed")) + } + + if *status == "running" { + return nil + } + + if *status == "uninitialized" { + iniRequest := monitor.NewRunPrometheusInstanceRequest() + iniRequest.InstanceId = &instanceId + err := resource.Retry(tccommon.WriteRetryTimeout, func() *resource.RetryError { + result, e := meta.(tccommon.ProviderMeta).GetAPIV3Conn().UseMonitorClient().RunPrometheusInstance(iniRequest) + if e != nil { + return tccommon.RetryError(e) + } else { + log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n", + logId, iniRequest.GetAction(), iniRequest.ToJsonString(), result.ToJsonString()) + } + + return nil + }) + + if err != nil { + return resource.RetryableError(fmt.Errorf("prometheusInstanceInit error %v, operate failed", err)) + } + + return resource.RetryableError(fmt.Errorf("prometheusInstance initializing, retry...")) + } + + return resource.RetryableError(fmt.Errorf("prometheusInstanceInit status is %v, retry...", *status)) + }) + + if err != nil { + return err + } + + err = resource.Retry(tccommon.WriteRetryTimeout, func() *resource.RetryError { + result, e := meta.(tccommon.ProviderMeta).GetAPIV3Conn().UseMonitorClient().CreateExporterIntegration(request) + if e != nil { + return tccommon.RetryError(e) + } else { + log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n", + logId, request.GetAction(), request.ToJsonString(), result.ToJsonString()) + } + + if result == nil || result.Response == nil || result.Response.Names == nil { + return resource.NonRetryableError(fmt.Errorf("Create monitor tmpExporterIntegration failed, Response is nil.")) + } + + response = result + return nil + }) + + if err != nil { + log.Printf("[CRITAL]%s create monitor tmpExporterIntegration failed, reason:%+v", logId, err) + return err + } + + if len(response.Response.Names) < 1 { + return fmt.Errorf("Names is nil.") + } + + tmpExporterIntegrationId := *response.Response.Names[0] + + if hasKubeType || hasClusterId { + d.SetId(strings.Join([]string{tmpExporterIntegrationId, instanceId, strconv.Itoa(kubeType), clusterId, kind}, tccommon.FILED_SP)) + } else { + d.SetId(strings.Join([]string{tmpExporterIntegrationId, instanceId, kind}, tccommon.FILED_SP)) + } + + return resourceTencentCloudMonitorTmpExporterIntegrationV2Read(d, meta) +} + +func resourceTencentCloudMonitorTmpExporterIntegrationV2Read(d *schema.ResourceData, meta interface{}) error { + defer tccommon.LogElapsed("resource.tencentcloud_monitor_tmp_exporter_integration_v2.read")() + defer tccommon.InconsistentCheck(d, meta)() + + var ( + logId = tccommon.GetLogId(tccommon.ContextNil) + ctx = context.WithValue(context.TODO(), tccommon.LogIdKey, logId) + service = svcmonitor.NewMonitorService(meta.(tccommon.ProviderMeta).GetAPIV3Conn()) + tmpExporterIntegrationId = d.Id() + ) + + tmpExporterIntegration, err := service.DescribeMonitorTmpExporterIntegration(ctx, tmpExporterIntegrationId) + if err != nil { + return err + } + + if tmpExporterIntegration == nil { + d.SetId("") + log.Printf("[WARN]%s resource `tmpExporterIntegration` [%s] not found, please check if it has been deleted.\n", logId, d.Id()) + return nil + } + + if tmpExporterIntegration.Kind != nil { + _ = d.Set("kind", tmpExporterIntegration.Kind) + } + + if tmpExporterIntegration.Content != nil { + _ = d.Set("content", tmpExporterIntegration.Content) + } + + return nil +} + +func resourceTencentCloudMonitorTmpExporterIntegrationV2Update(d *schema.ResourceData, meta interface{}) error { + defer tccommon.LogElapsed("resource.tencentcloud_monitor_tmp_exporter_integration_v2.update")() + defer tccommon.InconsistentCheck(d, meta)() + + var ( + logId = tccommon.GetLogId(tccommon.ContextNil) + request = monitor.NewUpdateExporterIntegrationRequest() + ) + + immutableArgs := []string{"instance_id", "kind", "kube_type", "cluster_id"} + for _, v := range immutableArgs { + if d.HasChange(v) { + return fmt.Errorf("argument `%s` cannot be changed.", v) + } + } + + if v, ok := d.GetOk("instance_id"); ok { + request.InstanceId = helper.String(v.(string)) + } + + if v, ok := d.GetOk("kind"); ok { + request.Kind = helper.String(v.(string)) + } + + if v, ok := d.GetOk("content"); ok { + request.Content = helper.String(v.(string)) + } + + if v, ok := d.GetOkExists("kube_type"); ok { + request.KubeType = helper.IntInt64(v.(int)) + } + + if v, ok := d.GetOk("cluster_id"); ok && v.(string) != "" { + request.ClusterId = helper.String(v.(string)) + } + + err := resource.Retry(tccommon.WriteRetryTimeout, func() *resource.RetryError { + result, e := meta.(tccommon.ProviderMeta).GetAPIV3Conn().UseMonitorClient().UpdateExporterIntegration(request) + if e != nil { + return tccommon.RetryError(e) + } else { + log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n", + logId, request.GetAction(), request.ToJsonString(), result.ToJsonString()) + } + + return nil + }) + + if err != nil { + return err + } + + return resourceTencentCloudMonitorTmpExporterIntegrationV2Read(d, meta) +} + +func resourceTencentCloudMonitorTmpExporterIntegrationV2Delete(d *schema.ResourceData, meta interface{}) error { + defer tccommon.LogElapsed("resource.tencentcloud_monitor_tmp_exporter_integration_v2.delete")() + defer tccommon.InconsistentCheck(d, meta)() + + var ( + logId = tccommon.GetLogId(tccommon.ContextNil) + ctx = context.WithValue(context.TODO(), tccommon.LogIdKey, logId) + service = svcmonitor.NewMonitorService(meta.(tccommon.ProviderMeta).GetAPIV3Conn()) + tmpExporterIntegrationId = d.Id() + ) + + if err := service.DeleteMonitorTmpExporterIntegrationById(ctx, tmpExporterIntegrationId); err != nil { + return err + } + + err := resource.Retry(2*tccommon.ReadRetryTimeout, func() *resource.RetryError { + tmpExporterIntegration, errRet := service.DescribeMonitorTmpExporterIntegration(ctx, tmpExporterIntegrationId) + if errRet != nil { + return tccommon.RetryError(errRet, tccommon.InternalError) + } + + if tmpExporterIntegration == nil { + return nil + } + + return resource.RetryableError(fmt.Errorf("exporter integration status is %v, retry...", *tmpExporterIntegration.Status)) + }) + + if err != nil { + return err + } + + return nil +} diff --git a/tencentcloud/services/tmp/resource_tc_monitor_tmp_exporter_integration_v2.md b/tencentcloud/services/tmp/resource_tc_monitor_tmp_exporter_integration_v2.md new file mode 100644 index 0000000000..7e3d81d4b5 --- /dev/null +++ b/tencentcloud/services/tmp/resource_tc_monitor_tmp_exporter_integration_v2.md @@ -0,0 +1,106 @@ +Provides a resource to create a monitor Exporter Integration + +~> **NOTE:** If you only want to upgrade the exporter version with same config, you can set `version` under `instanceSpec` with any value to trigger the change. + +Example Usage + +Use qcloud-exporter + +```hcl +resource "tencentcloud_monitor_tmp_exporter_integration_v2" "example" { + instance_id = "prom-gzg3f1em" + kind = "qcloud-exporter" + content = "{\"name\":\"test\",\"kind\":\"qcloud-exporter\",\"spec\":{\"scrapeSpec\":{\"interval\":\"1m\",\"timeout\":\"1m\",\"relabelConfigs\":\"#metricRelabelings:\\n#- action: labeldrop\\n# regex: tmp_test_label\\n\"},\"instanceSpec\":{\"region\":\"Guangzhou\",\"role\":\"CM_QCSLinkedRoleInTMP\",\"useRole\":true,\"authProvider\":{\"method\":1,\"presetRole\":\"CM_QCSLinkedRoleInTMP\"},\"rateLimit\":1000,\"delaySeconds\":0,\"rangeSeconds\":0,\"reload_interval_minutes\":10,\"uin\":\"100023201586\",\"tag_key_operation\":\"ToUnderLineAndLower\"},\"exporterSpec\":{\"cvm\":false,\"cbs\":true,\"imageRegistry\":\"ccr.ccs.tencentyun.com\",\"cpu\":\"0.25\",\"memory\":\"0.5Gi\"}},\"status\":{}}" +} +``` + +Use es-exporter + +``` +resource "tencentcloud_monitor_tmp_exporter_integration_v2" "example" { + instance_id = "prom-gzg3f1em" + kind = "es-exporter" + content = jsonencode({ + "name" : "ex-exporter-example", + "kind" : "es-exporter", + "spec" : { + "instanceSpec" : { + "user" : "root", + "password" : "Password@123" + "url" : "http://127.0.0.1:8080", + "labels" : { + "labelKey" : "labelValue" + } + }, + "exporterSpec" : { + "all" : true, + "indices" : true, + "indicesSettings" : true, + "shards" : true, + "snapshots" : true, + "clusterSettings" : true + } + } + }) +} +``` + +Integration Center: CVM Scrape Job + +``` +resource "tencentcloud_vpc" "vpc" { + name = "vpc" + cidr_block = "10.2.0.0/16" +} + +resource "tencentcloud_subnet" "subnet" { + vpc_id = tencentcloud_vpc.vpc.id + name = "subnet" + cidr_block = "10.2.11.0/24" + availability_zone = "ap-guangzhou-6" +} + +resource "tencentcloud_monitor_tmp_instance" "example" { + instance_name = "tf-example" + vpc_id = tencentcloud_vpc.vpc.id + subnet_id = tencentcloud_subnet.subnet.id + data_retention_time = 15 + zone = "ap-guangzhou-6" + tags = { + createdBy = "Terraform" + } +} + +# Integration Center: CVM Scrape Job +resource "tencentcloud_monitor_tmp_exporter_integration" "example" { + instance_id = tencentcloud_monitor_tmp_instance.example.id + kind = "cvm-http-sd-exporter" + content = jsonencode({ + "kind" : "cvm-http-sd-exporter", + "spec" : { + "job" : <<-EOT + job_name: example-cvm-job-name + metrics_path: /metrics + cvm_sd_configs: + - region: ap-guangzhou + ports: + - 9100 + filters: + - name: tag:YOUR_TAG_KEY + values: + - YOUR_TAG_VALUE + relabel_configs: + - source_labels: [__meta_cvm_instance_state] + regex: RUNNING + action: keep + - regex: __meta_cvm_tag_(.*) + replacement: $1 + action: labelmap + - source_labels: [__meta_cvm_region] + target_label: region + action: replace + EOT + } + }) +} +``` \ No newline at end of file diff --git a/website/docs/r/monitor_tmp_exporter_integration.html.markdown b/website/docs/r/monitor_tmp_exporter_integration.html.markdown index 2c5bd57a4a..17e8cc968d 100644 --- a/website/docs/r/monitor_tmp_exporter_integration.html.markdown +++ b/website/docs/r/monitor_tmp_exporter_integration.html.markdown @@ -11,6 +11,8 @@ description: |- Provides a resource to create a monitor tmpExporterIntegration +~> **NOTE:** This resource has been deprecated in Terraform TencentCloud provider version `1.81.182`. Please use `tencentcloud_monitor_tmp_exporter_integration_v2` instead. + ~> **NOTE:** If you only want to upgrade the exporter version with same config, you can set `version` under `instanceSpec` with any value to trigger the change. ## Example Usage diff --git a/website/docs/r/monitor_tmp_exporter_integration_v2.html.markdown b/website/docs/r/monitor_tmp_exporter_integration_v2.html.markdown new file mode 100644 index 0000000000..c54e0c4454 --- /dev/null +++ b/website/docs/r/monitor_tmp_exporter_integration_v2.html.markdown @@ -0,0 +1,136 @@ +--- +subcategory: "Managed Service for Prometheus(TMP)" +layout: "tencentcloud" +page_title: "TencentCloud: tencentcloud_monitor_tmp_exporter_integration_v2" +sidebar_current: "docs-tencentcloud-resource-monitor_tmp_exporter_integration_v2" +description: |- + Provides a resource to create a monitor Exporter Integration +--- + +# tencentcloud_monitor_tmp_exporter_integration_v2 + +Provides a resource to create a monitor Exporter Integration + +~> **NOTE:** If you only want to upgrade the exporter version with same config, you can set `version` under `instanceSpec` with any value to trigger the change. + +## Example Usage + +### Use qcloud-exporter + +```hcl +resource "tencentcloud_monitor_tmp_exporter_integration_v2" "example" { + instance_id = "prom-gzg3f1em" + kind = "qcloud-exporter" + content = "{\"name\":\"test\",\"kind\":\"qcloud-exporter\",\"spec\":{\"scrapeSpec\":{\"interval\":\"1m\",\"timeout\":\"1m\",\"relabelConfigs\":\"#metricRelabelings:\\n#- action: labeldrop\\n# regex: tmp_test_label\\n\"},\"instanceSpec\":{\"region\":\"Guangzhou\",\"role\":\"CM_QCSLinkedRoleInTMP\",\"useRole\":true,\"authProvider\":{\"method\":1,\"presetRole\":\"CM_QCSLinkedRoleInTMP\"},\"rateLimit\":1000,\"delaySeconds\":0,\"rangeSeconds\":0,\"reload_interval_minutes\":10,\"uin\":\"100023201586\",\"tag_key_operation\":\"ToUnderLineAndLower\"},\"exporterSpec\":{\"cvm\":false,\"cbs\":true,\"imageRegistry\":\"ccr.ccs.tencentyun.com\",\"cpu\":\"0.25\",\"memory\":\"0.5Gi\"}},\"status\":{}}" +} +``` + +### Use es-exporter + +```hcl +resource "tencentcloud_monitor_tmp_exporter_integration_v2" "example" { + instance_id = "prom-gzg3f1em" + kind = "es-exporter" + content = jsonencode({ + "name" : "ex-exporter-example", + "kind" : "es-exporter", + "spec" : { + "instanceSpec" : { + "user" : "root", + "password" : "Password@123" + "url" : "http://127.0.0.1:8080", + "labels" : { + "labelKey" : "labelValue" + } + }, + "exporterSpec" : { + "all" : true, + "indices" : true, + "indicesSettings" : true, + "shards" : true, + "snapshots" : true, + "clusterSettings" : true + } + } + }) +} +``` + +### Integration Center: CVM Scrape Job + +```hcl +resource "tencentcloud_vpc" "vpc" { + name = "vpc" + cidr_block = "10.2.0.0/16" +} + +resource "tencentcloud_subnet" "subnet" { + vpc_id = tencentcloud_vpc.vpc.id + name = "subnet" + cidr_block = "10.2.11.0/24" + availability_zone = "ap-guangzhou-6" +} + +resource "tencentcloud_monitor_tmp_instance" "example" { + instance_name = "tf-example" + vpc_id = tencentcloud_vpc.vpc.id + subnet_id = tencentcloud_subnet.subnet.id + data_retention_time = 15 + zone = "ap-guangzhou-6" + tags = { + createdBy = "Terraform" + } +} + +# Integration Center: CVM Scrape Job +resource "tencentcloud_monitor_tmp_exporter_integration" "example" { + instance_id = tencentcloud_monitor_tmp_instance.example.id + kind = "cvm-http-sd-exporter" + content = jsonencode({ + "kind" : "cvm-http-sd-exporter", + "spec" : { + "job" : <<-EOT + job_name: example-cvm-job-name + metrics_path: /metrics + cvm_sd_configs: + - region: ap-guangzhou + ports: + - 9100 + filters: + - name: tag:YOUR_TAG_KEY + values: + - YOUR_TAG_VALUE + relabel_configs: + - source_labels: [__meta_cvm_instance_state] + regex: RUNNING + action: keep + - regex: __meta_cvm_tag_(.*) + replacement: $1 + action: labelmap + - source_labels: [__meta_cvm_region] + target_label: region + action: replace + EOT + } + }) +} +``` + +## Argument Reference + +The following arguments are supported: + +* `content` - (Required, String) Integration config. +* `instance_id` - (Required, String) Instance ID. +* `kind` - (Required, String) Type. +* `cluster_id` - (Optional, String) Cluster ID. +* `kube_type` - (Optional, Int) Integration config. 1 - TKE; 2 - EKS; 3 - MEKS. + +## Attributes Reference + +In addition to all arguments above, the following attributes are exported: + +* `id` - ID of the resource. + + + diff --git a/website/tencentcloud.erb b/website/tencentcloud.erb index c92609db70..ca3d0b1cd0 100644 --- a/website/tencentcloud.erb +++ b/website/tencentcloud.erb @@ -2904,6 +2904,9 @@
  • tencentcloud_monitor_tmp_exporter_integration
  • +
  • + tencentcloud_monitor_tmp_exporter_integration_v2 +
  • tencentcloud_monitor_tmp_instance