Skip to content

Commit

Permalink
Implement import state for st-alicloud_aliadb_resource_group_bind_use…
Browse files Browse the repository at this point in the history
…r. (#42)

* Implement import state.

* Updated tfplugins.

* Bugfix ram policy description.

---------

Co-authored-by: [email protected] <[email protected]>
  • Loading branch information
ArthurEatsCode and [email protected] authored Nov 28, 2023
1 parent 3f0a492 commit 161e3bf
Show file tree
Hide file tree
Showing 20 changed files with 102 additions and 67 deletions.
70 changes: 64 additions & 6 deletions alicloud/resource_aliadb_resource_group_bind_user.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,27 @@ package alicloud

import (
"context"
"errors"
"strings"
"time"

"github.com/cenkalti/backoff"

alicloudAdbClient "github.com/alibabacloud-go/adb-20190315/v2/client"
util "github.com/alibabacloud-go/tea-utils/v2/service"
"github.com/alibabacloud-go/tea/tea"
"github.com/hashicorp/terraform-plugin-framework/path"
"github.com/hashicorp/terraform-plugin-framework/resource"
"github.com/hashicorp/terraform-plugin-framework/resource/schema"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier"
"github.com/hashicorp/terraform-plugin-framework/types"

alicloudAdbClient "github.com/alibabacloud-go/adb-20190315/v2/client"
)

var (
_ resource.Resource = &aliadbResourceGroupBindResource{}
_ resource.ResourceWithConfigure = &aliadbResourceGroupBindResource{}
_ resource.Resource = &aliadbResourceGroupBindResource{}
_ resource.ResourceWithConfigure = &aliadbResourceGroupBindResource{}
_ resource.ResourceWithImportState = &aliadbResourceGroupBindResource{}
)

func NewAliadbResourceGroupBindResource() resource.Resource {
Expand Down Expand Up @@ -115,10 +118,65 @@ func (r *aliadbResourceGroupBindResource) Create(ctx context.Context, req resour

// Read resource group user bind resource information
func (r *aliadbResourceGroupBindResource) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) {
// Alicloud doesn't provide a SDK for describing resource group user binding, the read function will not be implemented.
var state *aliadbResourceGroupBindResourceModel

// Retrieve values from state
getStateDiags := req.State.Get(ctx, &state)
resp.Diagnostics.Append(getStateDiags...)
if resp.Diagnostics.HasError() {
return
}

describeDBResourceGroupRequest := &alicloudAdbClient.DescribeDBResourceGroupRequest{
DBClusterId: tea.String(state.DBClusterId.ValueString()),
GroupName: tea.String(state.GroupName.ValueString()),
}
runtime := &util.RuntimeOptions{}
_, err := r.client.DescribeDBResourceGroupWithOptions(describeDBResourceGroupRequest, runtime)
if err != nil {
return
}

// Set state to plan data
setStateDiags := resp.State.Set(ctx, &state)
resp.Diagnostics.Append(setStateDiags...)
if resp.Diagnostics.HasError() {
return
}
}

func (r *aliadbResourceGroupBindResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) {
importID := req.ID

groupName, userName, dbClusterId, err := parseImportID(importID)
if err != nil {
resp.Diagnostics.AddError(
"Error importing item",
"Could not import item, unexpected error (ID should be an integer): "+err.Error(),
)
return
}

// Set the group_name, group_user and dbcluster_id as attributes in the response's state
resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("group_name"), groupName)...)
resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("group_user"), userName)...)
resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("dbcluster_id"), dbClusterId)...)

}

func parseImportID(importID string) (string, string, string, error) {
id := strings.Split(importID, ":")
if len(id) != 3 {
return "", "", "", errors.New("Invalid import ID format. The correct format looks like this GroupName:GroupUser:DBClusterID")
}

groupName := id[0]
userName := id[1]
dbClusterId := id[2]
return groupName, userName, dbClusterId, nil
}

