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 iam role for cloud services and agencies #1302

Merged
merged 2 commits into from
Jul 23, 2021
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
4 changes: 2 additions & 2 deletions docs/resources/identity_role.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
subcategory: "Identity and Access Management (IAM)"
---

# huaweicloud\_identity\_role
# huaweicloud_identity_role

Manages a **Custom Policy** resource within HuaweiCloud IAM service.

Note: You _must_ have admin privileges in your HuaweiCloud cloud to use
->**Note** You _must_ have admin privileges in your HuaweiCloud cloud to use
this resource.

## Example Usage
Expand Down
2 changes: 1 addition & 1 deletion huaweicloud/resource_huaweicloud_identity_role.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ func resourceIdentityRoleUpdate(d *schema.ResourceData, meta interface{}) error
Policy: policy,
}

logp.Printf("[DEBUG] Create Options: %#v", createOpts)
logp.Printf("[DEBUG] Update Options: %#v", createOpts)

_, err = policies.Update(identityClient, d.Id(), createOpts).Extract()
if err != nil {
Expand Down
60 changes: 60 additions & 0 deletions huaweicloud/resource_huaweicloud_identity_role_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,37 @@ func TestAccIdentityRole_basic(t *testing.T) {
})
}

func TestAccIdentityRole_agency(t *testing.T) {
var role policies.Role
var roleName = fmt.Sprintf("tf-acc-test-%s", acctest.RandString(5))
resourceName := "huaweicloud_identity_role.agency"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() {
testAccPreCheck(t)
testAccPreCheckAdminOnly(t)
},
Providers: testAccProviders,
CheckDestroy: testAccCheckIdentityRoleDestroy,
Steps: []resource.TestStep{
{
Config: testAccIdentityRole_agency(roleName),
Check: resource.ComposeTestCheckFunc(
testAccCheckIdentityRoleExists(resourceName, &role),
resource.TestCheckResourceAttrPtr(resourceName, "name", &role.Name),
resource.TestCheckResourceAttrPtr(resourceName, "description", &role.Description),
resource.TestCheckResourceAttr(resourceName, "type", "AX"),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
},
},
})
}

func testAccCheckIdentityRoleDestroy(s *terraform.State) error {
config := testAccProvider.Meta().(*config.Config)
identityClient, err := config.IAMV3Client(HW_REGION_NAME)
Expand Down Expand Up @@ -166,3 +197,32 @@ EOF
}
`, roleName, HW_REGION_NAME)
}

func testAccIdentityRole_agency(roleName string) string {
return fmt.Sprintf(`
resource "huaweicloud_identity_role" agency {
name = "%s"
description = "created by terraform"
type = "AX"
policy = <<EOF
{
"Version": "1.1",
"Statement": [
{
"Effect": "Allow",
"Action": [
"iam:agencies:assume"
],
"Resource": {
"uri": [
"/iam/agencies/07805aca-ba80-0fdd-4fbd-c00b8f888c7c",
"/iam/agencies/16d4d672-8665-496e-a0b5-71a8ad7f2fe8"
]
}
}
]
}
EOF
}
`, roleName)
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.