-
Notifications
You must be signed in to change notification settings - Fork 136
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(teo): [117892609] support realtime_log_delivery (#2697)
* feat(teo): [117892609] support realtime_log_delivery * feat: add changelog and doc
- Loading branch information
Showing
10 changed files
with
1,564 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
```release-note:new-resource | ||
tencentcloud_teo_realtime_log_delivery | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1,065 changes: 1,065 additions & 0 deletions
1,065
tencentcloud/services/teo/resource_tc_teo_realtime_log_delivery.go
Large diffs are not rendered by default.
Oops, something went wrong.
57 changes: 57 additions & 0 deletions
57
tencentcloud/services/teo/resource_tc_teo_realtime_log_delivery.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
Provides a resource to create a teo teo_realtime_log_delivery | ||
|
||
Example Usage | ||
|
||
```hcl | ||
resource "tencentcloud_teo_realtime_log_delivery" "teo_realtime_log_delivery" { | ||
area = "overseas" | ||
delivery_status = "disabled" | ||
entity_list = [ | ||
"sid-2yvhjw98uaco", | ||
] | ||
fields = [ | ||
"ServiceID", | ||
"ConnectTimeStamp", | ||
"DisconnetTimeStamp", | ||
"DisconnetReason", | ||
"ClientRealIP", | ||
"ClientRegion", | ||
"EdgeIP", | ||
"ForwardProtocol", | ||
"ForwardPort", | ||
"SentBytes", | ||
"ReceivedBytes", | ||
"LogTimeStamp", | ||
] | ||
log_type = "application" | ||
sample = 0 | ||
task_name = "test" | ||
task_type = "s3" | ||
zone_id = "zone-2qtuhspy7cr6" | ||
log_format { | ||
field_delimiter = "," | ||
format_type = "json" | ||
record_delimiter = "\n" | ||
record_prefix = "{" | ||
record_suffix = "}" | ||
} | ||
s3 { | ||
access_id = "xxxxxxxxxx" | ||
access_key = "xxxxxxxxxx" | ||
bucket = "test-1253833068" | ||
compress_type = "gzip" | ||
endpoint = "https://test-1253833068.cos.ap-nanjing.myqcloud.com" | ||
region = "ap-nanjing" | ||
} | ||
} | ||
``` | ||
|
||
Import | ||
|
||
teo teo_realtime_log_delivery can be imported using the id, e.g. | ||
|
||
``` | ||
terraform import tencentcloud_teo_realtime_log_delivery.teo_realtime_log_delivery zoneId#taskId | ||
``` |
83 changes: 83 additions & 0 deletions
83
tencentcloud/services/teo/resource_tc_teo_realtime_log_delivery_extension.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
package teo | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" | ||
teo "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/teo/v20220901" | ||
|
||
tccommon "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/common" | ||
) | ||
|
||
func resourceTencentCloudTeoRealtimeLogDeliveryCreatePostHandleResponse0(ctx context.Context, resp *teo.CreateRealtimeLogDeliveryTaskResponse) error { | ||
taskId := *resp.Response.TaskId | ||
return checkRealtimeLogDeliveryStatus(ctx, taskId, "enabled") | ||
} | ||
|
||
func resourceTencentCloudTeoRealtimeLogDeliveryUpdatePostHandleResponse0(ctx context.Context, resp *teo.ModifyRealtimeLogDeliveryTaskResponse) error { | ||
d := tccommon.ResourceDataFromContext(ctx) | ||
if d == nil { | ||
return fmt.Errorf("resource data can not be nil") | ||
} | ||
var taskId string | ||
if v, ok := d.GetOk("task_id"); ok { | ||
taskId = v.(string) | ||
} | ||
return checkRealtimeLogDeliveryStatus(ctx, taskId, "update") | ||
} | ||
|
||
func resourceTencentCloudTeoRealtimeLogDeliveryDeletePostHandleResponse0(ctx context.Context, resp *teo.DeleteRealtimeLogDeliveryTaskResponse) error { | ||
d := tccommon.ResourceDataFromContext(ctx) | ||
if d == nil { | ||
return fmt.Errorf("resource data can not be nil") | ||
} | ||
var taskId string | ||
if v, ok := d.GetOk("task_id"); ok { | ||
taskId = v.(string) | ||
} | ||
return checkRealtimeLogDeliveryStatus(ctx, taskId, "deleted") | ||
} | ||
|
||
func checkRealtimeLogDeliveryStatus(ctx context.Context, taskId string, expectedStatuses ...string) error { | ||
d := tccommon.ResourceDataFromContext(ctx) | ||
if d == nil { | ||
return fmt.Errorf("resource data can not be nil") | ||
} | ||
meta := tccommon.ProviderMetaFromContext(ctx) | ||
if meta == nil { | ||
return fmt.Errorf("provider meta can not be nil") | ||
} | ||
|
||
var zoneId string | ||
if v, ok := d.GetOk("zone_id"); ok { | ||
zoneId = v.(string) | ||
} | ||
|
||
if v, ok := d.GetOk("delivery_status"); ok && expectedStatuses[0] == "update" { | ||
expectedStatuses = append(expectedStatuses, v.(string)) | ||
} | ||
|
||
service := TeoService{client: meta.(tccommon.ProviderMeta).GetAPIV3Conn()} | ||
return resource.Retry(6*tccommon.ReadRetryTimeout, func() *resource.RetryError { | ||
instance, errRet := service.DescribeTeoRealtimeLogDeliveryById(ctx, zoneId, taskId) | ||
if errRet != nil { | ||
return tccommon.RetryError(errRet, tccommon.InternalError) | ||
} | ||
|
||
if instance == nil { | ||
if expectedStatuses[0] != "deleted" { | ||
return resource.NonRetryableError(fmt.Errorf("RealtimeLogDeliveryTask data not found, taskId: %v", taskId)) | ||
} | ||
return nil | ||
} | ||
|
||
for _, s := range expectedStatuses { | ||
if s == *instance.DeliveryStatus { | ||
return nil | ||
} | ||
} | ||
|
||
return resource.RetryableError(fmt.Errorf("RealtimeLogDeliveryTask status is %v, retry...", *instance.DeliveryStatus)) | ||
}) | ||
} |
164 changes: 164 additions & 0 deletions
164
tencentcloud/services/teo/resource_tc_teo_realtime_log_delivery_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,164 @@ | ||
package teo_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" | ||
|
||
tcacctest "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/acctest" | ||
) | ||
|
||
func TestAccTencentCloudTeoRealtimeLogDeliveryResource_basic(t *testing.T) { | ||
t.Parallel() | ||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { | ||
tcacctest.AccPreCheck(t) | ||
}, | ||
Providers: tcacctest.AccProviders, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccTeoRealtimeLogDelivery, | ||
Check: resource.ComposeTestCheckFunc( | ||
resource.TestCheckResourceAttrSet("tencentcloud_teo_realtime_log_delivery.teo_realtime_log_delivery", "id"), | ||
resource.TestCheckResourceAttr("tencentcloud_teo_realtime_log_delivery.teo_realtime_log_delivery", "area", "overseas"), | ||
resource.TestCheckResourceAttr("tencentcloud_teo_realtime_log_delivery.teo_realtime_log_delivery", "delivery_status", "enabled"), | ||
resource.TestCheckResourceAttr("tencentcloud_teo_realtime_log_delivery.teo_realtime_log_delivery", "entity_list.#", "1"), | ||
resource.TestCheckResourceAttrSet("tencentcloud_teo_realtime_log_delivery.teo_realtime_log_delivery", "fields.#"), | ||
resource.TestCheckResourceAttr("tencentcloud_teo_realtime_log_delivery.teo_realtime_log_delivery", "log_type", "application"), | ||
resource.TestCheckResourceAttr("tencentcloud_teo_realtime_log_delivery.teo_realtime_log_delivery", "sample", "0"), | ||
resource.TestCheckResourceAttr("tencentcloud_teo_realtime_log_delivery.teo_realtime_log_delivery", "task_name", "test"), | ||
resource.TestCheckResourceAttr("tencentcloud_teo_realtime_log_delivery.teo_realtime_log_delivery", "task_type", "s3"), | ||
resource.TestCheckResourceAttr("tencentcloud_teo_realtime_log_delivery.teo_realtime_log_delivery", "log_format.#", "1"), | ||
resource.TestCheckResourceAttr("tencentcloud_teo_realtime_log_delivery.teo_realtime_log_delivery", "s3.#", "1"), | ||
resource.TestCheckResourceAttrSet("tencentcloud_teo_realtime_log_delivery.teo_realtime_log_delivery", "s3.0.access_id"), | ||
resource.TestCheckResourceAttrSet("tencentcloud_teo_realtime_log_delivery.teo_realtime_log_delivery", "s3.0.access_key"), | ||
resource.TestCheckResourceAttrSet("tencentcloud_teo_realtime_log_delivery.teo_realtime_log_delivery", "s3.0.bucket"), | ||
resource.TestCheckResourceAttrSet("tencentcloud_teo_realtime_log_delivery.teo_realtime_log_delivery", "s3.0.compress_type"), | ||
resource.TestCheckResourceAttrSet("tencentcloud_teo_realtime_log_delivery.teo_realtime_log_delivery", "s3.0.endpoint"), | ||
resource.TestCheckResourceAttrSet("tencentcloud_teo_realtime_log_delivery.teo_realtime_log_delivery", "s3.0.region"), | ||
), | ||
}, | ||
{ | ||
ResourceName: "tencentcloud_teo_realtime_log_delivery.teo_realtime_log_delivery", | ||
ImportState: true, | ||
ImportStateVerify: true, | ||
}, | ||
{ | ||
Config: testAccTeoRealtimeLogDeliveryUp, | ||
Check: resource.ComposeTestCheckFunc( | ||
resource.TestCheckResourceAttrSet("tencentcloud_teo_realtime_log_delivery.teo_realtime_log_delivery", "id"), | ||
resource.TestCheckResourceAttr("tencentcloud_teo_realtime_log_delivery.teo_realtime_log_delivery", "area", "overseas"), | ||
resource.TestCheckResourceAttr("tencentcloud_teo_realtime_log_delivery.teo_realtime_log_delivery", "delivery_status", "disabled"), | ||
resource.TestCheckResourceAttr("tencentcloud_teo_realtime_log_delivery.teo_realtime_log_delivery", "entity_list.#", "1"), | ||
resource.TestCheckResourceAttrSet("tencentcloud_teo_realtime_log_delivery.teo_realtime_log_delivery", "fields.#"), | ||
resource.TestCheckResourceAttr("tencentcloud_teo_realtime_log_delivery.teo_realtime_log_delivery", "log_type", "application"), | ||
resource.TestCheckResourceAttr("tencentcloud_teo_realtime_log_delivery.teo_realtime_log_delivery", "sample", "0"), | ||
resource.TestCheckResourceAttr("tencentcloud_teo_realtime_log_delivery.teo_realtime_log_delivery", "task_name", "test"), | ||
resource.TestCheckResourceAttr("tencentcloud_teo_realtime_log_delivery.teo_realtime_log_delivery", "task_type", "s3"), | ||
resource.TestCheckResourceAttr("tencentcloud_teo_realtime_log_delivery.teo_realtime_log_delivery", "log_format.#", "1"), | ||
resource.TestCheckResourceAttr("tencentcloud_teo_realtime_log_delivery.teo_realtime_log_delivery", "s3.#", "1"), | ||
resource.TestCheckResourceAttrSet("tencentcloud_teo_realtime_log_delivery.teo_realtime_log_delivery", "s3.0.access_id"), | ||
resource.TestCheckResourceAttrSet("tencentcloud_teo_realtime_log_delivery.teo_realtime_log_delivery", "s3.0.access_key"), | ||
resource.TestCheckResourceAttrSet("tencentcloud_teo_realtime_log_delivery.teo_realtime_log_delivery", "s3.0.bucket"), | ||
resource.TestCheckResourceAttrSet("tencentcloud_teo_realtime_log_delivery.teo_realtime_log_delivery", "s3.0.compress_type"), | ||
resource.TestCheckResourceAttrSet("tencentcloud_teo_realtime_log_delivery.teo_realtime_log_delivery", "s3.0.endpoint"), | ||
resource.TestCheckResourceAttrSet("tencentcloud_teo_realtime_log_delivery.teo_realtime_log_delivery", "s3.0.region"), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
const testAccTeoRealtimeLogDelivery = ` | ||
resource "tencentcloud_teo_realtime_log_delivery" "teo_realtime_log_delivery" { | ||
area = "overseas" | ||
delivery_status = "enabled" | ||
entity_list = [ | ||
"sid-2yvhjw98uaco", | ||
] | ||
fields = [ | ||
"ServiceID", | ||
"ConnectTimeStamp", | ||
"DisconnetTimeStamp", | ||
"DisconnetReason", | ||
"ClientRealIP", | ||
"ClientRegion", | ||
"EdgeIP", | ||
"ForwardProtocol", | ||
"ForwardPort", | ||
"SentBytes", | ||
"ReceivedBytes", | ||
"LogTimeStamp", | ||
] | ||
log_type = "application" | ||
sample = 0 | ||
task_name = "test" | ||
task_type = "s3" | ||
zone_id = "zone-2qtuhspy7cr6" | ||
log_format { | ||
field_delimiter = "," | ||
format_type = "json" | ||
record_delimiter = "\n" | ||
record_prefix = "{" | ||
record_suffix = "}" | ||
} | ||
s3 { | ||
access_id = "xxxxxxxxxx" | ||
access_key = "xxxxxxxxxx" | ||
bucket = "test-1253833068" | ||
compress_type = "gzip" | ||
endpoint = "https://test-1253833068.cos.ap-nanjing.myqcloud.com" | ||
region = "ap-nanjing" | ||
} | ||
} | ||
` | ||
|
||
const testAccTeoRealtimeLogDeliveryUp = ` | ||
resource "tencentcloud_teo_realtime_log_delivery" "teo_realtime_log_delivery" { | ||
area = "overseas" | ||
delivery_status = "disabled" | ||
entity_list = [ | ||
"sid-2yvhjw98uaco", | ||
] | ||
fields = [ | ||
"ServiceID", | ||
"ConnectTimeStamp", | ||
"DisconnetTimeStamp", | ||
"DisconnetReason", | ||
"ClientRealIP", | ||
"ClientRegion", | ||
"EdgeIP", | ||
"ForwardProtocol", | ||
"ForwardPort", | ||
"SentBytes", | ||
"ReceivedBytes", | ||
"LogTimeStamp", | ||
] | ||
log_type = "application" | ||
sample = 0 | ||
task_name = "test" | ||
task_type = "s3" | ||
zone_id = "zone-2qtuhspy7cr6" | ||
log_format { | ||
field_delimiter = "," | ||
format_type = "json" | ||
record_delimiter = "\n" | ||
record_prefix = "{" | ||
record_suffix = "}" | ||
} | ||
s3 { | ||
access_id = "xxxxxxxxxx" | ||
access_key = "xxxxxxxxxx" | ||
bucket = "test-1253833068" | ||
compress_type = "gzip" | ||
endpoint = "https://test-1253833068.cos.ap-nanjing.myqcloud.com" | ||
region = "ap-nanjing" | ||
} | ||
} | ||
` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.