Skip to content
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

support iec vpc resource and docs #775

Merged
merged 1 commit into from
Dec 25, 2020
Merged
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
63 changes: 63 additions & 0 deletions docs/resources/iec_vpc.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
---
subcategory: "Intelligent EdgeCloud (IEC)"
---

# huaweicloud\_iec_vpc

Manages an IEC VPC resource within HuaweiCloud.

## Example Usage

```hcl
variable "vpc_name" {}
variable "vpc_cidr" {}

resource "huaweicloud_iec_vpc" "vpc" {
name = var.vpc_name
cidr = var.vpc_cidr
}

resource "huaweicloud_iec_vpc" "vpc_by_customer" {
name = var.vpc_name
cidr = var.vpc_cidr
mode = "CUSTOMER"
}
```

## Argument Reference

The following arguments are supported:

* `region` - (Optional, String, ForceNew) The region in which to create the IEC VPC. If omitted,
the provider-level region will be used. Changing this creates a new resource.

* `name` - (Required, String) Specifies the name of the IEC VPC. The name can contain a maximum of 64 characters.
Only letters, digits, underscores (_), hyphens (-), and periods (.) are allowed.

* `cidr` - (Required, String) Specifies the IP address range for the VPC. The subnet IP address in the VPC
must be within the IP address range of the VPC. The following CIDR blocks are supported:
*10.0.0.0/8-16*, *172.16.0.0/12-16*, *192.168.0.0/16*.

* `mode` - (Optional, String, ForceNew) Specifies the mode of the IEC VPC. Possible values are "SYSTEM" and "CUSTOMER",
defaults to "SYSTEM". Changing this creates a new IEC VPC.

## Attributes Reference

In addition to all arguments above, the following attributes are exported:

* `id` - ID of the IEC VPC.
* `subent_num` - Indicates the number of subents.

## Timeouts

This resource provides the following timeouts configuration options:
- `create` - Default is 10 minute.
- `delete` - Default is 3 minute.

## Import

VPCs can be imported using the `id`, e.g.

```
$ terraform import huaweicloud_iec_vpc.myvpc 7117d38e-4c8f-4624-a505-bd96b97d024c
```
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ require (
github.com/hashicorp/errwrap v1.0.0
github.com/hashicorp/go-cleanhttp v0.5.1
github.com/hashicorp/terraform-plugin-sdk v1.13.0
github.com/huaweicloud/golangsdk v0.0.0-20201224083252-010617edf28c
github.com/huaweicloud/golangsdk v0.0.0-20201225034918-fe22e43ed768
github.com/jen20/awspolicyequivalence v0.0.0-20170831201602-3d48364a137a
github.com/mitchellh/go-homedir v1.1.0
github.com/smartystreets/goconvey v0.0.0-20190222223459-a17d461953aa // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,8 @@ github.com/huaweicloud/golangsdk v0.0.0-20201223081519-cedf29b4891c h1:Wn/clEpob
github.com/huaweicloud/golangsdk v0.0.0-20201223081519-cedf29b4891c/go.mod h1:fcOI5u+0f62JtJd7zkCch/Z57BNC6bhqb32TKuiF4r0=
github.com/huaweicloud/golangsdk v0.0.0-20201224083252-010617edf28c h1:Igfi5l8W6r8NGUVOZyaIt1m6JZQqo9Lx5bOXbx53qyE=
github.com/huaweicloud/golangsdk v0.0.0-20201224083252-010617edf28c/go.mod h1:fcOI5u+0f62JtJd7zkCch/Z57BNC6bhqb32TKuiF4r0=
github.com/huaweicloud/golangsdk v0.0.0-20201225034918-fe22e43ed768 h1:v+5rLipFpQ99TnlPneFWn28mw6koeLtXgplfDdpDWag=
github.com/huaweicloud/golangsdk v0.0.0-20201225034918-fe22e43ed768/go.mod h1:fcOI5u+0f62JtJd7zkCch/Z57BNC6bhqb32TKuiF4r0=
github.com/jen20/awspolicyequivalence v0.0.0-20170831201602-3d48364a137a h1:FyS/ubzBR5xJlnJGRTwe7GUHpJOR4ukYK3y+LFNffuA=
github.com/jen20/awspolicyequivalence v0.0.0-20170831201602-3d48364a137a/go.mod h1:uoIMjNxUfXi48Ci40IXkPRbghZ1vbti6v9LCbNqRgHY=
github.com/jmespath/go-jmespath v0.0.0-20160202185014-0b12d6b521d8/go.mod h1:Nht3zPeWKUH0NzdCt2Blrr5ys8VGpn0CEB0cQHVjt7k=
Expand Down
1 change: 1 addition & 0 deletions huaweicloud/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,7 @@ func Provider() terraform.ResourceProvider {
"huaweicloud_identity_role": resourceIdentityRole(),
"huaweicloud_identity_role_assignment": ResourceIdentityRoleAssignmentV3(),
"huaweicloud_identity_user": ResourceIdentityUserV3(),
"huaweicloud_iec_vpc": ResourceIecVpc(),
"huaweicloud_images_image": ResourceImsImage(),
"huaweicloud_kms_key": resourceKmsKeyV1(),
"huaweicloud_lb_certificate": ResourceCertificateV2(),
Expand Down
138 changes: 138 additions & 0 deletions huaweicloud/resource_huaweicloud_iec_vpc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
package huaweicloud

import (
"fmt"
"log"
"time"

"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/huaweicloud/golangsdk/openstack/iec/v1/vpcs"
)

func ResourceIecVpc() *schema.Resource {
return &schema.Resource{
Create: resourceIecVpcV1Create,
Read: resourceIecVpcV1Read,
Update: resourceIecVpcV1Update,
Delete: resourceIecVpcV1Delete,

Importer: &schema.ResourceImporter{
State: schema.ImportStatePassthrough,
},
Timeouts: &schema.ResourceTimeout{
Create: schema.DefaultTimeout(10 * time.Minute),
Delete: schema.DefaultTimeout(3 * time.Minute),
},

Schema: map[string]*schema.Schema{
"region": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
},
"name": {
Type: schema.TypeString,
Required: true,
},
"cidr": {
Type: schema.TypeString,
Required: true,
},
"mode": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
Default: "SYSTEM",
},
"subnet_num": {
Type: schema.TypeInt,
Computed: true,
},
},
}
}

