Giter Club home page Giter Club logo

terraform-alicloud-vpc's Introduction

Alicloud VPC, VSwitch and Route Entry Terraform Module terraform-alicloud-vpc

English | 简体中文

A terraform module used to create an Alibaba Cloud VPC, several VSwitches and configure route entry.

  • The module contains one VPC, several VSwitches and several custom route entries.
  • If VPC is not specified, the module will launch a new one using default parameters.
  • The number of VSwitch depends on the length of the parameter vswitch_cidrs.
  • The number of custom route entry depends on the length of the parameter destination_cidrs
  • Each VSwitch needs an availability zone. If the length of availability_zones is less than the length of vswitch_cidrs, availability_zones item will be used repeatedly.

The following resources are supported:

Usage

module "vpc" {
  source  = "alibaba/vpc/alicloud"

  create            = true
  vpc_name          = "my-env-vpc"
  vpc_cidr          = "10.10.0.0/16"
  resource_group_id = "rg-acfmwvvtg5o****"

  availability_zones = ["cn-hangzhou-e", "cn-hangzhou-f", "cn-hangzhou-g"]
  vswitch_cidrs      = ["10.10.1.0/24", "10.10.2.0/24", "10.10.3.0/24"]

  vpc_tags = {
    Owner       = "user"
    Environment = "staging"
    Name        = "complete"
  }

  vswitch_tags = {
    Project  = "Secret"
    Endpoint = "true"
  }

  destination_cidrs = var.destination_cidrs
  nexthop_ids       = var.server_ids
}

Examples

Notes

From the version v1.9.0, the module has removed the following provider setting:

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/vpc"
}

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

module "vpc" {
  source  = "alibaba/vpc/alicloud"

  version     = "1.8.0"
  region      = "cn-hangzhou"
  profile     = "Your-Profile-Name"

  create            = true
  vpc_name          = "my-env-vpc"
  // ...
}

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

provider "alicloud" {
  region  = "cn-hangzhou"
  profile = "Your-Profile-Name"
}
module "vpc" {
  source  = "alibaba/vpc/alicloud"

  create            = true
  vpc_name          = "my-env-vpc"
  // ...
}

or specify an alias provider with a defined region to the module using providers:

provider "alicloud" {
  region  = "cn-hangzhou"
  profile = "Your-Profile-Name"
  alias   = "hz"
}

module "vpc" {
  source  = "alibaba/vpc/alicloud"

  providers = {
    alicloud = alicloud.hz
  }

  create            = true
  vpc_name          = "my-env-vpc"
  // ...
}

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

Terraform versions

Name Version
terraform >= 0.13.0
alicloud >= 1.56.0

Submit Issues

If you have any problems when using this module, please opening a provider issue and let us know.

Note: There does not recommend to open an issue on this repo.

Authors

Created and maintained by Alibaba Cloud Terraform Team([email protected])

License

Apache 2 Licensed. See LICENSE for full details.

Reference

terraform-alicloud-vpc's People

Contributors

alibaba-oss avatar andyzhang495 avatar github-actions[bot] avatar lexsss avatar mrwolong avatar shanye997 avatar wanghx0991 avatar xiaozhu36 avatar zql-tqy avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

terraform-alicloud-vpc's Issues

Error when I use this module

I come across the following errors suddenly in this morning which works perfectly ok previuosly:

