Skip to content

Commit

Permalink
fix data type of version in datasource ucloud_iam_policy_document (#159)
Browse files Browse the repository at this point in the history
* fix version type in IAMPolicyDocument datasource
  • Loading branch information
wangrzneu authored Nov 22, 2023
1 parent bbc4fa7 commit 5725c9f
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 13 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## 1.38.3 (2023-11-22)

BUG FIXES:

* `datasource/ucloud_iam_policy_document`: fix data type of version.

## 1.38.2 (2023-09-27)

FEATURES:
Expand Down
2 changes: 1 addition & 1 deletion examples/rssd/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ terraform {
required_providers {
ucloud = {
source = "ucloud/ucloud"
version = "~>1.38.2"
version = "~>1.38.3"
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion ucloud/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func (c *Config) Client() (*UCloudClient, error) {
// enable auto retry with http/connection error
cfg.MaxRetries = c.MaxRetries
cfg.LogLevel = log.PanicLevel
cfg.UserAgent = "Terraform-UCloud/1.38.2"
cfg.UserAgent = "Terraform-UCloud/1.38.3"
cfg.BaseUrl = c.BaseURL

cred := auth.NewCredential()
Expand Down
12 changes: 6 additions & 6 deletions ucloud/data_source_ucloud_iam_policy_document.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ func dataSourceUCloudIAMPolicyDocument() *schema.Resource {
Read: dataSourceUCloudIAMPolicyDocumentRead,
Schema: map[string]*schema.Schema{
"version": {
Type: schema.TypeInt,
Type: schema.TypeString,
Optional: true,
Default: 1,
ValidateFunc: validation.IntInSlice([]int{1}),
Default: "1",
ValidateFunc: validation.StringInSlice([]string{"1"}, false),
},
"statement": {
Type: schema.TypeList,
Expand Down Expand Up @@ -58,7 +58,7 @@ func dataSourceUCloudIAMPolicyDocument() *schema.Resource {
}
func dataSourceUCloudIAMPolicyDocumentRead(d *schema.ResourceData, meta interface{}) error {
if v, ok := d.GetOk("statement"); ok {
doc, err := assembleDataSourcePolicyJSON(v.([]interface{}), d.Get("version").(int))
doc, err := assembleDataSourcePolicyJSON(v.([]interface{}), d.Get("version").(string))
if err != nil {
return err
}
Expand All @@ -75,7 +75,7 @@ func dataSourceUCloudIAMPolicyDocumentRead(d *schema.ResourceData, meta interfac
return nil
}

func assembleDataSourcePolicyJSON(statements []interface{}, version int) (string, error) {
func assembleDataSourcePolicyJSON(statements []interface{}, version string) (string, error) {
document := PolicyDocument{Version: version}
for _, v := range statements {
var statement PolicyStatement
Expand All @@ -102,6 +102,6 @@ type PolicyStatement struct {
Resource []string `json:"Resource"`
}
type PolicyDocument struct {
Version int `json:"Version"`
Version string `json:"Version"`
Statement []PolicyStatement `json:"Statement"`
}
4 changes: 2 additions & 2 deletions ucloud/data_source_ucloud_iam_policy_document_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func TestAccUCloudIAMPolicyDocument_basic(t *testing.T) {

const testAccDataIAMPolicyDocumentConfig = `
data "ucloud_iam_policy_document" foo {
version = 1
version = "1"
statement {
effect = "Allow"
Expand All @@ -46,7 +46,7 @@ data "ucloud_iam_policy_document" foo {
]
resource = [
"ucs:uhost:*:<company-id>:instance/uhost-xxx",
"ucs:uhost:*:123:instance/uhost-xxx",
]
}
statement {
Expand Down
2 changes: 1 addition & 1 deletion website/docs/d/iam_policy_document.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Generates an IAM policy document in JSON format for use with resources that expe

```hcl
data "ucloud_iam_policy_document" foo {
version = 1
version = "1"
statement {
effect = "Allow"
Expand Down
4 changes: 2 additions & 2 deletions website/docs/index.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ terraform {
required_providers {
ucloud = {
source = "ucloud/ucloud"
version = "~>1.38.2"
version = "~>1.38.3"
}
}
}
Expand Down Expand Up @@ -91,7 +91,7 @@ terraform {
required_providers {
ucloud = {
source = "ucloud/ucloud"
version = "~>1.38.2"
version = "~>1.38.3"
}
}
}
Expand Down

0 comments on commit 5725c9f

Please sign in to comment.