func resourceIecVpcV1Create(d *schema.ResourceData, meta interface{}) error {
config := meta.(*Config)
iecV1Client, err := config.IECV1Client(GetRegion(d, config))

if err != nil {
return fmt.Errorf("Error creating Huaweicloud IEC client: %s", err)
}

createOpts := vpcs.CreateOpts{
Name: d.Get("name").(string),
Cidr: d.Get("cidr").(string),
Mode: d.Get("mode").(string),
}

n, err := vpcs.Create(iecV1Client, createOpts).Extract()
if err != nil {
return fmt.Errorf("Error creating Huaweicloud IEC VPC: %s", err)
}

log.Printf("[INFO] IEC VPC ID: %s", n.ID)
d.SetId(n.ID)

return resourceIecVpcV1Read(d, meta)
}

func resourceIecVpcV1Read(d *schema.ResourceData, meta interface{}) error {
config := meta.(*Config)
iecV1Client, err := config.IECV1Client(GetRegion(d, config))
if err != nil {
return fmt.Errorf("Error creating Huaweicloud IEC client: %s", err)
}

n, err := vpcs.Get(iecV1Client, d.Id()).Extract()
if err != nil {
return CheckDeleted(d, err, "Error retrieving Huaweicloud IEC VPC")
}

d.Set("name", n.Name)
d.Set("cidr", n.Cidr)
d.Set("mode", n.Mode)
d.Set("subnet_num", n.SubnetNum)

return nil
}

func resourceIecVpcV1Update(d *schema.ResourceData, meta interface{}) error {
config := meta.(*Config)
iecV1Client, err := config.IECV1Client(GetRegion(d, config))
if err != nil {
return fmt.Errorf("Error creating Huaweicloud IEC client: %s", err)
}

var updateOpts vpcs.UpdateOpts

if d.HasChange("name") {
updateOpts.Name = d.Get("name").(string)
}
if d.HasChange("cidr") {
updateOpts.Cidr = d.Get("cidr").(string)
}

_, err = vpcs.Update(iecV1Client, d.Id(), updateOpts).Extract()
if err != nil {
return fmt.Errorf("Error updating Huaweicloud IEC VPC: %s", err)
}

return resourceIecVpcV1Read(d, meta)
}

func resourceIecVpcV1Delete(d *schema.ResourceData, meta interface{}) error {
config := meta.(*Config)
iecV1Client, err := config.IECV1Client(GetRegion(d, config))
if err != nil {
return fmt.Errorf("Error creating Huaweicloud IEC client: %s", err)
}

err = vpcs.Delete(iecV1Client, d.Id()).ExtractErr()
if err != nil {
return CheckDeleted(d, err, "Error retrieving Huaweicloud IEC VPC")
}

d.SetId("")
return nil
}
Loading