Skip to content

Commit

Permalink
Support abroad domain cache config
Browse files Browse the repository at this point in the history
  • Loading branch information
tamperMonkeyZQ committed May 9, 2024
1 parent c94fee1 commit 841e977
Show file tree
Hide file tree
Showing 7 changed files with 256 additions and 84 deletions.
165 changes: 83 additions & 82 deletions baiducloud/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -265,88 +265,89 @@ func Provider() terraform.ResourceProvider {
},

ResourcesMap: map[string]*schema.Resource{
"baiducloud_instance": resourceBaiduCloudInstance(),
"baiducloud_cds": resourceBaiduCloudCDS(),
"baiducloud_cds_attachment": resourceBaiduCloudCDSAttachment(),
"baiducloud_snapshot": resourceBaiduCloudSnapshot(),
"baiducloud_auto_snapshot_policy": resourceBaiduCloudAutoSnapshotPolicy(),
"baiducloud_vpc": resourceBaiduCloudVpc(),
"baiducloud_subnet": resourceBaiduCloudSubnet(),
"baiducloud_route_rule": resourceBaiduCloudRouteRule(),
"baiducloud_security_group": resourceBaiduCloudSecurityGroup(),
"baiducloud_security_group_rule": resourceBaiduCloudSecurityGroupRule(),
"baiducloud_eip": resourceBaiduCloudEip(),
"baiducloud_eipbp": resourceBaiduCloudEipbp(),
"baiducloud_eipgroup": resourceBaiduCloudEipgroup(),
"baiducloud_eip_association": resourceBaiduCloudEipAssociation(),
"baiducloud_acl": resourceBaiduCloudAcl(),
"baiducloud_nat_gateway": resourceBaiduCloudNatGateway(),
"baiducloud_nat_snat_rule": resourceBaiduCloudNatSnatRule(),
"baiducloud_blb": resourceBaiduCloudBLB(),
"baiducloud_blb_listener": resourceBaiduCloudBlbListener(),
"baiducloud_blb_backend_server": resourceBaiduCloudBlbBackendServer(),
"baiducloud_blb_securitygroup": resourceBaiduCloudBlbSecurityGroup(),
"baiducloud_appblb": resourceBaiduCloudAppBLB(),
"baiducloud_peer_conn": resourceBaiduCloudPeerConn(),
"baiducloud_peer_conn_acceptor": resourceBaiduCloudPeerConnAcceptor(),
"baiducloud_appblb_server_group": resourceBaiduCloudAppBlbServerGroup(),
"baiducloud_appblb_listener": resourceBaiduCloudAppBlbListener(),
"baiducloud_bos_bucket": resourceBaiduCloudBosBucket(),
"baiducloud_bos_bucket_object": resourceBaiduCloudBucketObject(),
"baiducloud_cert": resourceBaiduCloudCert(),
"baiducloud_cfc_function": resourceBaiduCloudCFCFunction(),
"baiducloud_cfc_alias": resourceBaiduCloudCFCAlias(),
"baiducloud_cfc_version": resourceBaiduCloudCFCVersion(),
"baiducloud_cfc_trigger": resourceBaiduCloudCFCTrigger(),
"baiducloud_scs": resourceBaiduCloudScs(),
"baiducloud_cce_cluster": resourceBaiduCloudCCECluster(),
"baiducloud_ccev2_cluster": resourceBaiduCloudCCEv2Cluster(),
"baiducloud_ccev2_instance": resourceBaiduCloudCCEv2Instance(),
"baiducloud_ccev2_instance_group": resourceBaiduCloudCCEv2InstanceGroup(),
"baiducloud_rds_instance": resourceBaiduCloudRdsInstance(),
"baiducloud_rds_readonly_instance": resourceBaiduCloudRdsReadOnlyInstance(),
"baiducloud_rds_account": resourceBaiduCloudRdsAccount(),
"baiducloud_rds_security_ip": resourceBaiduCloudRdsSecurityIp(),
"baiducloud_dts": resourceBaiduCloudDts(),
"baiducloud_dns_zone": resourceBaiduCloudDnsZone(),
"baiducloud_dns_customline": resourceBaiduCloudDnsCustomline(),
"baiducloud_dns_record": resourceBaiduCloudDnsRecord(),
"baiducloud_iam_user": resourceBaiduCloudIamUser(),
"baiducloud_iam_group": resourceBaiduCloudIamGroup(),
"baiducloud_iam_group_membership": resourceBaiduCloudIamGroupMembership(),
"baiducloud_iam_policy": resourceBaiduCloudIamPolicy(),
"baiducloud_iam_user_policy_attachment": resourceBaiduCloudIamUserPolicyAttachment(),
"baiducloud_iam_group_policy_attachment": resourceBaiduCloudIamGroupPolicyAttachment(),
"baiducloud_cdn_domain": cdn.ResourceDomain(),
"baiducloud_abroad_cdn_domain": abroad.ResourceAbroadDomain(),
"baiducloud_cdn_domain_config_cache": cdn.ResourceDomainConfigCache(),
"baiducloud_cdn_domain_config_acl": cdn.ResourceDomainConfigACL(),
"baiducloud_cdn_domain_config_origin": cdn.ResourceDomainConfigOrigin(),
"baiducloud_cdn_domain_config_advanced": cdn.ResourceDomainConfigAdvanced(),
"baiducloud_cdn_domain_config_https": cdn.ResourceDomainConfigHttps(),
"baiducloud_localdns_privatezone": resourceBaiduCloudLocalDnsPrivateZone(),
"baiducloud_localdns_vpc": resourceBaiduCloudLocalDnsVpc(),
"baiducloud_localdns_record": resourceBaiduCloudPrivateZoneRecord(),
"baiducloud_bbc_instance": resourceBaiduCloudBccInstance(),
"baiducloud_bbc_image": resourceBaiduCloudBbcImage(),
"baiducloud_deployset": resourceBaiduCloudDeploySet(),
"baiducloud_vpn_gateway": resourceBaiduCloudVpnGateway(),
"baiducloud_vpn_conn": resourceBaiduCloudVpnConn(),
"baiducloud_eni": resourceBaiduCloudEni(),
"baiducloud_eni_attachment": resourceBaiduCloudEniInstanceAttachment(),
"baiducloud_cfs": resourceBaiduCloudCfs(),
"baiducloud_cfs_mount_target": resourceBaiduCloudCfsMountTarget(),
"baiducloud_sms_signature": resourceBaiduCloudSMSSignature(),
"baiducloud_sms_template": resourceBaiduCloudSMSTemplate(),
"baiducloud_bls_log_store": resourceBaiduCloudBLSLogStore(),
"baiducloud_snic": snic.ResourceSNIC(),
"baiducloud_bec_vm_instance": bec.ResourceVMInstance(),
"baiducloud_bcc_key_pair": bcc.ResourceKeyPair(),
"baiducloud_iam_access_key": iam.ResourceAccessKey(),
"baiducloud_et_gateway": resourceBaiduCloudEtGateway(),
"baiducloud_et_gateway_association": resourceBaiduCloudEtGatewayAssociation(),
"baiducloud_mongodb_instance": mongodb.ResourceInstance(),
"baiducloud_mongodb_sharding_instance": mongodb.ResourceShardingInstance(),
"baiducloud_instance": resourceBaiduCloudInstance(),
"baiducloud_cds": resourceBaiduCloudCDS(),
"baiducloud_cds_attachment": resourceBaiduCloudCDSAttachment(),
"baiducloud_snapshot": resourceBaiduCloudSnapshot(),
"baiducloud_auto_snapshot_policy": resourceBaiduCloudAutoSnapshotPolicy(),
"baiducloud_vpc": resourceBaiduCloudVpc(),
"baiducloud_subnet": resourceBaiduCloudSubnet(),
"baiducloud_route_rule": resourceBaiduCloudRouteRule(),
"baiducloud_security_group": resourceBaiduCloudSecurityGroup(),
"baiducloud_security_group_rule": resourceBaiduCloudSecurityGroupRule(),
"baiducloud_eip": resourceBaiduCloudEip(),
"baiducloud_eipbp": resourceBaiduCloudEipbp(),
"baiducloud_eipgroup": resourceBaiduCloudEipgroup(),
"baiducloud_eip_association": resourceBaiduCloudEipAssociation(),
"baiducloud_acl": resourceBaiduCloudAcl(),
"baiducloud_nat_gateway": resourceBaiduCloudNatGateway(),
"baiducloud_nat_snat_rule": resourceBaiduCloudNatSnatRule(),
"baiducloud_blb": resourceBaiduCloudBLB(),
"baiducloud_blb_listener": resourceBaiduCloudBlbListener(),
"baiducloud_blb_backend_server": resourceBaiduCloudBlbBackendServer(),
"baiducloud_blb_securitygroup": resourceBaiduCloudBlbSecurityGroup(),
"baiducloud_appblb": resourceBaiduCloudAppBLB(),
"baiducloud_peer_conn": resourceBaiduCloudPeerConn(),
"baiducloud_peer_conn_acceptor": resourceBaiduCloudPeerConnAcceptor(),
"baiducloud_appblb_server_group": resourceBaiduCloudAppBlbServerGroup(),
"baiducloud_appblb_listener": resourceBaiduCloudAppBlbListener(),
"baiducloud_bos_bucket": resourceBaiduCloudBosBucket(),
"baiducloud_bos_bucket_object": resourceBaiduCloudBucketObject(),
"baiducloud_cert": resourceBaiduCloudCert(),
"baiducloud_cfc_function": resourceBaiduCloudCFCFunction(),
"baiducloud_cfc_alias": resourceBaiduCloudCFCAlias(),
"baiducloud_cfc_version": resourceBaiduCloudCFCVersion(),
"baiducloud_cfc_trigger": resourceBaiduCloudCFCTrigger(),
"baiducloud_scs": resourceBaiduCloudScs(),
"baiducloud_cce_cluster": resourceBaiduCloudCCECluster(),
"baiducloud_ccev2_cluster": resourceBaiduCloudCCEv2Cluster(),
"baiducloud_ccev2_instance": resourceBaiduCloudCCEv2Instance(),
"baiducloud_ccev2_instance_group": resourceBaiduCloudCCEv2InstanceGroup(),
"baiducloud_rds_instance": resourceBaiduCloudRdsInstance(),
"baiducloud_rds_readonly_instance": resourceBaiduCloudRdsReadOnlyInstance(),
"baiducloud_rds_account": resourceBaiduCloudRdsAccount(),
"baiducloud_rds_security_ip": resourceBaiduCloudRdsSecurityIp(),
"baiducloud_dts": resourceBaiduCloudDts(),
"baiducloud_dns_zone": resourceBaiduCloudDnsZone(),
"baiducloud_dns_customline": resourceBaiduCloudDnsCustomline(),
"baiducloud_dns_record": resourceBaiduCloudDnsRecord(),
"baiducloud_iam_user": resourceBaiduCloudIamUser(),
"baiducloud_iam_group": resourceBaiduCloudIamGroup(),
"baiducloud_iam_group_membership": resourceBaiduCloudIamGroupMembership(),
"baiducloud_iam_policy": resourceBaiduCloudIamPolicy(),
"baiducloud_iam_user_policy_attachment": resourceBaiduCloudIamUserPolicyAttachment(),
"baiducloud_iam_group_policy_attachment": resourceBaiduCloudIamGroupPolicyAttachment(),
"baiducloud_cdn_domain": cdn.ResourceDomain(),
"baiducloud_abroad_cdn_domain": abroad.ResourceAbroadDomain(),
"baiducloud_abroad_cdn_domain_config_cache": abroad.ResourceAbroadDomainConfigCache(),
"baiducloud_cdn_domain_config_cache": cdn.ResourceDomainConfigCache(),
"baiducloud_cdn_domain_config_acl": cdn.ResourceDomainConfigACL(),
"baiducloud_cdn_domain_config_origin": cdn.ResourceDomainConfigOrigin(),
"baiducloud_cdn_domain_config_advanced": cdn.ResourceDomainConfigAdvanced(),
"baiducloud_cdn_domain_config_https": cdn.ResourceDomainConfigHttps(),
"baiducloud_localdns_privatezone": resourceBaiduCloudLocalDnsPrivateZone(),
"baiducloud_localdns_vpc": resourceBaiduCloudLocalDnsVpc(),
"baiducloud_localdns_record": resourceBaiduCloudPrivateZoneRecord(),
"baiducloud_bbc_instance": resourceBaiduCloudBccInstance(),
"baiducloud_bbc_image": resourceBaiduCloudBbcImage(),
"baiducloud_deployset": resourceBaiduCloudDeploySet(),
"baiducloud_vpn_gateway": resourceBaiduCloudVpnGateway(),
"baiducloud_vpn_conn": resourceBaiduCloudVpnConn(),
"baiducloud_eni": resourceBaiduCloudEni(),
"baiducloud_eni_attachment": resourceBaiduCloudEniInstanceAttachment(),
"baiducloud_cfs": resourceBaiduCloudCfs(),
"baiducloud_cfs_mount_target": resourceBaiduCloudCfsMountTarget(),
"baiducloud_sms_signature": resourceBaiduCloudSMSSignature(),
"baiducloud_sms_template": resourceBaiduCloudSMSTemplate(),
"baiducloud_bls_log_store": resourceBaiduCloudBLSLogStore(),
"baiducloud_snic": snic.ResourceSNIC(),
"baiducloud_bec_vm_instance": bec.ResourceVMInstance(),
"baiducloud_bcc_key_pair": bcc.ResourceKeyPair(),
"baiducloud_iam_access_key": iam.ResourceAccessKey(),
"baiducloud_et_gateway": resourceBaiduCloudEtGateway(),
"baiducloud_et_gateway_association": resourceBaiduCloudEtGatewayAssociation(),
"baiducloud_mongodb_instance": mongodb.ResourceInstance(),
"baiducloud_mongodb_sharding_instance": mongodb.ResourceShardingInstance(),
},

