forked from aliyun/terraform-provider-alicloud
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
A new resource for Resource Manager Resource Directory
- Loading branch information
Showing
6 changed files
with
206 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
81 changes: 81 additions & 0 deletions
81
alicloud/resource_alicloud_resource_manager_resource_directory.go
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,81 @@ | ||
package alicloud | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/aliyun/alibaba-cloud-sdk-go/services/resourcemanager" | ||
"github.com/hashicorp/terraform-plugin-sdk/helper/schema" | ||
"github.com/terraform-providers/terraform-provider-alicloud/alicloud/connectivity" | ||
) | ||
|
||
func resourceAlicloudResourceManagerResourceDirectory() *schema.Resource { | ||
return &schema.Resource{ | ||
Create: resourceAlicloudResourceManagerResourceDirectoryCreate, | ||
Read: resourceAlicloudResourceManagerResourceDirectoryRead, | ||
Delete: resourceAlicloudResourceManagerResourceDirectoryDelete, | ||
Importer: &schema.ResourceImporter{ | ||
State: schema.ImportStatePassthrough, | ||
}, | ||
Schema: map[string]*schema.Schema{ | ||
"master_account_id": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"master_account_name": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"root_folder_id": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func resourceAlicloudResourceManagerResourceDirectoryCreate(d *schema.ResourceData, meta interface{}) error { | ||
client := meta.(*connectivity.AliyunClient) | ||
|
||
request := resourcemanager.CreateInitResourceDirectoryRequest() | ||
raw, err := client.WithResourcemanagerClient(func(resourcemanagerClient *resourcemanager.Client) (interface{}, error) { | ||
return resourcemanagerClient.InitResourceDirectory(request) | ||
}) | ||
if err != nil { | ||
return WrapErrorf(err, DefaultErrorMsg, "alicloud_resource_manager_resource_directory", request.GetActionName(), AlibabaCloudSdkGoERROR) | ||
} | ||
addDebug(request.GetActionName(), raw) | ||
response, _ := raw.(*resourcemanager.InitResourceDirectoryResponse) | ||
d.SetId(fmt.Sprintf("%v", response.ResourceDirectory.ResourceDirectoryId)) | ||
|
||
return resourceAlicloudResourceManagerResourceDirectoryRead(d, meta) | ||
} | ||
func resourceAlicloudResourceManagerResourceDirectoryRead(d *schema.ResourceData, meta interface{}) error { | ||
client := meta.(*connectivity.AliyunClient) | ||
resourcemanagerService := ResourcemanagerService{client} | ||
object, err := resourcemanagerService.DescribeResourceManagerResourceDirectory(d.Id()) | ||
if err != nil { | ||
if NotFoundError(err) { | ||
d.SetId("") | ||
return nil | ||
} | ||
return WrapError(err) | ||
} | ||
|
||
d.Set("master_account_id", object.MasterAccountId) | ||
d.Set("master_account_name", object.MasterAccountName) | ||
d.Set("root_folder_id", object.RootFolderId) | ||
return nil | ||
} | ||
func resourceAlicloudResourceManagerResourceDirectoryDelete(d *schema.ResourceData, meta interface{}) error { | ||
client := meta.(*connectivity.AliyunClient) | ||
request := resourcemanager.CreateDestroyResourceDirectoryRequest() | ||
|
||
raw, err := client.WithResourcemanagerClient(func(resourcemanagerClient *resourcemanager.Client) (interface{}, error) { | ||
return resourcemanagerClient.DestroyResourceDirectory(request) | ||
}) | ||
addDebug(request.GetActionName(), raw) | ||
if err != nil { | ||
return WrapErrorf(err, DefaultErrorMsg, d.Id(), request.GetActionName(), AlibabaCloudSdkGoERROR) | ||
} | ||
return nil | ||
} |
53 changes: 53 additions & 0 deletions
53
alicloud/resource_alicloud_resource_manager_resource_directory_test.go
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,53 @@ | ||
package alicloud | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/aliyun/alibaba-cloud-sdk-go/services/resourcemanager" | ||
"github.com/hashicorp/terraform-plugin-sdk/helper/resource" | ||
"github.com/terraform-providers/terraform-provider-alicloud/alicloud/connectivity" | ||
) | ||
|
||
func TestAccAlicloudResourceManagerResourceDirectory_basic(t *testing.T) { | ||
var v resourcemanager.ResourceDirectory | ||
resourceId := "alicloud_resource_manager_resource_directory.default" | ||
ra := resourceAttrInit(resourceId, ResourceManagerResourceDirectoryMap) | ||
rc := resourceCheckInitWithDescribeMethod(resourceId, &v, func() interface{} { | ||
return &ResourcemanagerService{testAccProvider.Meta().(*connectivity.AliyunClient)} | ||
}, "DescribeResourceManagerResourceDirectory") | ||
rac := resourceAttrCheckInit(rc, ra) | ||
testAccCheck := rac.resourceAttrMapUpdateSet() | ||
testAccConfig := resourceTestAccConfigFunc(resourceId, "", ResourceManagerResourceDirectoryBasicdependence) | ||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { | ||
testAccPreCheck(t) | ||
}, | ||
|
||
IDRefreshName: resourceId, | ||
Providers: testAccProviders, | ||
CheckDestroy: rac.checkResourceDestroy(), | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccConfig(map[string]interface{}{}), | ||
Check: resource.ComposeTestCheckFunc( | ||
testAccCheck(map[string]string{}), | ||
), | ||
}, | ||
{ | ||
ResourceName: resourceId, | ||
ImportState: true, | ||
ImportStateVerify: true, | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
var ResourceManagerResourceDirectoryMap = map[string]string{ | ||
"master_account_id": CHECKSET, | ||
"master_account_name": CHECKSET, | ||
"root_folder_id": CHECKSET, | ||
} | ||
|
||
func ResourceManagerResourceDirectoryBasicdependence(name string) string { | ||
return "" | ||
} |
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
48 changes: 48 additions & 0 deletions
48
website/docs/r/resource_manager_resource_directory.html.markdown
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,48 @@ | ||
--- | ||
subcategory: "Resource Manager" | ||
layout: "alicloud" | ||
page_title: "Alicloud: alicloud_resource_manager_resource_directory" | ||
sidebar_current: "docs-alicloud-resource-resource-manager-resource-directory" | ||
description: |- | ||
Provides a Alicloud Resource Manager Resource Directory resource. | ||
--- | ||
|
||
# alicloud\_resource\_manager\_resource\_directory | ||
|
||
Provides a Resource Manager Resource Directory resource. Resource Directory enables you to establish an organizational structure for the resources used by applications of your enterprise. You can plan, build, and manage the resources in a centralized manner by using only one resource directory. | ||
|
||
For information about Resource Manager Resource Directory and how to use it, see [What is Resource Manager Resource Directory](https://www.alibabacloud.com/help/en/doc-detail/94475.htm). | ||
|
||
-> **NOTE:** Available in v1.84.0+. | ||
|
||
-> **NOTE:** An account can only be used to enable a resource directory after it passes enterprise real-name verification. An account that only passed individual real-name verification cannot be used to enable a resource directory. | ||
|
||
-> **NOTE:** Before you destroy the resource, make sure that the following requirements are met: | ||
- All member accounts must be removed from the resource directory. | ||
- All folders except the root folder must be deleted from the resource directory. | ||
|
||
## Example Usage | ||
|
||
Basic Usage | ||
|
||
``` | ||
resource "alicloud_resource_manager_resource_directory" "example" {} | ||
``` | ||
## Argument Reference | ||
|
||
The resource does not support any argument. | ||
|
||
## Attributes Reference | ||
|
||
* `id` - The ID of the resource directory. | ||
* `master_account_id` - The ID of the master account. | ||
* `master_account_name` - The name of the master account. | ||
* `root_folder_id` - The ID of the root folder. | ||
|
||
## Import | ||
|
||
Resource Manager Resource Directory can be imported using the id, e.g. | ||
|
||
``` | ||
$ terraform import alicloud_resource_manager_resource_directory.example rd-s3**** | ||
``` |