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

New Resource: alicloud_vpc_ipam_service. #8135

Merged
merged 1 commit into from
Jan 15, 2025
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
1 change: 1 addition & 0 deletions alicloud/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -887,6 +887,7 @@ func Provider() terraform.ResourceProvider {
"alicloud_vpc_ipam_ipams": dataSourceAliCloudVpcIpamIpams(),
},
ResourcesMap: map[string]*schema.Resource{
"alicloud_vpc_ipam_service": resourceAliCloudVpcIpamService(),
"alicloud_alb_load_balancer_zone_shifted_attachment": resourceAliCloudAlbLoadBalancerZoneShiftedAttachment(),
"alicloud_alb_load_balancer_access_log_config_attachment": resourceAliCloudAlbLoadBalancerAccessLogConfigAttachment(),
"alicloud_data_works_di_alarm_rule": resourceAliCloudDataWorksDiAlarmRule(),
Expand Down
104 changes: 104 additions & 0 deletions alicloud/resource_alicloud_vpc_ipam_service.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
// Package alicloud. This file is generated automatically. Please do not modify it manually, thank you!
package alicloud

import (
"log"
"time"

util "github.com/alibabacloud-go/tea-utils/service"
"github.com/aliyun/terraform-provider-alicloud/alicloud/connectivity"
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
)

func resourceAliCloudVpcIpamService() *schema.Resource {
return &schema.Resource{
Create: resourceAliCloudVpcIpamServiceCreate,
Read: resourceAliCloudVpcIpamServiceRead,
Delete: resourceAliCloudVpcIpamServiceDelete,
Importer: &schema.ResourceImporter{
State: schema.ImportStatePassthrough,
},
Timeouts: &schema.ResourceTimeout{
Create: schema.DefaultTimeout(5 * time.Minute),
Delete: schema.DefaultTimeout(5 * time.Minute),
},
Schema: map[string]*schema.Schema{
"enabled": {
Type: schema.TypeBool,
Computed: true,
},
},
}
}

func resourceAliCloudVpcIpamServiceCreate(d *schema.ResourceData, meta interface{}) error {

client := meta.(*connectivity.AliyunClient)

action := "OpenVpcIpamService"
var request map[string]interface{}
var response map[string]interface{}
query := make(map[string]interface{})
conn, err := client.NewVpcipamClient()
if err != nil {
return WrapError(err)
}
request = make(map[string]interface{})
request["RegionId"] = client.RegionId
request["ClientToken"] = buildClientToken(action)

runtime := util.RuntimeOptions{}
runtime.SetAutoretry(true)
wait := incrementalWait(3*time.Second, 5*time.Second)
err = resource.Retry(d.Timeout(schema.TimeoutCreate), func() *resource.RetryError {
response, err = conn.DoRequest(StringPointer(action), nil, StringPointer("POST"), StringPointer("2023-02-28"), StringPointer("AK"), query, request, &runtime)
if IsExpectedErrors(err, []string{"CURRENT_USER_QUANTITY_EXCEED"}) {
return nil
}
if err != nil {
if NeedRetry(err) {
wait()
return resource.RetryableError(err)
}
return resource.NonRetryableError(err)
}
return nil
})
addDebug(action, response, request)

if err != nil {
return WrapErrorf(err, DefaultErrorMsg, "alicloud_vpc_ipam_service", action, AlibabaCloudSdkGoERROR)
}

accountId, err := client.AccountId()
d.SetId(accountId)

return resourceAliCloudVpcIpamServiceRead(d, meta)
}

func resourceAliCloudVpcIpamServiceRead(d *schema.ResourceData, meta interface{}) error {
client := meta.(*connectivity.AliyunClient)
vpcIpamServiceV2 := VpcIpamServiceV2{client}

objectRaw, err := vpcIpamServiceV2.DescribeVpcIpamService(d.Id())
if err != nil {
if !d.IsNewResource() && NotFoundError(err) {
log.Printf("[DEBUG] Resource alicloud_vpc_ipam_service DescribeVpcIpamService Failed!!! %s", err)
d.SetId("")
return nil
}
return WrapError(err)
}

if objectRaw["Enabled"] != nil {
d.Set("enabled", objectRaw["Enabled"])
}

return nil
}

func resourceAliCloudVpcIpamServiceDelete(d *schema.ResourceData, meta interface{}) error {
log.Printf("[WARN] Cannot destroy resource AliCloud Resource Service. Terraform will remove this resource from the state file, however resources may remain.")
return nil
}
65 changes: 65 additions & 0 deletions alicloud/resource_alicloud_vpc_ipam_service_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package alicloud

import (
"fmt"
"testing"

"github.com/aliyun/terraform-provider-alicloud/alicloud/connectivity"
"github.com/hashicorp/terraform-plugin-sdk/helper/acctest"
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
)

// Test VpcIpam Service. >>> Resource test cases, automatically generated.
// Case ccc 8406
func TestAccAliCloudVpcIpamService_basic8406(t *testing.T) {
var v map[string]interface{}
resourceId := "alicloud_vpc_ipam_service.default"
ra := resourceAttrInit(resourceId, AlicloudVpcIpamServiceMap8406)
rc := resourceCheckInitWithDescribeMethod(resourceId, &v, func() interface{} {
return &VpcIpamServiceV2{testAccProvider.Meta().(*connectivity.AliyunClient)}
}, "DescribeVpcIpamService")
rac := resourceAttrCheckInit(rc, ra)
testAccCheck := rac.resourceAttrMapUpdateSet()
rand := acctest.RandIntRange(10000, 99999)
name := fmt.Sprintf("tf-testacc%svpcipamservice%d", defaultRegionToTest, rand)
testAccConfig := resourceTestAccConfigFunc(resourceId, name, AlicloudVpcIpamServiceBasicDependence8406)
resource.Test(t, resource.TestCase{
PreCheck: func() {
testAccPreCheckWithRegions(t, true, []connectivity.Region{"cn-hangzhou"})
testAccPreCheck(t)
},
IDRefreshName: resourceId,
Providers: testAccProviders,
CheckDestroy: nil,
Steps: []resource.TestStep{
{
Config: testAccConfig(map[string]interface{}{}),
Check: resource.ComposeTestCheckFunc(
testAccCheck(map[string]string{}),
),
},
{
ResourceName: resourceId,
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{},
},
},
})
}

var AlicloudVpcIpamServiceMap8406 = map[string]string{
"enabled": CHECKSET,
}

func AlicloudVpcIpamServiceBasicDependence8406(name string) string {
return fmt.Sprintf(`
variable "name" {
default = "%s"
}


`, name)
}

// Test VpcIpam Service. <<< Resource test cases, automatically generated.
72 changes: 72 additions & 0 deletions alicloud/service_alicloud_vpc_ipam_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -529,3 +529,75 @@ func (s *VpcIpamServiceV2) VpcIpamIpamPoolAllocationStateRefreshFunc(id string,
}

// DescribeVpcIpamIpamPoolAllocation >>> Encapsulated.

// DescribeVpcIpamService <<< Encapsulated get interface for VpcIpam Service.

func (s *VpcIpamServiceV2) DescribeVpcIpamService(id string) (object map[string]interface{}, err error) {
client := s.client
var request map[string]interface{}
var response map[string]interface{}
var query map[string]interface{}
conn, err := client.NewVpcipamClient()
if err != nil {
return object, WrapError(err)
}
request = make(map[string]interface{})
query = make(map[string]interface{})
request["RegionId"] = client.RegionId
action := "GetVpcIpamServiceStatus"
request["ClientToken"] = buildClientToken(action)

runtime := util.RuntimeOptions{}
runtime.SetAutoretry(true)
wait := incrementalWait(3*time.Second, 5*time.Second)
err = resource.Retry(1*time.Minute, func() *resource.RetryError {
response, err = conn.DoRequest(StringPointer(action), nil, StringPointer("POST"), StringPointer("2023-02-28"), StringPointer("AK"), query, request, &runtime)
request["ClientToken"] = buildClientToken(action)

if err != nil {
if NeedRetry(err) {
wait()
return resource.RetryableError(err)
}
return resource.NonRetryableError(err)
}
return nil
})
addDebug(action, response, request)
if err != nil {
return object, WrapErrorf(err, DefaultErrorMsg, id, action, AlibabaCloudSdkGoERROR)
}

return response, nil
}

func (s *VpcIpamServiceV2) VpcIpamServiceStateRefreshFunc(id string, field string, failStates []string) resource.StateRefreshFunc {
return func() (interface{}, string, error) {
object, err := s.DescribeVpcIpamService(id)
if err != nil {
if NotFoundError(err) {
return object, "", nil
}
return nil, "", WrapError(err)
}

v, err := jsonpath.Get(field, object)
currentStatus := fmt.Sprint(v)

if strings.HasPrefix(field, "#") {
v, _ := jsonpath.Get(strings.TrimPrefix(field, "#"), object)
if v != nil {
currentStatus = "#CHECKSET"
}
}

for _, failState := range failStates {
if currentStatus == failState {
return object, currentStatus, WrapError(Error(FailedToReachTargetStatus, currentStatus))
}
}
return object, currentStatus, nil
}
}

// DescribeVpcIpamService >>> Encapsulated.
62 changes: 62 additions & 0 deletions website/docs/r/vpc_ipam_service.html.markdown
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
---
subcategory: "Vpc Ipam"
layout: "alicloud"
page_title: "Alicloud: alicloud_vpc_ipam_service"
description: |-
Provides a Alicloud Vpc Ipam Service resource.
---

# alicloud_vpc_ipam_service

Provides a Vpc Ipam Service resource.

Ipam service, used to support automatic provisioning of Terraform.

For information about Vpc Ipam Service and how to use it, see [What is Service](https://www.alibabacloud.com/help/en/).

-> **NOTE:** Available since v1.242.0.

## Example Usage

Basic Usage

```terraform
variable "name" {
default = "terraform-example"
}

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


resource "alicloud_vpc_ipam_service" "default" {
}
```

### Deleting `alicloud_vpc_ipam_service` or removing it from your configuration

Terraform cannot destroy resource `alicloud_vpc_ipam_service`. Terraform will remove this resource from the state file, however resources may remain.

## Argument Reference

The following arguments are supported:

## Attributes Reference

The following attributes are exported:
* `id` - The ID of the resource supplied above.The value is formulated as ``.
* `enabled` - Whether the IPAM service has been activated.

## Timeouts

The `timeouts` block allows you to specify [timeouts](https://www.terraform.io/docs/configuration-0-11/resources.html#timeouts) for certain actions:
* `create` - (Defaults to 5 mins) Used when create the Service.

## Import

Vpc Ipam Service can be imported using the id, e.g.

```shell
$ terraform import alicloud_vpc_ipam_service.example
```
Loading