ConfigureFunc: providerConfigure,
Expand Down
53 changes: 53 additions & 0 deletions baiducloud/resource_baiducloud_rds_readonly_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,26 @@ func resourceBaiduCloudRdsReadOnlyInstance() *schema.Resource {
},
},
},
"auto_renew_time_unit": {
Type: schema.TypeString,
Description: "Time unit of automatic renewal, the value can be month or year. " +
"The default value is month. " +
"It is valid only when the payment_timing is Prepaid.",
Optional: true,
ForceNew: true,
Default: "month",
ValidateFunc: validation.StringInSlice([]string{"month", "year"}, false),
},
"auto_renew_time_length": {
Type: schema.TypeInt,
Description: "The time length of automatic renewal, empty indicating no automatic renewal." +
"It is valid when payment_timing is Prepaid, " +
"and the value should be 1-9 when the auto_renew_time_unit is month and 1-3 when the " +
"auto_renew_time_unit is year.",
Optional: true,
ForceNew: true,
ValidateFunc: validation.IntBetween(1, 9),
},
"reservation": {
Type: schema.TypeMap,
Description: "Reservation of the Rds.",
Expand Down Expand Up @@ -279,6 +299,39 @@ func resourceBaiduCloudRdsReadOnlyInstanceCreate(d *schema.ResourceData, meta in
if err != nil {
return err
}
// 开启自动续费
err = resource.Retry(d.Timeout(schema.TimeoutCreate), func() *resource.RetryError {
raw, err := client.WithRdsClient(func(rdsClient *rds.Client) (interface{}, error) {
args := &rds.AutoRenewArgs{
InstanceIds: []string{d.Id()},
}
if v, ok := d.GetOk("auto_renew_time_length"); ok {
args.AutoRenewTime = v.(int)
if args.AutoRenewTime > 0 {
if v, ok := d.GetOk("auto_renew_time_unit"); ok {
args.AutoRenewTimeUnit = v.(string)
}
} else {
return nil, WrapErrorf(nil, DefaultErrorMsg, "baiducloud_rds_readonly_instance",
action, "auto renew time invalid")
}
} else {
return nil, nil
}
return nil, rdsClient.AutoRenew(args)
})
if err != nil {
if IsExceptedErrors(err, []string{bce.EINTERNAL_ERROR}) {
return resource.RetryableError(err)
}
return resource.NonRetryableError(err)
}
addDebug(action, raw)
return nil
})
if err != nil {
return err
}
return resourceBaiduCloudRdsReadOnlyInstanceRead(d, meta)
}

Expand Down
2 changes: 1 addition & 1 deletion baiducloud/service/cdn/abroad/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func cacheTTLHash(v interface{}) int {
s = append(s, strconv.Itoa(v.(int)))
}
if v, ok := tfMap["override_origin"]; ok {
s = append(s, v.(string))
s = append(s, strconv.FormatBool(v.(bool)))
}
return hashcode.Strings(s)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
terraform import baiducloud_abroad_cdn_domain_config_cache.example example1.domain.com
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
resource "baiducloud_abroad_cdn_domain" "default" {
domain = "test.cdn.com"

origin {
backup = false
type = "IP"
addr = "1.2.3.4"
}
tags = {
terraform = "terraform-test2"
}
}

resource "baiducloud_abroad_cdn_domain_config_cache" "example" {
domain = baiducloud_abroad_cdn_domain.default.domain
cache_ttl {
type = "suffix"
value = ".png"
ttl = 36000
weight = 30
}
cache_ttl {
type = "path"
value = "/to/my/file"
ttl = 1800
weight = 5
}
}
88 changes: 88 additions & 0 deletions website/docs/r/abroad_cdn_domain_cache.html.markdown
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "baiducloud_abroad_cdn_domain_config_cache Resource - terraform-provider-baiducloud"
subcategory: "Content Delivery Network (CDN) (abroad version)"
description: |-
Use this resource to manage cache-related configuration of the abroad acceleration domain.
More information can be found in the Developer Guide https://cloud.baidu.com/doc/CDN-ABROAD/s/Zkbstm0vg.
~> NOTE: Creating a resource will overwrite current cache-related configuration. Deleting a resource won't change current configuration.
---

# baiducloud_abroad_cdn_domain_config_cache (Resource)

Use this resource to manage cache-related configuration of the abroad acceleration domain.

More information can be found in the [Developer Guide](https://cloud.baidu.com/doc/CDN-ABROAD/s/Zkbstm0vg).

~> **NOTE:** Creating a resource will overwrite current cache-related configuration. Deleting a resource won't change current configuration.

## Example Usage

```terraform
resource "baiducloud_abroad_cdn_domain" "default" {
domain = "test.cdn.com"
origin {
backup = false
type = "IP"
addr = "1.2.3.4"
}
tags = {
terraform = "terraform-test2"
}
}
resource "baiducloud_abroad_cdn_domain_config_cache" "example" {
domain = baiducloud_abroad_cdn_domain.default.domain
cache_ttl {
type = "suffix"
value = ".png"
ttl = 36000
weight = 30
}
cache_ttl {
type = "path"
value = "/to/my/file"
ttl = 1800
weight = 5
}
}
```

<!-- schema generated by tfplugindocs -->
## Schema

### Required

- `domain` (String) Name of the abroad acceleration domain.

### Optional

- `cache_full_url` (Boolean) Whether caching of full url is enabled. Defaults to `true`
- `cache_ttl` (Block Set) Cache expiration rules of the abroad acceleration domain. (see [below for nested schema](#nestedblock--cache_ttl))

### Read-Only

- `id` (String) The ID of this resource.

<a id="nestedblock--cache_ttl"></a>
### Nested Schema for `cache_ttl`

Required:

- `ttl` (Number) Cache duration in seconds.
- `type` (String) Cache rule type. Valid values: `suffix`(file name suffix), `path`(directory in the url), `origin`(origin server rule. There is only one such rule, and only `weight` is required. Set `value` to `-`, `ttl` to `0`), `exactPath`(path is completely matched).
- `value` (String) Configuration rule for the specified type.

Optional:

- `override_origin` (Boolean) Whether to override the origin site’s caching rules. Defaults to `true`
- `weight` (Number) The origin server weight. Must be between `0` and `100`. Defaults to `0`. The higher the weight, the higher the priority. No effect when `type` is `code`.

## Import

Import is supported using the following syntax:

```shell
terraform import baiducloud_abroad_cdn_domain_config_cache.example example1.domain.com
```
Loading

0 comments on commit 841e977

Please sign in to comment.