forked from KscSDK/terraform-provider-kingsoftcloud
-
Notifications
You must be signed in to change notification settings - Fork 15
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 #239 from fengyikai/feature/iam/trunk
Feature/iam/trunk
- Loading branch information
Showing
20 changed files
with
701 additions
and
24 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
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
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,94 @@ | ||
/* | ||
Provides a Iam Policy resource. | ||
# Example Usage | ||
```hcl | ||
resource "ksyun_iam_relation_policy" "user" { | ||
name = "iam_user_name" | ||
policy_name = "IAMReadOnlyAccess" | ||
relation_type = 1 | ||
}` | ||
resource "ksyun_iam_relation_policy" "user" { | ||
name = "iam_role_name" | ||
policy_name = "IAMReadOnlyAccess" | ||
relation_type = 2 | ||
}` | ||
``` | ||
# Import | ||
IAM Policy can be imported using the `policy_name`, e.g. | ||
``` | ||
$ terraform import ksyun_iam_relation_policy.user | ||
``` | ||
*/ | ||
|
||
package ksyun | ||
|
||
import ( | ||
"fmt" | ||
"github.com/hashicorp/terraform-plugin-sdk/helper/schema" | ||
) | ||
|
||
func resourceKsyunIamRelationPolicy() *schema.Resource { | ||
return &schema.Resource{ | ||
Create: resourceKsyunIamRelationPolicyCreate, | ||
Read: resourceKsyunIamRelationPolicyRead, | ||
Delete: resourceKsyunIamRelationPolicyDelete, | ||
Schema: map[string]*schema.Schema{ | ||
"name": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
ForceNew: true, | ||
Description: "IAM UserName or RoleName according to relation type.", | ||
}, | ||
"policy_name": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
ForceNew: true, | ||
Description: "IAM PolicyName.", | ||
}, | ||
"relation_type": { | ||
Type: schema.TypeInt, | ||
Required: true, | ||
ForceNew: true, | ||
Description: "relation type 1 is the user,relation type 2 is the role.", | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func resourceKsyunIamRelationPolicyCreate(d *schema.ResourceData, meta interface{}) (err error) { | ||
iamRelationPolicyService := IamRelationPolicyService{meta.(*KsyunClient)} | ||
err = iamRelationPolicyService.CreateIamRelationPolicy(d, resourceKsyunIamRelationPolicy()) | ||
if err != nil { | ||
return fmt.Errorf("error on creating IAM reliaton policy %q, %s", d.Id(), err) | ||
} | ||
return | ||
} | ||
|
||
func resourceKsyunIamRelationPolicyUpdate(d *schema.ResourceData, meta interface{}) (err error) { | ||
return | ||
} | ||
|
||
func resourceKsyunIamRelationPolicyRead(d *schema.ResourceData, meta interface{}) (err error) { | ||
iamRelationPolicyService := IamRelationPolicyService{meta.(*KsyunClient)} | ||
err = iamRelationPolicyService.ReadAndSetIamRelationPolicy(d, resourceKsyunIamRelationPolicy()) | ||
if err != nil { | ||
return fmt.Errorf("error on reading IAM reliaton policy, %s", err) | ||
} | ||
return | ||
} | ||
|
||
func resourceKsyunIamRelationPolicyDelete(d *schema.ResourceData, meta interface{}) (err error) { | ||
iamRelationPolicyService := IamRelationPolicyService{meta.(*KsyunClient)} | ||
err = iamRelationPolicyService.DeleteIamRelationPolicy(d) | ||
if err != nil { | ||
return fmt.Errorf("error on deleting IAM reliaton policy %q, %s", d.Id(), err) | ||
} | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package ksyun | ||
|
||
import ( | ||
"github.com/hashicorp/terraform-plugin-sdk/helper/resource" | ||
"testing" | ||
) | ||
|
||
func TestAccKsyunIamRelationPolicy_basic(t *testing.T) { | ||
resource.ParallelTest(t, resource.TestCase{ | ||
PreCheck: func() { | ||
testAccPreCheck(t) | ||
}, | ||
Providers: testAccProviders, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccKsyunIamRelationPolicyConfig, | ||
Check: resource.ComposeTestCheckFunc( | ||
testAccCheckIDExists("ksyun_iam_relation_policy.user"), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
const testAccKsyunIamRelationPolicyConfig = ` | ||
resource "ksyun_iam_relation_policy" "user" { | ||
name = "username01" | ||
policy_name = "IAMReadOnlyAccess" | ||
relation_type = 1 | ||
}` |
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
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
Oops, something went wrong.