on .terraform/modules/vpc/main.tf line 25, in resource "alicloud_vswitch" "vswitches":
25: resource "alicloud_vswitch" "vswitches" {

Error: missing expected [

Warning: "name": [DEPRECATED] Field 'name' has been deprecated from provider version 1.119.0. New field 'vswitch_name' instead.

on .terraform/modules/vpc/main.tf line 25, in resource "alicloud_vswitch" "vswitches":
25: resource "alicloud_vswitch" "vswitches" {

Error: .gateways[0].ip_lists[0]: missing expected {

Please suggest the solution. Thanks.
Screen Shot 2021-04-12 at 10 45 53 AM

add repo description

Can you please add a short repo description so that it can be seen in the icon view of within the Terraform registry.

Once you've add a description, you'll need to create a new version/tag in order for the registry to pull the edited repository information.

Thanks,
Chris

Outputs not working as specified

When trying to use the terraform outputs as specified here, some outputs show no value.

The specification lists following outputs:

cidr_block
Description: Deprecated and use this_vpc_cidr_block instead

this_vpc_name
Description: The VPC name

this_vpc_cidr_block
Description: The VPC cidr block

this_vpc_cidr_block and this_vpc_name do not seem to work at all.
They are used in the complete vpc example and are returning following output:

Outputs:

vpc_cidr_block = ""
vpc_name = ""

Using the deprecated cidr_block, I get an output for the cidr, but I did not find a way to get the name into the output:

Outputs:

vpc_cidr_block = "10.10.0.0/16"
vpc_name = ""
Terraform v0.15.4
on darwin_amd64
+ provider registry.terraform.io/aliyun/alicloud v1.124.0
+ provider registry.terraform.io/hashicorp/alicloud v1.124.0

vswitch resource uses deprecated argument name instead of vswitch_name vpc_name

https://github.com/terraform-alicloud-modules/terraform-alicloud-vpc/blob/master/main.tf#L22

resource "alicloud_vpc" "vpc" {
  count             = var.vpc_id != "" ? 0 : var.create ? 1 : 0
  vpc_name              = var.vpc_name
  cidr_block        = var.vpc_cidr
  resource_group_id = var.resource_group_id
  description       = var.vpc_description
  tags = merge(
    {
      "Name" = format("%s", var.vpc_name)
    },
    var.vpc_tags,
  )
}

resource "alicloud_vswitch" "vswitches" {
  count             = local.create_sub_resources ? length(var.vswitch_cidrs) : 0
  vpc_id            = var.vpc_id != "" ? var.vpc_id : concat(alicloud_vpc.vpc.*.id, [""])[0]
  cidr_block        = var.vswitch_cidrs[count.index]
  availability_zone = element(var.availability_zones, count.index)
  vswitch_name            = length(var.vswitch_cidrs) > 1 || var.use_num_suffix ? format("%s%03d", var.vswitch_name, count.index + 1) : var.vswitch_name
  description       = var.vswitch_description
  tags = merge(
    {
      Name = format(
        "%s%03d",
        var.vswitch_name,
        count.index + 1
      )
    },
    var.vswitch_tags,
  )
}

variable configuration

Hi'
Thank you for offer this module. I'm confused when i use this module. By default setting, it will appear an error when i run the command: terraform plan.
configuration is as fellow:
destination_cidrs = "${var.destination_cidrs}"
nexthop_ids = "${var.server_ids}"
I config the variable destination_cidrs with a ip network segment in the variable.tf file. but it can not work. It sames that the root main file can not reference the module variables. When I derect to set the 'destination_cidrs' and 'nexthop_ids' to a net segment. It can be work fine. Did you have some suggest for me. Thank you very much.

Alicloud Terraform always creating VPC in Beijing region

Hi Team,

Whenever I am trying to create a VPC no matter what region I mention in the provider it is creating the VPC in Beijing region. I am trying to create the VPC in Shanghai region but it creates it in Beijing region.

I tried creating alicloud_vpc resource but it is same. I also tried to create using existing module "vpc" from alicloud but still same.

Following is what I tried.

With alicloud_vpc resource :

provider "alicloud" {
  region     = "cn-shanghai"
}

resource "alicloud_vpc" "vpc" {
  description       = "Default VPC"
  cidr_block        = "10.0.0.0/8"
  vpc_name          = "test-vpc"
  enable_ipv6       = false
  resource_group_id = var.resource_group_id
}

data "alicloud_regions" "current_region_ds" {
  current = true
}

the output for current region shows :
current_region_id = "cn-shanghai"

tried this way also but still same result:


module "vpc" {
  source  = "alibaba/vpc/alicloud"
  region = "cn-shanghai"
  create            = true
  vpc_name          = "my-env-vpc"
  vpc_cidr          = "10.0.0.0/8"
  resource_group_id = "rg-acfmwvvtg5o****"

}

About the license

The README.md shows Apache 2 Licensed, but the license file reads Mozilla Public License Version 2.0.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.