Skip to content

新增加 alicloud_vswitch,alicloud_vpc 资源查询 #15

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 67 additions & 5 deletions README-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ terraform-alicloud-redis

## Terraform 版本

本模板要求使用版本 Terraform 0.12 和阿里云 Provider 1.56.0+。
| Name | Version |
|------|---------|
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 0.12.0 |
| <a name="requirement_alicloud"></a> [alicloud](#requirement\_alicloud) | >= 1.56.0

## 用法

Expand All @@ -23,7 +26,6 @@ terraform-alicloud-redis
```hcl
module "redis" {
source = "terraform-alicloud-modules/redis/alicloud"
region = "cn-beijing"
#################
# Redis Instance
#################
Expand Down Expand Up @@ -85,7 +87,6 @@ module "redis" {
```hcl
module "redis" {
source = "terraform-alicloud-modules/redis/alicloud"
region = "cn-beijing"
#################
# Redis Instance
#################
Expand Down Expand Up @@ -152,12 +153,73 @@ module "redis" {
更多模板详见 [Modules](https://github.com/terraform-alicloud-modules/terraform-alicloud-redis/tree/master/modules).

## 注意事项
本Module从版本v1.3.0开始已经移除掉如下的 provider 的显示设置:
```hcl
provider "alicloud" {
profile = var.profile != "" ? var.profile : null
shared_credentials_file = var.shared_credentials_file != "" ? var.shared_credentials_file : null
region = var.region != "" ? var.region : null
skip_region_validation = var.skip_region_validation
configuration_source = "terraform-alicloud-modules/redis"
}
```

如果你依然想在Module中使用这个 provider 配置,你可以在调用Module的时候,指定一个特定的版本,比如 1.2.0:

```hcl
module "redis" {
source = "terraform-alicloud-modules/redis/alicloud"
version = "1.2.0"
region = "cn-hangzhou"
profile = "Your-Profile-Name"

alarm_rule_name = "CmsAlarmForRedis"
alarm_rule_statistics = "Average"
alarm_rule_period = 300
alarm_rule_operator = "<="
}
```
如果你想对正在使用中的Module升级到 1.3.0 或者更高的版本,那么你可以在模板中显示定义一个相同Region的provider:
```hcl
provider "alicloud" {
region = "cn-hangzhou"
profile = "Your-Profile-Name"
}
module "redis" {
source = "terraform-alicloud-modules/redis/alicloud"
alarm_rule_name = "CmsAlarmForRedis"
alarm_rule_statistics = "Average"
alarm_rule_period = 300
alarm_rule_operator = "<="
}
```
或者,如果你是多Region部署,你可以利用 `alias` 定义多个 provider,并在Module中显示指定这个provider:

```hcl
provider "alicloud" {
region = "cn-hangzhou"
profile = "Your-Profile-Name"
alias = "hz"
}
module "redis" {
source = "terraform-alicloud-modules/redis/alicloud"
providers = {
alicloud = alicloud.hz
}
alarm_rule_name = "CmsAlarmForRedis"
alarm_rule_statistics = "Average"
alarm_rule_period = 300
alarm_rule_operator = "<="
}
```

定义完provider之后,运行命令 `terraform init` 和 `terraform apply` 来让这个provider生效即可。

* 本 Module 使用的 AccessKey 和 SecretKey 可以直接从 `profile` 和 `shared_credentials_file` 中获取。如果未设置,可通过下载安装 [aliyun-cli](https://github.com/aliyun/aliyun-cli#installation) 后进行配置。
更多provider的使用细节,请移步[How to use provider in the module](https://www.terraform.io/docs/language/modules/develop/providers.html#passing-providers-explicitly)

作者
-------
Created and maintained by Yi Jincheng([email protected]), He Guimin(@xiaozhu36, heguimin36@163.com)
Created and maintained by Alibaba Cloud Terraform Team(terraform@alibabacloud.com)

许可
----
Expand Down
75 changes: 69 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ These types of resources are supported:

## Terraform versions

This module requires Terraform 0.12 and Terraform Provider Alicloud 1.56.0+.
| Name | Version |
|------|---------|
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 0.12.0 |
| <a name="requirement_alicloud"></a> [alicloud](#requirement\_alicloud) | >= 1.56.0

Usage
-----
Expand All @@ -26,7 +29,6 @@ Be careful:Create Account supports redis instances of version 4.0 or above.
```hcl
module "redis" {
source = "terraform-alicloud-modules/redis/alicloud"
region = "cn-beijing"
#################
# Redis Instance
#################
Expand Down Expand Up @@ -89,7 +91,6 @@ Be careful:Create Account supports redis instances of version 4.0 or above.
```hcl
module "redis" {
source = "terraform-alicloud-modules/redis/alicloud"
region = "cn-beijing"
#################
# Redis Instance
#################
Expand Down Expand Up @@ -156,14 +157,76 @@ This module provides rich sub-modules to support different Redis version and usa
See [more modules](https://github.com/terraform-alicloud-modules/terraform-alicloud-redis/tree/master/modules).

## Notes
From the version v1.3.0, the module has removed the following `provider` setting:

* This module using AccessKey and SecretKey are from `profile` and `shared_credentials_file`.
If you have not set them yet, please install [aliyun-cli](https://github.com/aliyun/aliyun-cli#installation) and configure it.
```hcl
provider "alicloud" {
profile = var.profile != "" ? var.profile : null
shared_credentials_file = var.shared_credentials_file != "" ? var.shared_credentials_file : null
region = var.region != "" ? var.region : null
skip_region_validation = var.skip_region_validation
configuration_source = "terraform-alicloud-modules/redis"
}
```

If you still want to use the `provider` setting to apply this module, you can specify a supported version, like 1.2.0:

```hcl
module "redis" {
source = "terraform-alicloud-modules/redis/alicloud"
version = "1.2.0"
region = "cn-hangzhou"
profile = "Your-Profile-Name"

alarm_rule_name = "CmsAlarmForRedis"
alarm_rule_statistics = "Average"
alarm_rule_period = 300
alarm_rule_operator = "<="
}
```

If you want to upgrade the module to 1.3.0 or higher in-place, you can define a provider which same region with
previous region:

```hcl
provider "alicloud" {
region = "cn-hangzhou"
profile = "Your-Profile-Name"
}
module "redis" {
source = "terraform-alicloud-modules/redis/alicloud"
alarm_rule_name = "CmsAlarmForRedis"
alarm_rule_statistics = "Average"
alarm_rule_period = 300
alarm_rule_operator = "<="
}
```
or specify an alias provider with a defined region to the module using `providers`:

```hcl
provider "alicloud" {
region = "cn-hangzhou"
profile = "Your-Profile-Name"
alias = "hz"
}
module "redis" {
source = "terraform-alicloud-modules/redis/alicloud"
providers = {
alicloud = alicloud.hz
}
alarm_rule_name = "CmsAlarmForRedis"
alarm_rule_statistics = "Average"
alarm_rule_period = 300
alarm_rule_operator = "<="
}
```

and then run `terraform init` and `terraform apply` to make the defined provider effect to the existing module state.
More details see [How to use provider in the module](https://www.terraform.io/docs/language/modules/develop/providers.html#passing-providers-explicitly)

Authors
---------
Created and maintained by Yi Jincheng([email protected]), He Guimin(@xiaozhu36, heguimin36@163.com)
Created and maintained by Alibaba Cloud Terraform Team(terraform@alibabacloud.com)

License
----
Expand Down
26 changes: 21 additions & 5 deletions examples/complete/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,39 @@ locals {
data "alicloud_vpcs" "default" {
is_default = true
}

data "alicloud_vswitches" "default" {
zone_id = data.alicloud_zones.default.zones.0.multi_zone_ids.0
vpc_id = length(data.alicloud_vpcs.default.ids) > 0 ? "${data.alicloud_vpcs.default.ids.0}" : alicloud_vpc.default.0.id
}

resource "alicloud_vpc" "default" {
count = length(data.alicloud_vpcs.default.ids) > 0 ? 0 : 1
cidr_block = "172.16.0.0/12"
vpc_name = "test_vpc_007"
}

data "alicloud_zones" "default" {
available_resource_creation = "KVStore"
multi = true
enable_details = true
}

data "alicloud_kvstore_instance_classes" "default" {
zone_id = data.alicloud_zones.default.zones.0.multi_zone_ids.0
engine = local.engine
engine_version = local.engine_version
architecture = local.architecture
}

resource "alicloud_vswitch" "this" {
name = "redis_vpc"
availability_zone = data.alicloud_zones.default.zones.0.multi_zone_ids.0
vpc_id = data.alicloud_vpcs.default.vpcs.0.id
cidr_block = cidrsubnet(data.alicloud_vpcs.default.vpcs.0.cidr_block, 4, 10)
count = length(data.alicloud_vswitches.default.ids) > 0 ? 0 : 1
vswitch_name = "redis_vpc_007"
zone_id = data.alicloud_zones.default.zones.0.multi_zone_ids.0
vpc_id = length(data.alicloud_vpcs.default.ids) > 0 ? data.alicloud_vpcs.default.vpcs.0.id : alicloud_vpc.default.0.id
cidr_block = "172.16.0.0/24"
}

module "redis_example" {
source = "../../"
region = var.region
Expand All @@ -44,7 +60,7 @@ module "redis_example" {
password = "Yourpwd123456"
period = 1
availability_zone = data.alicloud_zones.default.zones.0.multi_zone_ids.0
vswitch_id = alicloud_vswitch.this.id
vswitch_id = length(data.alicloud_vswitches.default.ids) > 0 ? data.alicloud_vswitches.default.ids.0 : alicloud_vswitch.this.0.id
security_ips = ["1.1.1.1", "2.2.2.2", "3.3.3.3"]
tags = {
Env = "Private"
Expand Down
8 changes: 0 additions & 8 deletions main.tf
Original file line number Diff line number Diff line change
@@ -1,11 +1,3 @@
provider "alicloud" {
profile = var.profile != "" ? var.profile : null
shared_credentials_file = var.shared_credentials_file != "" ? var.shared_credentials_file : null
region = var.region != "" ? var.region : null
skip_region_validation = var.skip_region_validation
configuration_source = "terraform-alicloud-modules/redis"
}

locals {
this_instance_id = var.existing_instance_id != "" ? var.existing_instance_id : concat(alicloud_kvstore_instance.this.*.id, [""])[0]
create_more_resources = var.existing_instance_id != "" || var.create_instance ? true : false
Expand Down
8 changes: 0 additions & 8 deletions modules/account/main.tf
Original file line number Diff line number Diff line change
@@ -1,11 +1,3 @@
provider "alicloud" {
profile = var.profile != "" ? var.profile : null
shared_credentials_file = var.shared_credentials_file != "" ? var.shared_credentials_file : null
region = var.region != "" ? var.region : null
skip_region_validation = var.skip_region_validation
configuration_source = "terraform-alicloud-modules/redis"
}

resource "alicloud_kvstore_account" "this" {
count = var.create_account ? length(var.accounts) : 0
instance_id = var.redis_instance_id
Expand Down
8 changes: 4 additions & 4 deletions modules/account/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,23 @@
#################

variable "profile" {
description = "The profile name as set in the shared credentials file. If not set, it will be sourced from the ALICLOUD_PROFILE environment variable."
description = "(Deprecated from version 1.3.0)The profile name as set in the shared credentials file. If not set, it will be sourced from the ALICLOUD_PROFILE environment variable."
default = ""
}

variable "shared_credentials_file" {
description = "This is the path to the shared credentials file. If this is not set and a profile is specified, $HOME/.aliyun/config.json will be used."
description = "(Deprecated from version 1.3.0)This is the path to the shared credentials file. If this is not set and a profile is specified, $HOME/.aliyun/config.json will be used."
default = ""
}

variable "skip_region_validation" {
description = "Skip static validation of region ID. Used by users of alternative AlibabaCloud-like APIs or users w/ access to regions that are not public (yet)."
description = "(Deprecated from version 1.3.0)Skip static validation of region ID. Used by users of alternative AlibabaCloud-like APIs or users w/ access to regions that are not public (yet)."
type = bool
default = false
}

variable "region" {
description = "The region used to launch this module resources."
description = "(Deprecated from version 1.3.0)The region used to launch this module resources."
default = ""
}

Expand Down
7 changes: 0 additions & 7 deletions modules/redis-2.8-communtity-cluster/main.tf
Original file line number Diff line number Diff line change
@@ -1,10 +1,3 @@
provider "alicloud" {
profile = var.profile != "" ? var.profile : null
shared_credentials_file = var.shared_credentials_file != "" ? var.shared_credentials_file : null
region = var.region != "" ? var.region : null
skip_region_validation = var.skip_region_validation
configuration_source = "terraform-alicloud-modules/redis"
}
locals {
engine = "Redis"
engine_version = "2.8"
Expand Down
8 changes: 4 additions & 4 deletions modules/redis-2.8-communtity-cluster/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,22 @@
#################

variable "profile" {
description = "The profile name as set in the shared credentials file. If not set, it will be sourced from the ALICLOUD_PROFILE environment variable."
description = "(Deprecated from version 1.3.0)The profile name as set in the shared credentials file. If not set, it will be sourced from the ALICLOUD_PROFILE environment variable."
default = ""
}

variable "shared_credentials_file" {
description = "This is the path to the shared credentials file. If this is not set and a profile is specified, $HOME/.aliyun/config.json will be used."
description = "(Deprecated from version 1.3.0)This is the path to the shared credentials file. If this is not set and a profile is specified, $HOME/.aliyun/config.json will be used."
default = ""
}

variable "region" {
description = "The region used to launch this module resources."
description = "(Deprecated from version 1.3.0)The region used to launch this module resources."
default = ""
}

variable "skip_region_validation" {
description = "Skip static validation of region ID. Used by users of alternative AlibabaCloud-like APIs or users w/ access to regions that are not public (yet)."
description = "(Deprecated from version 1.3.0)Skip static validation of region ID. Used by users of alternative AlibabaCloud-like APIs or users w/ access to regions that are not public (yet)."
type = bool
default = false
}
Expand Down
7 changes: 0 additions & 7 deletions modules/redis-2.8-communtity-rwsplit/main.tf
Original file line number Diff line number Diff line change
@@ -1,10 +1,3 @@
provider "alicloud" {
profile = var.profile != "" ? var.profile : null
shared_credentials_file = var.shared_credentials_file != "" ? var.shared_credentials_file : null
region = var.region != "" ? var.region : null
skip_region_validation = var.skip_region_validation
configuration_source = "terraform-alicloud-modules/redis"
}
locals {
engine = "Redis"
engine_version = "2.8"
Expand Down
8 changes: 4 additions & 4 deletions modules/redis-2.8-communtity-rwsplit/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,22 @@
#################

variable "profile" {
description = "The profile name as set in the shared credentials file. If not set, it will be sourced from the ALICLOUD_PROFILE environment variable."
description = "(Deprecated from version 1.3.0)The profile name as set in the shared credentials file. If not set, it will be sourced from the ALICLOUD_PROFILE environment variable."
default = ""
}

variable "shared_credentials_file" {
description = "This is the path to the shared credentials file. If this is not set and a profile is specified, $HOME/.aliyun/config.json will be used."
description = "(Deprecated from version 1.3.0)This is the path to the shared credentials file. If this is not set and a profile is specified, $HOME/.aliyun/config.json will be used."
default = ""
}

variable "region" {
description = "The region used to launch this module resources."
description = "(Deprecated from version 1.3.0)The region used to launch this module resources."
default = ""
}

variable "skip_region_validation" {
description = "Skip static validation of region ID. Used by users of alternative AlibabaCloud-like APIs or users w/ access to regions that are not public (yet)."
description = "(Deprecated from version 1.3.0)Skip static validation of region ID. Used by users of alternative AlibabaCloud-like APIs or users w/ access to regions that are not public (yet)."
type = bool
default = false
}
Expand Down
Loading