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 #186 from kingsoftcloud/trunk
Trunk
- Loading branch information
Showing
10 changed files
with
654 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
/* | ||
Provides a Tagv2 resource. | ||
# Example Usage | ||
```hcl | ||
resource "ksyun_tag_v2" "tag" { | ||
key = "test_tag_key" | ||
value = "test_tag_value" | ||
} | ||
``` | ||
# Import | ||
Tagv2 can be imported using the `key&value`, e.g. | ||
``` | ||
$ terraform import ksyun_tag_v2.tag ${tagv2_key}:${tagv2_value} | ||
``` | ||
*/ | ||
|
||
package ksyun | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/helper/schema" | ||
) | ||
|
||
func resourceKsyunTagv2() *schema.Resource { | ||
return &schema.Resource{ | ||
Create: resourceKsyunTagv2Create, | ||
Read: resourceKsyunTagv2Read, | ||
Update: resourceKsyunTagv2Update, | ||
Delete: resourceKsyunTagv2Delete, | ||
Importer: &schema.ResourceImporter{ | ||
State: importTagResource, | ||
}, | ||
CustomizeDiff: resourceKsyunTagv2Diff(), | ||
Schema: map[string]*schema.Schema{ | ||
"key": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
Description: "Tag key.", | ||
}, | ||
"value": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
Description: "Tag value.", | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func resourceKsyunTagv2Diff() schema.CustomizeDiffFunc { | ||
return func(diff *schema.ResourceDiff, i interface{}) (err error) { | ||
keys := []string{"key", "value", "resource_type", "resource_id"} | ||
|
||
for _, k := range keys { | ||
if diff.HasChange(k) { | ||
err = diff.ForceNew(k) | ||
if err != nil { | ||
return | ||
} | ||
} | ||
} | ||
|
||
return | ||
} | ||
} | ||
|
||
func resourceKsyunTagv2Create(d *schema.ResourceData, meta interface{}) (err error) { | ||
tagService := TagService{meta.(*KsyunClient)} | ||
err = tagService.CreateTag(d, resourceKsyunTagv2()) | ||
if err != nil { | ||
return fmt.Errorf("error on creating Tagv2 %q, %s", d.Id(), err) | ||
} | ||
return resourceKsyunTagv2Read(d, meta) | ||
} | ||
|
||
func resourceKsyunTagv2Update(d *schema.ResourceData, meta interface{}) (err error) { | ||
return | ||
} | ||
|
||
func resourceKsyunTagv2Read(d *schema.ResourceData, meta interface{}) (err error) { | ||
tagService := TagService{meta.(*KsyunClient)} | ||
err = tagService.ReadAndSetTag(d, resourceKsyunTagv2()) | ||
if err != nil { | ||
return fmt.Errorf("error on reading Tagv2, %s", err) | ||
} | ||
return | ||
} | ||
|
||
func resourceKsyunTagv2Delete(d *schema.ResourceData, meta interface{}) (err error) { | ||
tagService := TagService{meta.(*KsyunClient)} | ||
err = tagService.DeleteTag(d) | ||
if err != nil { | ||
return fmt.Errorf("error on deleting Tagv2 %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,129 @@ | ||
/* | ||
Provides an attachment for pinning tag upon resource. | ||
> Note: supported all of resource_type | ||
> The tag will be created if it is not existed. | ||
# Example Usage | ||
```hcl | ||
resource "ksyun_tag_v2" "tagv2" { | ||
key = "test_tag_key" | ||
value = "test_tag_value" | ||
} | ||
resource "ksyun_tag_v2_attachment" "tag" { | ||
key = "test_tag_key" | ||
value = "test_tag_value" | ||
resource_type = "redis-instance" | ||
resource_id = "1f4e8c22-xxxx-xxxx-xxxx-cc6345011af4" | ||
} | ||
``` | ||
# Import | ||
Tagv2Attachment can be imported using the `id`, e.g. | ||
``` | ||
$ terraform import ksyun_tag_v2_attachment.tag ${tag_key}:${tag_value},${resource_type}:${resource_id} | ||
``` | ||
*/ | ||
|
||
package ksyun | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/helper/schema" | ||
) | ||
|
||
func resourceKsyunTagv2Attachment() *schema.Resource { | ||
return &schema.Resource{ | ||
Create: resourceKsyunTagv2AttachmentCreate, | ||
Read: resourceKsyunTagv2AttachmentRead, | ||
Update: resourceKsyunTagv2AttachmentUpdate, | ||
Delete: resourceKsyunTagv2AttachmentDelete, | ||
Importer: &schema.ResourceImporter{ | ||
State: importTagV1Resource, | ||
}, | ||
CustomizeDiff: resourceKsyunTagv2AttachmentDiff(), | ||
Schema: map[string]*schema.Schema{ | ||
"key": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
Description: "Tag key.", | ||
}, | ||
"value": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
Description: "Tag value.", | ||
}, | ||
"resource_type": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
Description: "Resource type. [supported type](https://docs.ksyun.com/documents/39807).", | ||
}, | ||
"resource_id": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
Description: "Resource ID.", | ||
}, | ||
|
||
"tag_id": { | ||
Type: schema.TypeFloat, | ||
Computed: true, | ||
Description: "Tag id.", | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func resourceKsyunTagv2AttachmentDiff() schema.CustomizeDiffFunc { | ||
return func(diff *schema.ResourceDiff, i interface{}) (err error) { | ||
keys := []string{"key", "value", "resource_type", "resource_id"} | ||
|
||
for _, k := range keys { | ||
if diff.HasChange(k) { | ||
err = diff.ForceNew(k) | ||
if err != nil { | ||
return | ||
} | ||
} | ||
} | ||
|
||
return | ||
} | ||
} | ||
|
||
func resourceKsyunTagv2AttachmentCreate(d *schema.ResourceData, meta interface{}) (err error) { | ||
tagService := TagService{meta.(*KsyunClient)} | ||
err = tagService.CreateTagResourceAttachment(d, resourceKsyunTagv2Attachment()) | ||
if err != nil { | ||
return fmt.Errorf("error on creating Tagv2Attachment %q, %s", d.Id(), err) | ||
} | ||
return resourceKsyunTagv2AttachmentRead(d, meta) | ||
} | ||
|
||
func resourceKsyunTagv2AttachmentUpdate(d *schema.ResourceData, meta interface{}) (err error) { | ||
return | ||
} | ||
|
||
func resourceKsyunTagv2AttachmentRead(d *schema.ResourceData, meta interface{}) (err error) { | ||
tagService := TagService{meta.(*KsyunClient)} | ||
err = tagService.ReadAndSetTagAttachment(d, resourceKsyunTagv2Attachment()) | ||
if err != nil { | ||
return fmt.Errorf("error on reading Tagv2Attachment, %s", err) | ||
} | ||
return | ||
} | ||
|
||
func resourceKsyunTagv2AttachmentDelete(d *schema.ResourceData, meta interface{}) (err error) { | ||
tagService := TagService{meta.(*KsyunClient)} | ||
err = tagService.DetachResourceTags(d) | ||
if err != nil { | ||
return fmt.Errorf("error on deleting Tagv2Attachment %q, %s", d.Id(), err) | ||
} | ||
return | ||
} |
Oops, something went wrong.