// Update updates the DNS weight resource and sets the updated Terraform state on success.
// Update updates the resource group user binding and sets the updated Terraform state on success.
func (r *aliadbResourceGroupBindResource) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) {
var plan *aliadbResourceGroupBindResourceModel

Expand Down
2 changes: 1 addition & 1 deletion alicloud/resource_ram_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func (r *ramPolicyResource) Schema(_ context.Context, _ resource.SchemaRequest,
Description: "Provides a RAM Policy resource that manages policy content " +
"exceeding character limits by splitting it into smaller segments. " +
"These segments are combined to form a complete policy attached to " +
"the user. However, the policy` that exceed the maximum length of a " +
"the user. However, the policy that exceed the maximum length of a " +
"policy, they will be attached directly to the user.",
Attributes: map[string]schema.Attribute{
"attached_policies": schema.ListAttribute{
Expand Down
2 changes: 1 addition & 1 deletion docs/data-sources/cdn_domain.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "st-alicloud_cdn_domain Data Source - st-alicloud"
page_title: "st-alicloud_cdn_domain Data Source - terraform-provider-st-alicloud"
subcategory: ""
description: |-
This data source provides the CDN Instance of the current Alibaba Cloud user.
Expand Down
2 changes: 1 addition & 1 deletion docs/data-sources/cs_user_kubeconfig.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "st-alicloud_cs_user_kubeconfig Data Source - st-alicloud"
page_title: "st-alicloud_cs_user_kubeconfig Data Source - terraform-provider-st-alicloud"
subcategory: ""
description: |-
This data source provides the Kubeconfig of container service for the set Alibaba Cloud user.
Expand Down
2 changes: 1 addition & 1 deletion docs/data-sources/ddoscoo_domain_resources.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "st-alicloud_ddoscoo_domain_resources Data Source - st-alicloud"
page_title: "st-alicloud_ddoscoo_domain_resources Data Source - terraform-provider-st-alicloud"
subcategory: ""
description: |-
This data source provides the AntiDDoS domain resources of the current AliCloud user.
Expand Down
4 changes: 1 addition & 3 deletions docs/data-sources/ddoscoo_instances.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "st-alicloud_ddoscoo_instances Data Source - st-alicloud"
page_title: "st-alicloud_ddoscoo_instances Data Source - terraform-provider-st-alicloud"
subcategory: ""
description: |-
This data source provides the AntiDDoS domain resources of the current AliCloud user.
Expand Down Expand Up @@ -63,5 +63,3 @@ Read-Only:
- `remark` (String) Remark of AntiDDoS instance.
- `service_bandwidth` (Number) Service bandwidth of AntiDDoS instance.
- `status` (Number) Status of AntiDDoS instance.


4 changes: 1 addition & 3 deletions docs/data-sources/slb_load_balancers.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "st-alicloud_slb_load_balancers Data Source - st-alicloud"
page_title: "st-alicloud_slb_load_balancers Data Source - terraform-provider-st-alicloud"
subcategory: ""
description: |-
This data source provides the Server Load Balancers in desired region or user account.
Expand Down Expand Up @@ -66,5 +66,3 @@ Read-Only:
- `name` (String) The name of the SLB.
- `slave_zone_id` (String) Slave zone of the SLB.
- `tags` (Map of String) The tags of the SLB.


2 changes: 1 addition & 1 deletion docs/resources/aliadb_resource_group_bind_user.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "st-alicloud_aliadb_resource_group_bind_user Resource - st-alicloud"
page_title: "st-alicloud_aliadb_resource_group_bind_user Resource - terraform-provider-st-alicloud"
subcategory: ""
description: |-
Provides a Aliadb resource group association resource.
Expand Down
4 changes: 2 additions & 2 deletions docs/resources/alidns_domain_attachment.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "st-alicloud_alidns_domain_attachment Resource - st-alicloud"
page_title: "st-alicloud_alidns_domain_attachment Resource - terraform-provider-st-alicloud"
subcategory: ""
description: |-
---

# st-alicloud_alidns_domain_attachment (Resource)
Expand Down
4 changes: 1 addition & 3 deletions docs/resources/alidns_gtm_instance.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "st-alicloud_alidns_gtm_instance Resource - st-alicloud"
page_title: "st-alicloud_alidns_gtm_instance Resource - terraform-provider-st-alicloud"
subcategory: ""
description: |-
Provides a Alidns Gtm Instance resource.
Expand Down Expand Up @@ -68,5 +68,3 @@ Optional:
- `dingtalk_notice` (Boolean) Whether to configure DingTalk notifications. Valid values: true, false.
- `email_notice` (Boolean) Whether to configure mail notification. Valid values: true, false.
- `sms_notice` (Boolean) Whether to configure SMS notification. Valid values: true, false.


4 changes: 2 additions & 2 deletions docs/resources/alidns_instance.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "st-alicloud_alidns_instance Resource - st-alicloud"
page_title: "st-alicloud_alidns_instance Resource - terraform-provider-st-alicloud"
subcategory: ""
description: |-
---

# st-alicloud_alidns_instance (Resource)
Expand Down
4 changes: 1 addition & 3 deletions docs/resources/alidns_record_weight.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "st-alicloud_alidns_record_weight Resource - st-alicloud"
page_title: "st-alicloud_alidns_record_weight Resource - terraform-provider-st-alicloud"
subcategory: ""
description: |-
Provides a Alidns record weight resource.
Expand Down Expand Up @@ -30,5 +30,3 @@ resource "st-alicloud_alidns_record_weight" "def" {
### Read-Only

- `status` (Boolean) Subdomain Weight Status


4 changes: 1 addition & 3 deletions docs/resources/cms_composite_group_metric_rule.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "st-alicloud_cms_composite_group_metric_rule Resource - st-alicloud"
page_title: "st-alicloud_cms_composite_group_metric_rule Resource - terraform-provider-st-alicloud"
subcategory: ""
description: |-
Provides a Cloud Monitor Service alarm rule resource.
Expand Down Expand Up @@ -52,5 +52,3 @@ Required:
- `expression_raw` (String) Alarm rule expression.
- `level` (String) Alarm alert level.
- `times` (Number) Alarm retry times.


4 changes: 1 addition & 3 deletions docs/resources/cms_system_event_contact_group_attachment.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "st-alicloud_cms_system_event_contact_group_attachment Resource - st-alicloud"
page_title: "st-alicloud_cms_system_event_contact_group_attachment Resource - terraform-provider-st-alicloud"
subcategory: ""
description: |-
Provides a Alicloud CMS System Event Contact Group Attachment Resource.
Expand Down Expand Up @@ -28,5 +28,3 @@ resource "st-alicloud_cms_system_event_contact_group_attachment" "contact_group_
- `contact_group_name` (String) The name of the alert contact group.
- `level` (String) The alert notification methods.
- `rule_name` (String) The name of the event-triggered alert rule.


17 changes: 9 additions & 8 deletions docs/resources/ddoscoo_webconfig_ai_protect_config.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "st-alicloud_ddoscoo_webconfig_ai_protect_config Resource - st-alicloud"
page_title: "st-alicloud_ddoscoo_webconfig_ai_protect_config Resource - terraform-provider-st-alicloud"
subcategory: ""
description: |-
Modify AI Protect Mode in Anti-DDoS configuration.
Modify a domain AI Protect Mode in Anti-DDoS website configuration.
---

# st-alicloud_ddoscoo_webconfig_ai_protect_config (Resource)

Modify AI Protect Mode in Anti-DDoS configuration.
Modify a domain AI Protect Mode in Anti-DDoS website configuration.

## Example Usage

```terraform
resource "st-alicloud_ddoscoo_webconfig_ai_protect_config" "test" {
enabled = true
domain = "api.xxx.com"
enabled = true
domain = "api.xxxx.com"
mode = "warning"
level = "normal"
}
Expand All @@ -26,9 +26,10 @@ resource "st-alicloud_ddoscoo_webconfig_ai_protect_config" "test" {

### Required

- `enabled` (Boolean) Enable/Disable of AI Protect Mode status. <br/>**Valid values**: `true`, `false`.
- `domain` (String) Domain name.
- `enabled` (Boolean) Enable/Disable of ai protect mode status.

### Optional
- `mode` (String) config to set AiMode. <br/>**Valid values**: `warning`, `protection`. default to `protection`.
- `level` (String) config to set AiTemplate. <br/>**Valid values**: `loose`, `normal`, `strict`. default to `normal`.

- `level` (String) config to set AiTemplate.
- `mode` (String) config to set AiMode.
11 changes: 6 additions & 5 deletions docs/resources/ddoscoo_webconfig_ssl_attachment.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "st-alicloud_ddoscoo_webconfig_ssl_attachment Resource - st-alicloud"
page_title: "st-alicloud_ddoscoo_webconfig_ssl_attachment Resource - terraform-provider-st-alicloud"
subcategory: ""
description: |-
Associate the domain with the TLS version of the SSL certificate and cipher suite in the Anti-DDoS website configuration. [Document](https://www.alibabacloud.com/help/en/ddos-protection/latest/api-ddoscoo-2020-01-01-modifytlsconfig?spm=a2c63.p38356.0.0.419b504fICZVeU)
Associate the domain with the TLS version of the SSL certificate and cipher suite in the Anti-DDoS website configuration. Document https://www.alibabacloud.com/help/en/ddos-protection/latest/api-ddoscoo-2020-01-01-modifytlsconfig?spm=a2c63.p38356.0.0.419b504fICZVeU
---

# st-alicloud_ddoscoo_webconfig_ssl_attachment (Resource)

Associate the domain with the TLS version of the SSL certificate and cipher suite in the Anti-DDoS website configuration. [Document](https://www.alibabacloud.com/help/en/ddos-protection/latest/api-ddoscoo-2020-01-01-modifytlsconfig?spm=a2c63.p38356.0.0.419b504fICZVeU)
Associate the domain with the TLS version of the SSL certificate and cipher suite in the Anti-DDoS website configuration. [Document](https://www.alibabacloud.com/help/en/ddos-protection/latest/api-ddoscoo-2020-01-01-modifytlsconfig?spm=a2c63.p38356.0.0.419b504fICZVeU)

## Example Usage

Expand All @@ -30,5 +30,6 @@ resource "st-alicloud_ddoscoo_webconfig_ssl_attachment" "bind_ssl" {
- `domain` (String) Domain name.

### Optional
- `tls_version` (String) TLS Versions for SSL Certificate. <br/>**Valid values**: `tls1.0`, `tls1.1`, `tls1.2` . default to `tls1.0`.
- `cipher_suites` (String) Cipher Suites for SSL Certificate. <br/>**Valid values**: `all`, `strong`, `default`, `improved`. <br/> `tls1.0` & `tls1.1` only can accept `all`, `strong`, `default`. <br/> Only `tls1.2` can support up to `all`, `strong`, `default`, `improved`. default to `default`.

- `cipher_suites` (String) Cipher Suites for SSL Certificate.
- `tls_version` (String) TLS Versions for SSL Certificate.
19 changes: 5 additions & 14 deletions docs/resources/emr_metric_auto_scaling_rules.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "st-alicloud_emr_metric_auto_scaling_rules Resource - st-alicloud"
page_title: "st-alicloud_emr_metric_auto_scaling_rules Resource - terraform-provider-st-alicloud"
subcategory: ""
description: |-
Auto scaling rule for AliCloud E-MapReduce cluster nodes.
Expand Down Expand Up @@ -69,7 +69,6 @@ resource "st-alicloud_emr_metric_auto_scaling_rules" "metric_auto_scaling" {
```

<!-- schema generated by tfplugindocs -->

## Schema

### Required
Expand All @@ -87,15 +86,14 @@ resource "st-alicloud_emr_metric_auto_scaling_rules" "metric_auto_scaling" {
- `node_group_id` (String) Alicloud E-MapReduce cluster task node group ID.

<a id="nestedblock--scaling_rule"></a>

### Nested Schema for `scaling_rule`

Required:

- `evaluation_count` (Number) Amount of times scaling is triggered. (Repetitions that trigger scale out.)
- `multi_metric_relationship` (String) Determines whether auto scaling triggers when all metrics match the rules **(And)** or any metrics match the rules **(Or)**. <br/>**Accepted values**: `And`, `Or`.
- `multi_metric_relationship` (String) Determines whether auto scaling triggers when all metrics trigger (And) or any metrics are triggered (Or). Accepted Values: "And", "Or".
- `rule_name` (String) Auto scaling rule name.
- `scale_operation` (String) Scaling mode, scale out (up) or scale in (down). <br/>**Accepted values**: `SCALE_OUT`, `SCALE_IN`
- `scale_operation` (String) Scaling mode, scale out (up) or scale in (down). Accepted values: "SCALE_OUT", "SCALE_IN"
- `scaling_node_count` (Number) Number of nodes being scaled up or down.
- `statistical_period` (Number) Period to collect cluster load metrics.

Expand All @@ -105,18 +103,11 @@ Optional:
- `metric_rule` (Block List) (see [below for nested schema](#nestedblock--scaling_rule--metric_rule))

<a id="nestedblock--scaling_rule--metric_rule"></a>

### Nested Schema for `scaling_rule.metric_rule`

Required:

- `comparison_operator` (String) Comparison operator. <br/>**Accepted values**:
`EQ`: equals,
`NE`: not equals,
`GT`: greater than,
`LT`: lesser than,
`GE`: greater or equal,
`LE`: lesser or equal.
- `comparison_operator` (String) Comparison operator. Accepted values: "EQ": equals, "NE": not equals, "GT": greater than, "LT": lesser than, "GE": greater or equal, "LE": lesser or equal.
- `metric_name` (String) Metric name.
- `statistical_measure` (String) Statistical measure. <br/>**Accepted values**: `AVG`, `MIN`, `MAX`.
- `statistical_measure` (String) Statistical measure. Accepted values: "AVG", "MIN", "MAX".
- `threshold` (Number) Threshold percentage of metric to trigger auto scaling.
2 changes: 1 addition & 1 deletion docs/resources/ess_clb_default_server_group_attachment.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "st-alicloud_ess_clb_default_server_group_attachment Resource - st-alicloud"
page_title: "st-alicloud_ess_clb_default_server_group_attachment Resource - terraform-provider-st-alicloud"
subcategory: ""
description: |-
Attach an auto scaling group (ESS) with a list of load balancers (CLB) default server group.
Expand Down
4 changes: 1 addition & 3 deletions docs/resources/ram_policy.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "st-alicloud_ram_policy Resource - st-alicloud"
page_title: "st-alicloud_ram_policy Resource - terraform-provider-st-alicloud"
subcategory: ""
description: |-
Provides a RAM Policy resource that manages policy content exceeding character limits by splitting it into smaller segments. These segments are combined to form a complete policy attached to the user. However, the policy that exceed the maximum length of a policy, they will be attached directly to the user.
Expand Down Expand Up @@ -38,5 +38,3 @@ Read-Only:

- `policy_document` (String) The policy document of the RAM policy.
- `policy_name` (String) The policy name.


Loading

0 comments on commit 161e3bf

Please sign in to comment.