-
Notifications
You must be signed in to change notification settings - Fork 560
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New Resource: alicloud_vpc_ipam_service.
- Loading branch information
1 parent
83d20ce
commit a5e658b
Showing
5 changed files
with
304 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
``` |