-
Notifications
You must be signed in to change notification settings - Fork 162
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add cts tracker resource service * add cts tracker resource docs
- Loading branch information
1 parent
1aa5ac2
commit e41827c
Showing
17 changed files
with
1,126 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
resource "huaweicloud_s3_bucket" "bucket" { | ||
bucket = "tf-test-bucket" | ||
acl = "public-read" | ||
} | ||
resource "huaweicloud_smn_topic_v2" "topic_1" { | ||
name = "topic_check" | ||
display_name = "The display name of topic_1" | ||
} | ||
|
||
resource "huaweicloud_cts_tracker_v1" "tracker_v1" { | ||
bucket_name = "${huaweicloud_s3_bucket.bucket.bucket}" | ||
file_prefix_name = "yO8Q" | ||
is_support_smn = true | ||
topic_id = "${huaweicloud_smn_topic_v2.topic_1.id}" | ||
is_send_all_key_operation = false | ||
operations = ["delete","create","login"] | ||
need_notify_user_list = ["user1"] | ||
} |
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,116 @@ | ||
package huaweicloud | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
|
||
"github.com/hashicorp/terraform/helper/schema" | ||
"github.com/huaweicloud/golangsdk/openstack/cts/v1/tracker" | ||
) | ||
|
||
func dataSourceCTSTrackerV1() *schema.Resource { | ||
return &schema.Resource{ | ||
Read: dataSourceCTSTrackerV1Read, | ||
|
||
Schema: map[string]*schema.Schema{ | ||
"region": &schema.Schema{ | ||
Type: schema.TypeString, | ||
Optional: true, | ||
Computed: true, | ||
ForceNew: true, | ||
}, | ||
"status": &schema.Schema{ | ||
Type: schema.TypeString, | ||
Optional: true, | ||
Computed: true, | ||
}, | ||
"bucket_name": &schema.Schema{ | ||
Type: schema.TypeString, | ||
Optional: true, | ||
Computed: true, | ||
}, | ||
"file_prefix_name": &schema.Schema{ | ||
Type: schema.TypeString, | ||
Optional: true, | ||
Computed: true, | ||
}, | ||
"tracker_name": &schema.Schema{ | ||
Type: schema.TypeString, | ||
Optional: true, | ||
Computed: true, | ||
}, | ||
"is_support_smn": &schema.Schema{ | ||
Type: schema.TypeBool, | ||
Computed: true, | ||
}, | ||
"topic_id": &schema.Schema{ | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"operations": &schema.Schema{ | ||
Type: schema.TypeSet, | ||
Computed: true, | ||
Elem: &schema.Schema{Type: schema.TypeString}, | ||
Set: schema.HashString, | ||
}, | ||
"is_send_all_key_operation": &schema.Schema{ | ||
Type: schema.TypeBool, | ||
Computed: true, | ||
}, | ||
"need_notify_user_list": &schema.Schema{ | ||
Type: schema.TypeSet, | ||
Computed: true, | ||
Elem: &schema.Schema{Type: schema.TypeString}, | ||
Set: schema.HashString, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func dataSourceCTSTrackerV1Read(d *schema.ResourceData, meta interface{}) error { | ||
config := meta.(*Config) | ||
trackerClient, err := config.ctsV1Client(GetRegion(d, config)) | ||
|
||
listOpts := tracker.ListOpts{ | ||
TrackerName: d.Get("tracker_name").(string), | ||
BucketName: d.Get("bucket_name").(string), | ||
FilePrefixName: d.Get("file_prefix_name").(string), | ||
Status: d.Get("status").(string), | ||
} | ||
|
||
refinedTrackers, err := tracker.List(trackerClient, listOpts) | ||
|
||
if err != nil { | ||
return fmt.Errorf("Unable to retrieve cts tracker: %s", err) | ||
} | ||
|
||
if len(refinedTrackers) < 1 { | ||
return fmt.Errorf("Your query returned no results. " + | ||
"Please change your search criteria and try again.") | ||
} | ||
|
||
if len(refinedTrackers) > 1 { | ||
return fmt.Errorf("Your query returned more than one result." + | ||
" Please try a more specific search criteria") | ||
} | ||
|
||
trackers := refinedTrackers[0] | ||
|
||
log.Printf("[INFO] Retrieved cts tracker %s using given filter", trackers.TrackerName) | ||
|
||
d.SetId(trackers.TrackerName) | ||
|
||
d.Set("tracker_name", trackers.TrackerName) | ||
d.Set("bucket_name", trackers.BucketName) | ||
d.Set("file_prefix_name", trackers.FilePrefixName) | ||
d.Set("status", trackers.Status) | ||
d.Set("is_support_smn", trackers.SimpleMessageNotification.IsSupportSMN) | ||
d.Set("topic_id", trackers.SimpleMessageNotification.TopicID) | ||
d.Set("is_send_all_key_operation", trackers.SimpleMessageNotification.IsSendAllKeyOperation) | ||
d.Set("operations", trackers.SimpleMessageNotification.Operations) | ||
d.Set("need_notify_user_list", trackers.SimpleMessageNotification.NeedNotifyUserList) | ||
|
||
d.Set("region", GetRegion(d, config)) | ||
|
||
return nil | ||
} |
67 changes: 67 additions & 0 deletions
67
huaweicloud/data_source_huaweicloud_cts_tracker_v1_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,67 @@ | ||
package huaweicloud | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform/helper/resource" | ||
"github.com/hashicorp/terraform/terraform" | ||
) | ||
|
||
func TestAccCTSTrackerV1DataSource_basic(t *testing.T) { | ||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
Providers: testAccProviders, | ||
Steps: []resource.TestStep{ | ||
resource.TestStep{ | ||
Config: testAccCTSTrackerV1DataSource_basic, | ||
Check: resource.ComposeTestCheckFunc( | ||
testAccCheckCTSTrackerV1DataSourceID("data.huaweicloud_cts_tracker_v1.tracker_v1"), | ||
resource.TestCheckResourceAttr("data.huaweicloud_cts_tracker_v1.tracker_v1", "bucket_name", "tf-test-bucket"), | ||
resource.TestCheckResourceAttr("data.huaweicloud_cts_tracker_v1.tracker_v1", "status", "enabled"), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testAccCheckCTSTrackerV1DataSourceID(n string) resource.TestCheckFunc { | ||
return func(s *terraform.State) error { | ||
rs, ok := s.RootModule().Resources[n] | ||
if !ok { | ||
return fmt.Errorf("Can't find cts tracker data source: %s ", n) | ||
} | ||
|
||
if rs.Primary.ID == "" { | ||
return fmt.Errorf("tracker data source not set ") | ||
} | ||
|
||
return nil | ||
} | ||
} | ||
|
||
const testAccCTSTrackerV1DataSource_basic = ` | ||
resource "huaweicloud_s3_bucket" "bucket" { | ||
bucket = "tf-test-bucket" | ||
acl = "public-read" | ||
force_destroy = true | ||
} | ||
resource "huaweicloud_smn_topic_v2" "topic_1" { | ||
name = "tf-test-topic" | ||
display_name = "The display name of tf-test-topic" | ||
} | ||
resource "huaweicloud_cts_tracker_v1" "tracker_v1" { | ||
bucket_name = "${huaweicloud_s3_bucket.bucket.bucket}" | ||
file_prefix_name = "yO8Q" | ||
is_support_smn = true | ||
topic_id = "${huaweicloud_smn_topic_v2.topic_1.id}" | ||
is_send_all_key_operation = false | ||
operations = ["login"] | ||
need_notify_user_list = ["user1"] | ||
} | ||
data "huaweicloud_cts_tracker_v1" "tracker_v1" { | ||
tracker_name = "${huaweicloud_cts_tracker_v1.tracker_v1.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,28 @@ | ||
package huaweicloud | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform/helper/resource" | ||
) | ||
|
||
func TestAccCTSTrackerV1_importBasic(t *testing.T) { | ||
resourceName := "huaweicloud_cts_tracker_v1.tracker_v1" | ||
|
||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
Providers: testAccProviders, | ||
CheckDestroy: testAccCheckCTSTrackerV1Destroy, | ||
Steps: []resource.TestStep{ | ||
resource.TestStep{ | ||
Config: testAccCTSTrackerV1_basic, | ||
}, | ||
|
||
resource.TestStep{ | ||
ResourceName: resourceName, | ||
ImportState: true, | ||
ImportStateVerify: true, | ||
}, | ||
}, | ||
}) | ||
} |
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.