-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #133 from volcengine/feat/iam
Feat/iam
- Loading branch information
Showing
24 changed files
with
1,689 additions
and
16 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,21 @@ | ||
resource "volcengine_iam_policy" "foo" { | ||
policy_name = "acc-test-policy" | ||
description = "acc-test" | ||
policy_document = "{\"Statement\":[{\"Effect\":\"Allow\",\"Action\":[\"auto_scaling:DescribeScalingGroups\"],\"Resource\":[\"*\"]}]}" | ||
} | ||
|
||
resource "volcengine_iam_user_group" "foo" { | ||
user_group_name = "acc-test-group" | ||
description = "acc-test" | ||
display_name = "acc-test" | ||
} | ||
|
||
resource "volcengine_iam_user_group_policy_attachment" "foo" { | ||
policy_name = volcengine_iam_policy.foo.policy_name | ||
policy_type = "Custom" | ||
user_group_name = volcengine_iam_user_group.foo.user_group_name | ||
} | ||
|
||
data "volcengine_iam_user_group_policy_attachments" "foo" { | ||
user_group_name = volcengine_iam_user_group_policy_attachment.foo.user_group_name | ||
} |
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,22 @@ | ||
resource "volcengine_vpc_prefix_list" "foo" { | ||
prefix_list_name = "acc-test-prefix" | ||
max_entries = 3 | ||
description = "acc test description" | ||
ip_version = "IPv4" | ||
prefix_list_entries { | ||
cidr = "192.168.4.0/28" | ||
description = "acc-test-1" | ||
} | ||
prefix_list_entries { | ||
cidr = "192.168.5.0/28" | ||
description = "acc-test-2" | ||
} | ||
tags { | ||
key = "tf-key1" | ||
value = "tf-value1" | ||
} | ||
} | ||
|
||
data "volcengine_vpc_prefix_lists" "foo" { | ||
ids = [volcengine_vpc_prefix_list.foo.id] | ||
} |
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,17 @@ | ||
resource "volcengine_iam_policy" "foo" { | ||
policy_name = "acc-test-policy" | ||
description = "acc-test" | ||
policy_document = "{\"Statement\":[{\"Effect\":\"Allow\",\"Action\":[\"auto_scaling:DescribeScalingGroups\"],\"Resource\":[\"*\"]}]}" | ||
} | ||
|
||
resource "volcengine_iam_user_group" "foo" { | ||
user_group_name = "acc-test-group" | ||
description = "acc-test" | ||
display_name = "acc-test" | ||
} | ||
|
||
resource "volcengine_iam_user_group_policy_attachment" "foo" { | ||
policy_name = volcengine_iam_policy.foo.policy_name | ||
policy_type = "Custom" | ||
user_group_name = volcengine_iam_user_group.foo.user_group_name | ||
} |
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,22 @@ | ||
resource "volcengine_vpc_prefix_list" "foo" { | ||
prefix_list_name = "acc-test-prefix" | ||
max_entries = 7 | ||
description = "acc test description" | ||
ip_version = "IPv4" | ||
prefix_list_entries { | ||
cidr = "192.168.4.0/28" | ||
description = "acc-test-1" | ||
} | ||
prefix_list_entries { | ||
cidr = "192.168.9.0/28" | ||
description = "acc-test-4" | ||
} | ||
prefix_list_entries { | ||
cidr = "192.168.8.0/28" | ||
description = "acc-test-5" | ||
} | ||
tags { | ||
key = "tf-key1" | ||
value = "tf-value1" | ||
} | ||
} |
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
68 changes: 68 additions & 0 deletions
68
..._user_group_policy_attachment/data_source_volcengine_iam_user_group_policy_attachments.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,68 @@ | ||
package iam_user_group_policy_attachment | ||
|
||
import ( | ||
"github.com/hashicorp/terraform-plugin-sdk/helper/schema" | ||
ve "github.com/volcengine/terraform-provider-volcengine/common" | ||
) | ||
|
||
func DataSourceVolcengineIamUserGroupPolicyAttachments() *schema.Resource { | ||
return &schema.Resource{ | ||
Read: dataSourceVolcengineIamUserGroupPolicyAttachmentsRead, | ||
Schema: map[string]*schema.Schema{ | ||
"user_group_name": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
Description: "A name of user group.", | ||
}, | ||
"output_file": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
Description: "File name where to save data source results.", | ||
}, | ||
"total_count": { | ||
Type: schema.TypeInt, | ||
Computed: true, | ||
Description: "The total count of query.", | ||
}, | ||
"policies": { | ||
Description: "The collection of query.", | ||
Type: schema.TypeList, | ||
Computed: true, | ||
Elem: &schema.Resource{ | ||
Schema: map[string]*schema.Schema{ | ||
"policy_trn": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
Description: "Resource name of the strategy.", | ||
}, | ||
"policy_name": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
Description: "Name of the policy.", | ||
}, | ||
"policy_type": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
Description: "The type of the policy.", | ||
}, | ||
"attach_date": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
Description: "Attached time.", | ||
}, | ||
"description": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
Description: "The description.", | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func dataSourceVolcengineIamUserGroupPolicyAttachmentsRead(d *schema.ResourceData, meta interface{}) error { | ||
service := NewIamUserGroupPolicyAttachmentService(meta.(*ve.SdkClient)) | ||
return service.Dispatcher.Data(service, d, DataSourceVolcengineIamUserGroupPolicyAttachments()) | ||
} |
95 changes: 95 additions & 0 deletions
95
.../iam_user_group_policy_attachment/resource_volcengine_iam_user_group_policy_attachment.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,95 @@ | ||
package iam_user_group_policy_attachment | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
"time" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/helper/schema" | ||
ve "github.com/volcengine/terraform-provider-volcengine/common" | ||
) | ||
|
||
/* | ||
Import | ||
IamUserGroupPolicyAttachment can be imported using the user group name and policy name, e.g. | ||
``` | ||
$ terraform import volcengine_iam_user_group_policy_attachment.default userGroupName:policyName | ||
``` | ||
*/ | ||
|
||
func ResourceVolcengineIamUserGroupPolicyAttachment() *schema.Resource { | ||
resource := &schema.Resource{ | ||
Create: resourceVolcengineIamUserGroupPolicyAttachmentCreate, | ||
Read: resourceVolcengineIamUserGroupPolicyAttachmentRead, | ||
Delete: resourceVolcengineIamUserGroupPolicyAttachmentDelete, | ||
Importer: &schema.ResourceImporter{ | ||
State: func(data *schema.ResourceData, i interface{}) ([]*schema.ResourceData, error) { | ||
items := strings.Split(data.Id(), ":") | ||
if len(items) != 2 { | ||
return []*schema.ResourceData{data}, fmt.Errorf("import id must split with ':'") | ||
} | ||
if err := data.Set("user_group_name", items[0]); err != nil { | ||
return []*schema.ResourceData{data}, err | ||
} | ||
if err := data.Set("policy_name", items[1]); err != nil { | ||
return []*schema.ResourceData{data}, err | ||
} | ||
return []*schema.ResourceData{data}, nil | ||
}, | ||
}, | ||
Timeouts: &schema.ResourceTimeout{ | ||
Create: schema.DefaultTimeout(30 * time.Minute), | ||
Delete: schema.DefaultTimeout(30 * time.Minute), | ||
}, | ||
Schema: map[string]*schema.Schema{ | ||
"user_group_name": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
ForceNew: true, | ||
Description: "The user group name.", | ||
}, | ||
"policy_name": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
ForceNew: true, | ||
Description: "The policy name.", | ||
}, | ||
"policy_type": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
ForceNew: true, | ||
Description: "Strategy types, System strategy, Custom strategy.", | ||
}, | ||
}, | ||
} | ||
return resource | ||
} | ||
|
||
func resourceVolcengineIamUserGroupPolicyAttachmentCreate(d *schema.ResourceData, meta interface{}) (err error) { | ||
service := NewIamUserGroupPolicyAttachmentService(meta.(*ve.SdkClient)) | ||
err = service.Dispatcher.Create(service, d, ResourceVolcengineIamUserGroupPolicyAttachment()) | ||
if err != nil { | ||
return fmt.Errorf("error on creating iam_user_group_policy_attachment %q, %s", d.Id(), err) | ||
} | ||
return resourceVolcengineIamUserGroupPolicyAttachmentRead(d, meta) | ||
} | ||
|
||
func resourceVolcengineIamUserGroupPolicyAttachmentRead(d *schema.ResourceData, meta interface{}) (err error) { | ||
service := NewIamUserGroupPolicyAttachmentService(meta.(*ve.SdkClient)) | ||
err = service.Dispatcher.Read(service, d, ResourceVolcengineIamUserGroupPolicyAttachment()) | ||
if err != nil { | ||
return fmt.Errorf("error on reading iam_user_group_policy_attachment %q, %s", d.Id(), err) | ||
} | ||
return err | ||
} | ||
|
||
func resourceVolcengineIamUserGroupPolicyAttachmentDelete(d *schema.ResourceData, meta interface{}) (err error) { | ||
service := NewIamUserGroupPolicyAttachmentService(meta.(*ve.SdkClient)) | ||
err = service.Dispatcher.Delete(service, d, ResourceVolcengineIamUserGroupPolicyAttachment()) | ||
if err != nil { | ||
return fmt.Errorf("error on deleting iam_user_group_policy_attachment %q, %s", d.Id(), err) | ||
} | ||
return err | ||
} |
65 changes: 65 additions & 0 deletions
65
...user_group_policy_attachment/resource_volcengine_iam_user_group_policy_attachment_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,65 @@ | ||
package iam_user_group_policy_attachment_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/helper/resource" | ||
ve "github.com/volcengine/terraform-provider-volcengine/common" | ||
"github.com/volcengine/terraform-provider-volcengine/volcengine" | ||
"github.com/volcengine/terraform-provider-volcengine/volcengine/iam/iam_user_group_policy_attachment" | ||
) | ||
|
||
const testAccVolcengineIamUserGroupPolicyAttachmentCreateConfig = ` | ||
resource "volcengine_iam_policy" "foo" { | ||
policy_name = "acc-test-policy" | ||
description = "acc-test" | ||
policy_document = "{\"Statement\":[{\"Effect\":\"Allow\",\"Action\":[\"auto_scaling:DescribeScalingGroups\"],\"Resource\":[\"*\"]}]}" | ||
} | ||
resource "volcengine_iam_user_group" "foo" { | ||
user_group_name = "acc-test-group" | ||
description = "acc-test" | ||
display_name = "acc-test" | ||
} | ||
resource "volcengine_iam_user_group_policy_attachment" "foo" { | ||
policy_name = volcengine_iam_policy.foo.policy_name | ||
policy_type = "Custom" | ||
user_group_name = volcengine_iam_user_group.foo.user_group_name | ||
} | ||
` | ||
|
||
func TestAccVolcengineIamUserGroupPolicyAttachmentResource_Basic(t *testing.T) { | ||
resourceName := "volcengine_iam_user_group_policy_attachment.foo" | ||
|
||
acc := &volcengine.AccTestResource{ | ||
ResourceId: resourceName, | ||
SvcInitFunc: func(client *ve.SdkClient) ve.ResourceService { | ||
return iam_user_group_policy_attachment.NewIamUserGroupPolicyAttachmentService(client) | ||
}, | ||
} | ||
|
||
resource.ParallelTest(t, resource.TestCase{ | ||
PreCheck: func() { | ||
volcengine.AccTestPreCheck(t) | ||
}, | ||
Providers: volcengine.GetTestAccProviders(), | ||
CheckDestroy: volcengine.AccTestCheckResourceRemove(acc), | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccVolcengineIamUserGroupPolicyAttachmentCreateConfig, | ||
Check: resource.ComposeTestCheckFunc( | ||
volcengine.AccTestCheckResourceExists(acc), | ||
resource.TestCheckResourceAttr(acc.ResourceId, "policy_name", "acc-test-policy"), | ||
resource.TestCheckResourceAttr(acc.ResourceId, "policy_type", "Custom"), | ||
resource.TestCheckResourceAttr(acc.ResourceId, "user_group_name", "acc-test-group"), | ||
), | ||
}, | ||
{ | ||
ResourceName: resourceName, | ||
ImportState: true, | ||
ImportStateVerify: true, | ||
}, | ||
}, | ||
}) | ||
} |
Oops, something went wrong.