From ba3b617240dc49cf3e263c06c88b111f74c8f504 Mon Sep 17 00:00:00 2001 From: daegon-lee Date: Thu, 10 Nov 2022 17:46:48 +0900 Subject: [PATCH 1/5] update: sourcepipeline(trigger) resources and data --- docs/data-sources/sourcepipeline_project.md | 15 +- .../sourcepipeline_trigger_timezone.md | 22 ++ docs/resources/sourcepipeline_project.md | 44 ++- examples/sourcepipeline/main.tf | 19 +- ...ta_source_ncloud_sourcepipeline_project.go | 51 +++- ...urce_ncloud_sourcepipeline_project_test.go | 10 +- ..._ncloud_sourcepipeline_trigger_timezone.go | 79 +++++ ...ud_sourcepipeline_trigger_timezone_test.go | 44 +++ .../resource_ncloud_sourcepipeline_project.go | 287 ++++++++++++++---- ...urce_ncloud_sourcepipeline_project_test.go | 42 +-- 10 files changed, 512 insertions(+), 101 deletions(-) create mode 100644 docs/data-sources/sourcepipeline_trigger_timezone.md create mode 100644 ncloud/data_source_ncloud_sourcepipeline_trigger_timezone.go create mode 100644 ncloud/data_source_ncloud_sourcepipeline_trigger_timezone_test.go diff --git a/docs/data-sources/sourcepipeline_project.md b/docs/data-sources/sourcepipeline_project.md index da23e4006..35b480ac1 100644 --- a/docs/data-sources/sourcepipeline_project.md +++ b/docs/data-sources/sourcepipeline_project.md @@ -51,6 +51,15 @@ The following attributes are exported: * `full_manifest` - List of target manifest files name of the Sourcedeploy task. * `linked_tasks` - List of linked tasks. * `triggers` - * `sourcecommit` - * `repository_name` - Name of the Sourcecommit repository to trigger execution of pipeline. - * `branch` - Name of repository branch to trigger execution of pipeline. + * `repository` - Repository trigger. + * `type` - Type of the repository. + * `name` - Name of the repository. + * `branch` - Name of a repository branch. + * `schedule` - Schedule trigger. + * `day` - List of day of week . + * `time` - Time to trigger. + * `timezone` - Timezone for trigger. + * `schedule_only_with_change` - Schedule trigger option. You can decide whether schedule trigger only execute when SourcePipeline configuration or Repositoryor not. + * `sourcepipeline` - Sourcepipeline trigger. + * `id` - Id of the sourcepipeline project to trigger execution of pipeline. + * `name` - Name of the sourcepipeline project to trigger execution of pipeline. diff --git a/docs/data-sources/sourcepipeline_trigger_timezone.md b/docs/data-sources/sourcepipeline_trigger_timezone.md new file mode 100644 index 000000000..f4005f385 --- /dev/null +++ b/docs/data-sources/sourcepipeline_trigger_timezone.md @@ -0,0 +1,22 @@ +# Data Source: ncloud_sourcepipieline_trigger_timezone + +This data source is useful for look up the list of Sourcepipeline trigger time zone. + +## Example Usage + +In the example below, Retrieves all Sourcepipeline schedule trigger time zone list. + +```hcl +data "ncloud_sourcepipeline_trigger_timezone" "list_timezone" { +} + +output "lookup-timezone-output" { + value = data.ncloud_sourcepipeline_trigger_timezone.list_timezone.timezone +} +``` + +## Attributes Reference + +The following attributes are exported: + +* `timezone` - The list of Timezone for schedule trigger. diff --git a/docs/resources/sourcepipeline_project.md b/docs/resources/sourcepipeline_project.md index 814e5b9a8..edf6b9c0f 100644 --- a/docs/resources/sourcepipeline_project.md +++ b/docs/resources/sourcepipeline_project.md @@ -37,10 +37,20 @@ resource "ncloud_sourcepipeline_project" "test-sourcepipeline" { linked_tasks = ["task_name_1"] } triggers { - sourcecommit { + repository { + type = "sourcecommit" repository_name = ncloud_sourcecommit_repository.test-sourcecommit.name branch = "master" } + schedule { + day = ["MON", "TUE"] + time = "13:01" + timezone = "Asia/Seoul (UTC+09:00)" + schedule_only_with_change = false + } + sourcepipeline { + id = 1234 + } } } ``` @@ -67,6 +77,9 @@ data "ncloud_sourcedeploy_project_stage_scenarios" "test-sourcedeploy_scenarios" stage_id = data.ncloud_sourcedeploy_project_stages.test-sourcedeploy_stages.stages[0].id } +data "ncloud_sourcepipeline_projects" "test-sourcepipeline" { +} + resource "ncloud_sourcepipeline_project" "test-sourcepipeline" { name = "tf-sourcepipeline_project-test" task { @@ -91,10 +104,20 @@ resource "ncloud_sourcepipeline_project" "test-sourcepipeline" { linked_tasks = ["task_name_1"] } triggers { - sourcecommit { + repository { + type = "sourcecommit" repository_name = ncloud_sourcecommit_repository.test-sourcecommit.name branch = "master" } + schedule { + day = ["MON", "TUE"] + time = "13:01" + timezone = "Asia/Seoul (UTC+09:00)" + schedule_only_with_change = false + } + sourcepipeline { + id = data.ncloud_sourcebuild_projects.test-sourcepipeline.projects[0].id + } } } ``` @@ -116,9 +139,17 @@ The following arguments are supported: * `repository_branch` - (Optional) Target repository branch of SourceBuild task. Default : main branch of target repository * `linked_tasks` - (Required) Linked tasks which has to be executed before. * `triggers` - (Required) `triggers` block describes trigger configuration. - * `sourcecommit` - (Optional) - * `repository_name` - (Required) Name of sourcecommit repository to trigger execution of pipeline - * `branch` - (Required) Name of a repository branch to trigger execution of pipeline. + * `repository` - (Optional) + * `type` - (Optional, Required if `trigger.repository` exists) Type of repository. Accepted values: `sourcecommit` + * `name` - (Optional, Required if `trigger.repository` exists) Name of repository. + * `branch` - (Optional, Required if `trigger.repository` exists) Name of a repository branch. + * `schedule` - (Optional) + * `day` - (Optional, Required if `trigger.schedule` exists) List of day of week. + * `time` - (Optional, Required if `trigger.schedule` exists) Time to trigger. + * `timezone` - (Optional, Required if `trigger.schedule` exists) Timezone for trigger. Accepted values: `MON` | `TUE` | `WED` | `THU` | `FRI` | `SAT` | `SUN`. + * `schedule_only_with_change` - (Optional, Required if `trigger.schedule` exists) Schedule trigger option. You can decide whether schedule trigger always execute in time or execute if Sourcepipeline project configuration or Sourcecommit repository has changed. + * `sourcepipeline` - (Optional) + * `id` - (Optional, Required if `trigger.sourcepipeline` exists) Id of the sourcepipeline project. ## Attributes Reference @@ -132,3 +163,6 @@ The following arguments are supported: * `file` - Target file name of the Sourcedeploy task. It is set only when `task.type` is SourceDeploy and `task.config.target.type` is ObjectStorage. * `manifest` - Target manifest file name of the Sourcedeploy task. It is set only when `task.type` is SourceDeploy and `task.config.target.type` is KubernetesService. * `full_manifest` - List of target manifest files name. It is set only when `task.type` is SourceDeploy and `task.config.target.type` is KubernetesService. +* `triggers` + * `sourcepipeline` + * `name` - Name of the sourcepipeline trigger project. diff --git a/examples/sourcepipeline/main.tf b/examples/sourcepipeline/main.tf index eb64d1a16..46be857bf 100644 --- a/examples/sourcepipeline/main.tf +++ b/examples/sourcepipeline/main.tf @@ -23,6 +23,9 @@ data "ncloud_sourcedeploy_project_stage_scenarios" "test-sourcedeploy_scenarios" stage_id = data.ncloud_sourcedeploy_project_stages.test-sourcedeploy_stages.stages[0].id } +data "ncloud_sourcepipeline_projects" "test-sourcepipeline" { +} + resource "ncloud_sourcepipeline_project" "test-sourcepipeline" { name = "tf-sourcepipeline_project-test" task { @@ -47,9 +50,19 @@ resource "ncloud_sourcepipeline_project" "test-sourcepipeline" { linked_tasks = ["task_name_1"] } triggers { - sourcecommit { - repository_name = ncloud_sourcecommit_repository.test-sourcecommit.name - branch = "master" + repository { + type = "sourcecommit" + name = ncloud_sourcecommit_repository.test-sourcecommit.name + branch = "master" + } + schedule { + day = ["MON", "TUE"] + time = "13:01" + timezone = "Asia/Seoul (UTC+09:00)" + schedule_only_with_change = false + } + sourcepipeline { + id = data.ncloud_sourcepipeline_projects.test-sourcepipeline.projects[0].id } } } diff --git a/ncloud/data_source_ncloud_sourcepipeline_project.go b/ncloud/data_source_ncloud_sourcepipeline_project.go index 161614ed3..732bb39fc 100644 --- a/ncloud/data_source_ncloud_sourcepipeline_project.go +++ b/ncloud/data_source_ncloud_sourcepipeline_project.go @@ -112,12 +112,16 @@ func dataSourceNcloudSourcePipelineProject() *schema.Resource { Computed: true, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ - "sourcecommit": { + "repository": { Type: schema.TypeList, Computed: true, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ - "repository_name": { + "type": { + Type: schema.TypeString, + Computed: true, + }, + "name": { Type: schema.TypeString, Computed: true, }, @@ -128,6 +132,49 @@ func dataSourceNcloudSourcePipelineProject() *schema.Resource { }, }, }, + "schedule": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "day": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + }, + "time": { + Type: schema.TypeString, + Computed: true, + }, + "timezone": { + Type: schema.TypeString, + Computed: true, + }, + "schedule_only_with_change": { + Type: schema.TypeBool, + Computed: true, + }, + }, + }, + }, + "sourcepipeline": { + Type: schema.TypeList, + Optional: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "id": { + Type: schema.TypeInt, + Computed: true, + }, + "name": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, }, }, }, diff --git a/ncloud/data_source_ncloud_sourcepipeline_project_test.go b/ncloud/data_source_ncloud_sourcepipeline_project_test.go index eee41549a..3625c1df5 100644 --- a/ncloud/data_source_ncloud_sourcepipeline_project_test.go +++ b/ncloud/data_source_ncloud_sourcepipeline_project_test.go @@ -130,10 +130,12 @@ resource "ncloud_sourcepipeline_project" "test-project" { linked_tasks = [] } triggers { - sourcecommit { - repository_name = ncloud_sourcecommit_repository.test-repo.name - branch = "master" - } + schedule { + day = ["MON", "TUE"] + time = "13:01" + timezone = "Asia/Seoul (UTC+09:00)" + schedule_only_with_change = false + } } } diff --git a/ncloud/data_source_ncloud_sourcepipeline_trigger_timezone.go b/ncloud/data_source_ncloud_sourcepipeline_trigger_timezone.go new file mode 100644 index 000000000..3ed408527 --- /dev/null +++ b/ncloud/data_source_ncloud_sourcepipeline_trigger_timezone.go @@ -0,0 +1,79 @@ +package ncloud + +import ( + "context" + "time" + + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" +) + +func init() { + RegisterDataSource("ncloud_sourcepipeline_trigger_timezone", dataSourceNcloudSourcePipelineTimeZone()) +} + +func dataSourceNcloudSourcePipelineTimeZone() *schema.Resource { + return &schema.Resource{ + ReadContext: dataSourceNcloudSourcePipelineTimeZoneRead, + Schema: map[string]*schema.Schema{ + "output_file": { + Type: schema.TypeString, + Optional: true, + }, + "timezone": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + }, + }, + } +} + +func dataSourceNcloudSourcePipelineTimeZoneRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + config := meta.(*ProviderConfig) + + timeZone, err := getSourcePipelineTimeZone(ctx, config) + if err != nil { + logErrorResponse("getSourcePipelineTimeZone", err, timeZone) + return diag.FromErr(err) + } + logResponse("getSourcePipelineTimeZone", timeZone) + + if timeZone == nil { + d.SetId("") + return nil + } + + d.SetId(time.Now().UTC().String()) + d.Set("timezone", timeZone) + + if output, ok := d.GetOk("output_file"); ok && output.(string) != "" { + return diag.FromErr(writeToFile(output.(string), timeZone)) + } + return nil +} + +func getSourcePipelineTimeZone(ctx context.Context, config *ProviderConfig) ([]*string, error) { + if config.SupportVPC { + return getVpcSourcePipelineTimeZone(ctx, config) + } + return getClassicSourcePipelineTimeZone(ctx, config) +} + +func getClassicSourcePipelineTimeZone(ctx context.Context, config *ProviderConfig) ([]*string, error) { + resp, err := config.Client.sourcepipeline.V1Api.GetTimeZone(ctx) + if err != nil { + return nil, err + } + return resp.TimeZone, nil +} + +func getVpcSourcePipelineTimeZone(ctx context.Context, config *ProviderConfig) ([]*string, error) { + resp, err := config.Client.vsourcepipeline.V1Api.GetTimeZone(ctx) + if err != nil { + return nil, err + } + return resp.TimeZone, nil +} diff --git a/ncloud/data_source_ncloud_sourcepipeline_trigger_timezone_test.go b/ncloud/data_source_ncloud_sourcepipeline_trigger_timezone_test.go new file mode 100644 index 000000000..20f1ef168 --- /dev/null +++ b/ncloud/data_source_ncloud_sourcepipeline_trigger_timezone_test.go @@ -0,0 +1,44 @@ +package ncloud + +import ( + "fmt" + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" +) + +func TestAccDataSourceNcloudSourcePipelineTriggerTimeZone_classic_basic(t *testing.T) { + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccClassicProviders, + Steps: []resource.TestStep{ + { + Config: testAccDataSourceNcloudSourcePipelineTriggerTimeZoneConfig(), + Check: resource.ComposeTestCheckFunc( + testAccCheckDataSourceID("data.ncloud_sourcepipeline_trigger_timezone.time_zone"), + ), + }, + }, + }) +} +func TestAccDataSourceNcloudSourcePipelineTriggerTimeZone_vpc_basic(t *testing.T) { + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + Steps: []resource.TestStep{ + { + Config: testAccDataSourceNcloudSourcePipelineTriggerTimeZoneConfig(), + Check: resource.ComposeTestCheckFunc( + testAccCheckDataSourceID("data.ncloud_sourcepipeline_trigger_timezone.time_zone"), + ), + }, + }, + }) +} + +func testAccDataSourceNcloudSourcePipelineTriggerTimeZoneConfig() string { + return fmt.Sprintf(` +data "ncloud_sourcepipeline_trigger_timezone" "time_zone" { +} +`) +} diff --git a/ncloud/resource_ncloud_sourcepipeline_project.go b/ncloud/resource_ncloud_sourcepipeline_project.go index d26a6e395..d0f5c12fd 100644 --- a/ncloud/resource_ncloud_sourcepipeline_project.go +++ b/ncloud/resource_ncloud_sourcepipeline_project.go @@ -145,12 +145,16 @@ func resourceNcloudSourcePipeline() *schema.Resource { MaxItems: 1, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ - "sourcecommit": { + "repository": { Type: schema.TypeList, Optional: true, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ - "repository_name": { + "type": { + Type: schema.TypeString, + Required: true, + }, + "name": { Type: schema.TypeString, Required: true, }, @@ -161,6 +165,49 @@ func resourceNcloudSourcePipeline() *schema.Resource { }, }, }, + "schedule": { + Type: schema.TypeList, + Optional: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "day": { + Type: schema.TypeList, + Required: true, + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + }, + "time": { + Type: schema.TypeString, + Required: true, + }, + "timezone": { + Type: schema.TypeString, + Required: true, + }, + "schedule_only_with_change": { + Type: schema.TypeBool, + Required: true, + }, + }, + }, + }, + "sourcepipeline": { + Type: schema.TypeList, + Optional: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "id": { + Type: schema.TypeInt, + Required: true, + }, + "name": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, }, }, }, @@ -482,47 +529,89 @@ func makeVpcPipelineTaskParams(d *schema.ResourceData) ([]*vsourcepipeline.Creat } func makeClassicPipelineTriggerParams(d *schema.ResourceData) *sourcepipeline.CreateProjectTrigger { - var triggerTargets []*sourcepipeline.GetScTargetInfo - setting := false + var repositoryTrigger []*sourcepipeline.GetRepositoryTrigger + var scheduleTrigger []*sourcepipeline.GetScheduleTrigger + var sourcepipelineTrigger []*sourcepipeline.GetPipelineTrigger + pipelineTrigger := &sourcepipeline.CreateProjectTrigger{} - if _, ok := d.GetOk("triggers.0.sourcecommit"); ok { - setting = true - triggerCount := d.Get("triggers.0.sourcecommit.#").(int) + if _, ok := d.GetOk("triggers.0.repository"); ok { + triggerCount := d.Get("triggers.0.repository.#").(int) for i := 0; i < triggerCount; i++ { - prefix := fmt.Sprintf("triggers.0.sourcecommit.%d.", i) - triggerTargets = append(triggerTargets, &sourcepipeline.GetScTargetInfo{ - Repository: StringPtrOrNil(d.GetOk(prefix + "repository_name")), - Branch: StringPtrOrNil(d.GetOk(prefix + "branch")), + prefix := fmt.Sprintf("triggers.0.repository.%d.", i) + repositoryTrigger = append(repositoryTrigger, &sourcepipeline.GetRepositoryTrigger{ + Type_: StringPtrOrNil(d.GetOk(prefix + "type")), + Name: StringPtrOrNil(d.GetOk(prefix + "name")), + Branch: StringPtrOrNil(d.GetOk(prefix + "branch")), }) } + pipelineTrigger.Repository = repositoryTrigger } - - pipelineTrigger := &sourcepipeline.CreateProjectTrigger{ - Setting: ncloud.Bool(setting), - Sourcecommit: triggerTargets, + if _, ok := d.GetOk("triggers.0.schedule"); ok { + triggerCount := d.Get("triggers.0.schedule.#").(int) + for i := 0; i < triggerCount; i++ { + prefix := fmt.Sprintf("triggers.0.schedule.%d.", i) + scheduleTrigger = append(scheduleTrigger, &sourcepipeline.GetScheduleTrigger{ + Day: StringListPtrOrNil(d.GetOk(prefix + "day")), + Time: StringPtrOrNil(d.GetOk(prefix + "time")), + TimeZone: StringPtrOrNil(d.GetOk(prefix + "timezone")), + ScheduleOnlyWithChange: ncloud.Bool(d.Get(prefix + "schedule_only_with_change").(bool)), + }) + } + pipelineTrigger.Schedule = scheduleTrigger + } + if _, ok := d.GetOk("triggers.0.sourcepipeline"); ok { + triggerCount := d.Get("triggers.0.sourcepipeline.#").(int) + for i := 0; i < triggerCount; i++ { + prefix := fmt.Sprintf("triggers.0.sourcepipeline.%d.", i) + sourcepipelineTrigger = append(sourcepipelineTrigger, &sourcepipeline.GetPipelineTrigger{ + Id: Int32PtrOrNil(d.GetOk(prefix + "id")), + }) + } + pipelineTrigger.SourcePipeline = sourcepipelineTrigger } return pipelineTrigger } func makeVpcPipelineTriggerParams(d *schema.ResourceData) *vsourcepipeline.CreateProjectTrigger { - var triggerTargets []*vsourcepipeline.GetScTargetInfo - setting := false + var repositoryTrigger []*vsourcepipeline.GetRepositoryTrigger + var scheduleTrigger []*vsourcepipeline.GetScheduleTrigger + var sourcepipelineTrigger []*vsourcepipeline.GetPipelineTrigger + pipelineTrigger := &vsourcepipeline.CreateProjectTrigger{} - if _, ok := d.GetOk("triggers.0.sourcecommit"); ok { - setting = true - triggerCount := d.Get("triggers.0.sourcecommit.#").(int) + if _, ok := d.GetOk("triggers.0.repository"); ok { + triggerCount := d.Get("triggers.0.repository.#").(int) for i := 0; i < triggerCount; i++ { - prefix := fmt.Sprintf("triggers.0.sourcecommit.%d.", i) - triggerTargets = append(triggerTargets, &vsourcepipeline.GetScTargetInfo{ - Repository: StringPtrOrNil(d.GetOk(prefix + "repository_name")), - Branch: StringPtrOrNil(d.GetOk(prefix + "branch")), + prefix := fmt.Sprintf("triggers.0.repository.%d.", i) + repositoryTrigger = append(repositoryTrigger, &vsourcepipeline.GetRepositoryTrigger{ + Type_: StringPtrOrNil(d.GetOk(prefix + "type")), + Name: StringPtrOrNil(d.GetOk(prefix + "name")), + Branch: StringPtrOrNil(d.GetOk(prefix + "branch")), }) } + pipelineTrigger.Repository = repositoryTrigger } - - pipelineTrigger := &vsourcepipeline.CreateProjectTrigger{ - Setting: ncloud.Bool(setting), - Sourcecommit: triggerTargets, + if _, ok := d.GetOk("triggers.0.schedule"); ok { + triggerCount := d.Get("triggers.0.schedule.#").(int) + for i := 0; i < triggerCount; i++ { + prefix := fmt.Sprintf("triggers.0.schedule.%d.", i) + scheduleTrigger = append(scheduleTrigger, &vsourcepipeline.GetScheduleTrigger{ + Day: StringListPtrOrNil(d.GetOk(prefix + "day")), + Time: StringPtrOrNil(d.GetOk(prefix + "time")), + TimeZone: StringPtrOrNil(d.GetOk(prefix + "timezone")), + ScheduleOnlyWithChange: ncloud.Bool(d.Get(prefix + "schedule_only_with_change").(bool)), + }) + } + pipelineTrigger.Schedule = scheduleTrigger + } + if _, ok := d.GetOk("triggers.0.sourcepipeline"); ok { + triggerCount := d.Get("triggers.0.sourcepipeline.#").(int) + for i := 0; i < triggerCount; i++ { + prefix := fmt.Sprintf("triggers.0.sourcepipeline.%d.", i) + sourcepipelineTrigger = append(sourcepipelineTrigger, &vsourcepipeline.GetPipelineTrigger{ + Id: Int32PtrOrNil(d.GetOk(prefix + "id")), + }) + } + pipelineTrigger.SourcePipeline = sourcepipelineTrigger } return pipelineTrigger } @@ -691,21 +780,41 @@ func checkVpcDeployTaskConfig(taskConfig *PipelineTaskConfig, deployTarget *vsou func makeTriggerData(triggerData *PipelineTrigger) []map[string]interface{} { if triggerData != nil { - var triggerRepository []map[string]interface{} - for _, repo := range triggerData.Sourcecommit { + var repositoryTrigger []map[string]interface{} + var scheduleTrigger []map[string]interface{} + var sourcepipelineTrigger []map[string]interface{} + + for _, repo := range triggerData.Repository { + mapping := map[string]interface{}{ + "type": ncloud.StringValue(repo.Type_), + "name": ncloud.StringValue(repo.Name), + "branch": ncloud.StringValue(repo.Branch), + } + repositoryTrigger = append(repositoryTrigger, mapping) + } + for _, schedule := range triggerData.Schedule { + mapping := map[string]interface{}{ + "day": ncloud.StringListValue(schedule.Day), + "time": ncloud.StringValue(schedule.Time), + "timezone": ncloud.StringValue(schedule.TimeZone), + "schedule_only_with_change": ncloud.BoolValue(schedule.ScheduleOnlyWithChange), + } + scheduleTrigger = append(scheduleTrigger, mapping) + } + for _, pipeline := range triggerData.SourcePipeline { mapping := map[string]interface{}{ - "repository_name": ncloud.StringValue(repo.RepositoryName), - "branch": ncloud.StringValue(repo.Branch), + "id": ncloud.Int32Value(pipeline.Id), + "name": ncloud.StringValue(pipeline.Name), } - triggerRepository = append(triggerRepository, mapping) + sourcepipelineTrigger = append(sourcepipelineTrigger, mapping) } triggerInfo := map[string]interface{}{ - "sourcecommit": triggerRepository, + "repository": repositoryTrigger, + "schedule": scheduleTrigger, + "sourcepipeline": sourcepipelineTrigger, } - return []map[string]interface{}{triggerInfo} } - return []map[string]interface{}{} } @@ -767,22 +876,35 @@ func convertClassicPipelineProject(r *sourcepipeline.GetProjectDetailResponse) * project.Task = append(project.Task, ti) } - triggers := &PipelineTrigger{ - Setting: r.Trigger.Setting, - } - - if *r.Trigger.Setting { - for _, repositoryInfo := range r.Trigger.Sourcecommit { - ri := &PipelineTriggerSourceCommit{ - RepositoryName: repositoryInfo.Repository, - Branch: repositoryInfo.Branch, + if r.Trigger != nil { + trigger := &PipelineTrigger{} + for _, repositoryInfo := range r.Trigger.Repository { + ri := &PipelineTriggerRepository{ + Type_: repositoryInfo.Type_, + Name: repositoryInfo.Name, + Branch: repositoryInfo.Branch, } - - triggers.Sourcecommit = append(triggers.Sourcecommit, ri) + trigger.Repository = append(trigger.Repository, ri) + } + for _, scheduleInfo := range r.Trigger.Schedule { + ri := &PipelineTriggerSchedule{ + Day: scheduleInfo.Day, + Time: scheduleInfo.Time, + TimeZone: scheduleInfo.TimeZone, + ScheduleOnlyWithChange: scheduleInfo.ScheduleOnlyWithChange, + } + trigger.Schedule = append(trigger.Schedule, ri) + } + for _, pipelineInfo := range r.Trigger.SourcePipeline { + ri := &PipelineTriggerSourcePipeline{ + Id: pipelineInfo.Id, + Name: pipelineInfo.Name, + } + trigger.SourcePipeline = append(trigger.SourcePipeline, ri) } - } - project.Triggers = triggers + project.Triggers = trigger + } return project } @@ -838,22 +960,35 @@ func convertVpcPipelineProject(r *vsourcepipeline.GetProjectDetailResponse) *Pip project.Task = append(project.Task, ti) } - triggers := &PipelineTrigger{ - Setting: r.Trigger.Setting, - } - - if *r.Trigger.Setting { - for _, repositoryInfo := range r.Trigger.Sourcecommit { - ri := &PipelineTriggerSourceCommit{ - RepositoryName: repositoryInfo.Repository, - Branch: repositoryInfo.Branch, + if r.Trigger != nil { + trigger := &PipelineTrigger{} + for _, repositoryInfo := range r.Trigger.Repository { + ri := &PipelineTriggerRepository{ + Type_: repositoryInfo.Type_, + Name: repositoryInfo.Name, + Branch: repositoryInfo.Branch, } - - triggers.Sourcecommit = append(triggers.Sourcecommit, ri) + trigger.Repository = append(trigger.Repository, ri) + } + for _, scheduleInfo := range r.Trigger.Schedule { + ri := &PipelineTriggerSchedule{ + Day: scheduleInfo.Day, + Time: scheduleInfo.Time, + TimeZone: scheduleInfo.TimeZone, + ScheduleOnlyWithChange: scheduleInfo.ScheduleOnlyWithChange, + } + trigger.Schedule = append(trigger.Schedule, ri) + } + for _, pipelineInfo := range r.Trigger.SourcePipeline { + ri := &PipelineTriggerSourcePipeline{ + Id: pipelineInfo.Id, + Name: pipelineInfo.Name, + } + trigger.SourcePipeline = append(trigger.SourcePipeline, ri) } - } - project.Triggers = triggers + project.Triggers = trigger + } return project } @@ -921,13 +1056,33 @@ type BitbucketWorkspace struct { } type PipelineTrigger struct { - Setting *bool `json:"setting,omitempty"` + Repository []*PipelineTriggerRepository `json:"repository,omitempty"` + + Schedule []*PipelineTriggerSchedule `json:"schedule,omitempty"` - Sourcecommit []*PipelineTriggerSourceCommit `json:"sourcecommit,omitempty"` + SourcePipeline []*PipelineTriggerSourcePipeline `json:"sourcepipeline,omitempty"` } -type PipelineTriggerSourceCommit struct { - RepositoryName *string `json:"repository,omitempty"` +type PipelineTriggerRepository struct { + Type_ *string `json:"type,omitempty"` + + Name *string `json:"name,omitempty"` Branch *string `json:"branch,omitempty"` } + +type PipelineTriggerSchedule struct { + Day []*string `json:"day,omitempty"` + + Time *string `json:"time,omitempty"` + + TimeZone *string `json:"timeZone,omitempty"` + + ScheduleOnlyWithChange *bool `json:"scheduleOnlyWithChange,omitempty"` +} + +type PipelineTriggerSourcePipeline struct { + Id *int32 `json:"id,omitempty"` + + Name *string `json:"name,omitempty"` +} diff --git a/ncloud/resource_ncloud_sourcepipeline_project_test.go b/ncloud/resource_ncloud_sourcepipeline_project_test.go index ce80415b3..ce5374746 100644 --- a/ncloud/resource_ncloud_sourcepipeline_project_test.go +++ b/ncloud/resource_ncloud_sourcepipeline_project_test.go @@ -297,9 +297,10 @@ resource "ncloud_sourcepipeline_project" "foo" { linked_tasks = [] } triggers { - sourcecommit { - repository_name = ncloud_sourcecommit_repository.test-repo.name - branch = "master" + repository { + type = "sourcecommit" + name = "sourceCommit" + branch = "master" } } } @@ -387,9 +388,10 @@ resource "ncloud_sourcepipeline_project" "foo" { linked_tasks = [] } triggers { - sourcecommit { - repository_name = ncloud_sourcecommit_repository.test-repo.name - branch = "master" + repository { + type = "sourcecommit" + name = "sourceCommit" + branch = "master" } } } @@ -477,9 +479,10 @@ resource "ncloud_sourcepipeline_project" "foo" { linked_tasks = [] } triggers { - sourcecommit { - repository_name = ncloud_sourcecommit_repository.test-repo.name - branch = "master" + repository { + type = "sourcecommit" + name = "sourceCommit" + branch = "master" } } } @@ -567,9 +570,10 @@ resource "ncloud_sourcepipeline_project" "foo" { linked_tasks = [] } triggers { - sourcecommit { - repository_name = ncloud_sourcecommit_repository.test-repo.name - branch = "master" + repository { + type = "sourcecommit" + name = "sourceCommit" + branch = "master" } } } @@ -657,9 +661,10 @@ resource "ncloud_sourcepipeline_project" "foo" { linked_tasks = [] } triggers { - sourcecommit { - repository_name = ncloud_sourcecommit_repository.test-repo.name - branch = "master" + repository { + type = "sourcecommit" + name = "sourceCommit" + branch = "master" } } } @@ -747,9 +752,10 @@ resource "ncloud_sourcepipeline_project" "foo" { linked_tasks = [] } triggers { - sourcecommit { - repository_name = ncloud_sourcecommit_repository.test-repo.name - branch = "master" + repository { + type = "sourcecommit" + name = "sourceCommit" + branch = "master" } } } From f6a82a2ec1be42dae21910a8b5d355226ecc252e Mon Sep 17 00:00:00 2001 From: daegon-lee Date: Wed, 30 Nov 2022 18:42:39 +0900 Subject: [PATCH 2/5] Update: sourcepipeline trigger attributes --- docs/data-sources/sourcepipeline_project.md | 2 +- docs/resources/sourcepipeline_project.md | 10 +++++----- examples/sourcepipeline/main.tf | 2 +- .../data_source_ncloud_sourcepipeline_project.go | 2 +- ...ta_source_ncloud_sourcepipeline_project_test.go | 2 +- ncloud/resource_ncloud_sourcepipeline_project.go | 14 +++++++------- 6 files changed, 16 insertions(+), 16 deletions(-) diff --git a/docs/data-sources/sourcepipeline_project.md b/docs/data-sources/sourcepipeline_project.md index 35b480ac1..55ab4e1cd 100644 --- a/docs/data-sources/sourcepipeline_project.md +++ b/docs/data-sources/sourcepipeline_project.md @@ -59,7 +59,7 @@ The following attributes are exported: * `day` - List of day of week . * `time` - Time to trigger. * `timezone` - Timezone for trigger. - * `schedule_only_with_change` - Schedule trigger option. You can decide whether schedule trigger only execute when SourcePipeline configuration or Repositoryor not. + * `execute_only_with_change` - Schedule trigger option. Schedule trigger always execute in time, if option is false. Schedule trigger execute when Sourcepipeline project configuration or Sourcecommit repository has changed, if option is true. * `sourcepipeline` - Sourcepipeline trigger. * `id` - Id of the sourcepipeline project to trigger execution of pipeline. * `name` - Name of the sourcepipeline project to trigger execution of pipeline. diff --git a/docs/resources/sourcepipeline_project.md b/docs/resources/sourcepipeline_project.md index edf6b9c0f..fe5afcd67 100644 --- a/docs/resources/sourcepipeline_project.md +++ b/docs/resources/sourcepipeline_project.md @@ -46,7 +46,7 @@ resource "ncloud_sourcepipeline_project" "test-sourcepipeline" { day = ["MON", "TUE"] time = "13:01" timezone = "Asia/Seoul (UTC+09:00)" - schedule_only_with_change = false + execute_only_with_change = false } sourcepipeline { id = 1234 @@ -113,7 +113,7 @@ resource "ncloud_sourcepipeline_project" "test-sourcepipeline" { day = ["MON", "TUE"] time = "13:01" timezone = "Asia/Seoul (UTC+09:00)" - schedule_only_with_change = false + execute_only_with_change = false } sourcepipeline { id = data.ncloud_sourcebuild_projects.test-sourcepipeline.projects[0].id @@ -144,10 +144,10 @@ The following arguments are supported: * `name` - (Optional, Required if `trigger.repository` exists) Name of repository. * `branch` - (Optional, Required if `trigger.repository` exists) Name of a repository branch. * `schedule` - (Optional) - * `day` - (Optional, Required if `trigger.schedule` exists) List of day of week. + * `day` - (Optional, Required if `trigger.schedule` exists) List of day of week. Accepted values: `MON` | `TUE` | `WED` | `THU` | `FRI` | `SAT` | `SUN`. * `time` - (Optional, Required if `trigger.schedule` exists) Time to trigger. - * `timezone` - (Optional, Required if `trigger.schedule` exists) Timezone for trigger. Accepted values: `MON` | `TUE` | `WED` | `THU` | `FRI` | `SAT` | `SUN`. - * `schedule_only_with_change` - (Optional, Required if `trigger.schedule` exists) Schedule trigger option. You can decide whether schedule trigger always execute in time or execute if Sourcepipeline project configuration or Sourcecommit repository has changed. + * `timezone` - (Optional, Required if `trigger.schedule` exists) Timezone for trigger. + * `execute_only_with_change` - (Optional, Required if `trigger.schedule` exists) Schedule trigger option. You can decide whether schedule trigger always execute in time or execute if Sourcepipeline project configuration or Sourcecommit repository has changed. * `sourcepipeline` - (Optional) * `id` - (Optional, Required if `trigger.sourcepipeline` exists) Id of the sourcepipeline project. diff --git a/examples/sourcepipeline/main.tf b/examples/sourcepipeline/main.tf index 46be857bf..5a2c6dd11 100644 --- a/examples/sourcepipeline/main.tf +++ b/examples/sourcepipeline/main.tf @@ -59,7 +59,7 @@ resource "ncloud_sourcepipeline_project" "test-sourcepipeline" { day = ["MON", "TUE"] time = "13:01" timezone = "Asia/Seoul (UTC+09:00)" - schedule_only_with_change = false + execute_only_with_change = false } sourcepipeline { id = data.ncloud_sourcepipeline_projects.test-sourcepipeline.projects[0].id diff --git a/ncloud/data_source_ncloud_sourcepipeline_project.go b/ncloud/data_source_ncloud_sourcepipeline_project.go index 732bb39fc..9f0c85ff7 100644 --- a/ncloud/data_source_ncloud_sourcepipeline_project.go +++ b/ncloud/data_source_ncloud_sourcepipeline_project.go @@ -152,7 +152,7 @@ func dataSourceNcloudSourcePipelineProject() *schema.Resource { Type: schema.TypeString, Computed: true, }, - "schedule_only_with_change": { + "execute_only_with_change": { Type: schema.TypeBool, Computed: true, }, diff --git a/ncloud/data_source_ncloud_sourcepipeline_project_test.go b/ncloud/data_source_ncloud_sourcepipeline_project_test.go index 3625c1df5..7bcf407fa 100644 --- a/ncloud/data_source_ncloud_sourcepipeline_project_test.go +++ b/ncloud/data_source_ncloud_sourcepipeline_project_test.go @@ -134,7 +134,7 @@ resource "ncloud_sourcepipeline_project" "test-project" { day = ["MON", "TUE"] time = "13:01" timezone = "Asia/Seoul (UTC+09:00)" - schedule_only_with_change = false + execute_only_with_change = false } } } diff --git a/ncloud/resource_ncloud_sourcepipeline_project.go b/ncloud/resource_ncloud_sourcepipeline_project.go index d0f5c12fd..c3a58749f 100644 --- a/ncloud/resource_ncloud_sourcepipeline_project.go +++ b/ncloud/resource_ncloud_sourcepipeline_project.go @@ -185,7 +185,7 @@ func resourceNcloudSourcePipeline() *schema.Resource { Type: schema.TypeString, Required: true, }, - "schedule_only_with_change": { + "execute_only_with_change": { Type: schema.TypeBool, Required: true, }, @@ -554,7 +554,7 @@ func makeClassicPipelineTriggerParams(d *schema.ResourceData) *sourcepipeline.Cr Day: StringListPtrOrNil(d.GetOk(prefix + "day")), Time: StringPtrOrNil(d.GetOk(prefix + "time")), TimeZone: StringPtrOrNil(d.GetOk(prefix + "timezone")), - ScheduleOnlyWithChange: ncloud.Bool(d.Get(prefix + "schedule_only_with_change").(bool)), + ScheduleOnlyWithChange: ncloud.Bool(d.Get(prefix + "execute_only_with_change").(bool)), }) } pipelineTrigger.Schedule = scheduleTrigger @@ -598,7 +598,7 @@ func makeVpcPipelineTriggerParams(d *schema.ResourceData) *vsourcepipeline.Creat Day: StringListPtrOrNil(d.GetOk(prefix + "day")), Time: StringPtrOrNil(d.GetOk(prefix + "time")), TimeZone: StringPtrOrNil(d.GetOk(prefix + "timezone")), - ScheduleOnlyWithChange: ncloud.Bool(d.Get(prefix + "schedule_only_with_change").(bool)), + ScheduleOnlyWithChange: ncloud.Bool(d.Get(prefix + "execute_only_with_change").(bool)), }) } pipelineTrigger.Schedule = scheduleTrigger @@ -797,7 +797,7 @@ func makeTriggerData(triggerData *PipelineTrigger) []map[string]interface{} { "day": ncloud.StringListValue(schedule.Day), "time": ncloud.StringValue(schedule.Time), "timezone": ncloud.StringValue(schedule.TimeZone), - "schedule_only_with_change": ncloud.BoolValue(schedule.ScheduleOnlyWithChange), + "execute_only_with_change": ncloud.BoolValue(schedule.ExecuteOnlyWithChange), } scheduleTrigger = append(scheduleTrigger, mapping) } @@ -891,7 +891,7 @@ func convertClassicPipelineProject(r *sourcepipeline.GetProjectDetailResponse) * Day: scheduleInfo.Day, Time: scheduleInfo.Time, TimeZone: scheduleInfo.TimeZone, - ScheduleOnlyWithChange: scheduleInfo.ScheduleOnlyWithChange, + ExecuteOnlyWithChange: scheduleInfo.ScheduleOnlyWithChange, } trigger.Schedule = append(trigger.Schedule, ri) } @@ -975,7 +975,7 @@ func convertVpcPipelineProject(r *vsourcepipeline.GetProjectDetailResponse) *Pip Day: scheduleInfo.Day, Time: scheduleInfo.Time, TimeZone: scheduleInfo.TimeZone, - ScheduleOnlyWithChange: scheduleInfo.ScheduleOnlyWithChange, + ExecuteOnlyWithChange: scheduleInfo.ScheduleOnlyWithChange, } trigger.Schedule = append(trigger.Schedule, ri) } @@ -1078,7 +1078,7 @@ type PipelineTriggerSchedule struct { TimeZone *string `json:"timeZone,omitempty"` - ScheduleOnlyWithChange *bool `json:"scheduleOnlyWithChange,omitempty"` + ExecuteOnlyWithChange *bool `json:"scheduleOnlyWithChange,omitempty"` } type PipelineTriggerSourcePipeline struct { From 8d1b367b9325b7fb8ccc3d873d85e33cac013171 Mon Sep 17 00:00:00 2001 From: daegon-lee Date: Fri, 2 Dec 2022 14:33:24 +0900 Subject: [PATCH 3/5] update: ncloud-sdk-go-v2 version to 1.5.6 --- go.mod | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/go.mod b/go.mod index 47e369274..6f7a3ad07 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/terraform-providers/terraform-provider-ncloud go 1.16 require ( - github.com/NaverCloudPlatform/ncloud-sdk-go-v2 v1.5.3 + github.com/NaverCloudPlatform/ncloud-sdk-go-v2 v1.5.6 github.com/hashicorp/go-cty v1.4.1-0.20200414143053-d3edf31b6320 github.com/hashicorp/terraform-plugin-sdk/v2 v2.13.0 gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c From 75aa6953e0f137afe36f893596c54f31d604db09 Mon Sep 17 00:00:00 2001 From: daegon-lee Date: Mon, 5 Dec 2022 19:36:41 +0900 Subject: [PATCH 4/5] Modify triggers schema type to Optional --- ncloud/resource_ncloud_sourcepipeline_project.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/ncloud/resource_ncloud_sourcepipeline_project.go b/ncloud/resource_ncloud_sourcepipeline_project.go index c3a58749f..a864c8c75 100644 --- a/ncloud/resource_ncloud_sourcepipeline_project.go +++ b/ncloud/resource_ncloud_sourcepipeline_project.go @@ -141,7 +141,7 @@ func resourceNcloudSourcePipeline() *schema.Resource { }, "triggers": { Type: schema.TypeList, - Required: true, + Optional: true, MaxItems: 1, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ @@ -903,7 +903,9 @@ func convertClassicPipelineProject(r *sourcepipeline.GetProjectDetailResponse) * trigger.SourcePipeline = append(trigger.SourcePipeline, ri) } - project.Triggers = trigger + if len(r.Trigger.Repository) != 0 || len(r.Trigger.Schedule) != 0 || len(r.Trigger.SourcePipeline) != 0 { + project.Triggers = trigger + } } return project @@ -987,7 +989,9 @@ func convertVpcPipelineProject(r *vsourcepipeline.GetProjectDetailResponse) *Pip trigger.SourcePipeline = append(trigger.SourcePipeline, ri) } - project.Triggers = trigger + if len(r.Trigger.Repository) != 0 || len(r.Trigger.Schedule) != 0 || len(r.Trigger.SourcePipeline) != 0 { + project.Triggers = trigger + } } return project From 4929a2322c80481d9ec7bb148042a67b69bd6459 Mon Sep 17 00:00:00 2001 From: daegon-lee Date: Tue, 6 Dec 2022 02:18:59 +0900 Subject: [PATCH 5/5] Modify trigger attributes type to typeSet --- .../resource_ncloud_sourcepipeline_project.go | 68 +++++++++---------- 1 file changed, 31 insertions(+), 37 deletions(-) diff --git a/ncloud/resource_ncloud_sourcepipeline_project.go b/ncloud/resource_ncloud_sourcepipeline_project.go index a864c8c75..2178727af 100644 --- a/ncloud/resource_ncloud_sourcepipeline_project.go +++ b/ncloud/resource_ncloud_sourcepipeline_project.go @@ -146,7 +146,7 @@ func resourceNcloudSourcePipeline() *schema.Resource { Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ "repository": { - Type: schema.TypeList, + Type: schema.TypeSet, Optional: true, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ @@ -166,7 +166,7 @@ func resourceNcloudSourcePipeline() *schema.Resource { }, }, "schedule": { - Type: schema.TypeList, + Type: schema.TypeSet, Optional: true, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ @@ -193,7 +193,7 @@ func resourceNcloudSourcePipeline() *schema.Resource { }, }, "sourcepipeline": { - Type: schema.TypeList, + Type: schema.TypeSet, Optional: true, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ @@ -535,36 +535,33 @@ func makeClassicPipelineTriggerParams(d *schema.ResourceData) *sourcepipeline.Cr pipelineTrigger := &sourcepipeline.CreateProjectTrigger{} if _, ok := d.GetOk("triggers.0.repository"); ok { - triggerCount := d.Get("triggers.0.repository.#").(int) - for i := 0; i < triggerCount; i++ { - prefix := fmt.Sprintf("triggers.0.repository.%d.", i) + for _, ti := range d.Get("triggers.0.repository").(*schema.Set).List() { + triggerInput := ti.(map[string]interface{}) repositoryTrigger = append(repositoryTrigger, &sourcepipeline.GetRepositoryTrigger{ - Type_: StringPtrOrNil(d.GetOk(prefix + "type")), - Name: StringPtrOrNil(d.GetOk(prefix + "name")), - Branch: StringPtrOrNil(d.GetOk(prefix + "branch")), + Type_: ncloud.String(triggerInput["type"].(string)), + Name: ncloud.String(triggerInput["name"].(string)), + Branch: ncloud.String(triggerInput["branch"].(string)), }) } pipelineTrigger.Repository = repositoryTrigger } if _, ok := d.GetOk("triggers.0.schedule"); ok { - triggerCount := d.Get("triggers.0.schedule.#").(int) - for i := 0; i < triggerCount; i++ { - prefix := fmt.Sprintf("triggers.0.schedule.%d.", i) + for _, ti := range d.Get("triggers.0.schedule").(*schema.Set).List() { + triggerInput := ti.(map[string]interface{}) scheduleTrigger = append(scheduleTrigger, &sourcepipeline.GetScheduleTrigger{ - Day: StringListPtrOrNil(d.GetOk(prefix + "day")), - Time: StringPtrOrNil(d.GetOk(prefix + "time")), - TimeZone: StringPtrOrNil(d.GetOk(prefix + "timezone")), - ScheduleOnlyWithChange: ncloud.Bool(d.Get(prefix + "execute_only_with_change").(bool)), + Day: ncloud.StringInterfaceList(triggerInput["day"].([]interface{})), + Time: ncloud.String(triggerInput["time"].(string)), + TimeZone: ncloud.String(triggerInput["timezone"].(string)), + ScheduleOnlyWithChange: ncloud.Bool(triggerInput["execute_only_with_change"].(bool)), }) } pipelineTrigger.Schedule = scheduleTrigger } if _, ok := d.GetOk("triggers.0.sourcepipeline"); ok { - triggerCount := d.Get("triggers.0.sourcepipeline.#").(int) - for i := 0; i < triggerCount; i++ { - prefix := fmt.Sprintf("triggers.0.sourcepipeline.%d.", i) + for _, ti := range d.Get("triggers.0.sourcepipeline").(*schema.Set).List() { + triggerInput := ti.(map[string]interface{}) sourcepipelineTrigger = append(sourcepipelineTrigger, &sourcepipeline.GetPipelineTrigger{ - Id: Int32PtrOrNil(d.GetOk(prefix + "id")), + Id: ncloud.Int32(int32(triggerInput["id"].(int))), }) } pipelineTrigger.SourcePipeline = sourcepipelineTrigger @@ -579,36 +576,33 @@ func makeVpcPipelineTriggerParams(d *schema.ResourceData) *vsourcepipeline.Creat pipelineTrigger := &vsourcepipeline.CreateProjectTrigger{} if _, ok := d.GetOk("triggers.0.repository"); ok { - triggerCount := d.Get("triggers.0.repository.#").(int) - for i := 0; i < triggerCount; i++ { - prefix := fmt.Sprintf("triggers.0.repository.%d.", i) + for _, ti := range d.Get("triggers.0.repository").(*schema.Set).List() { + triggerInput := ti.(map[string]interface{}) repositoryTrigger = append(repositoryTrigger, &vsourcepipeline.GetRepositoryTrigger{ - Type_: StringPtrOrNil(d.GetOk(prefix + "type")), - Name: StringPtrOrNil(d.GetOk(prefix + "name")), - Branch: StringPtrOrNil(d.GetOk(prefix + "branch")), + Type_: ncloud.String(triggerInput["type"].(string)), + Name: ncloud.String(triggerInput["name"].(string)), + Branch: ncloud.String(triggerInput["branch"].(string)), }) } pipelineTrigger.Repository = repositoryTrigger } if _, ok := d.GetOk("triggers.0.schedule"); ok { - triggerCount := d.Get("triggers.0.schedule.#").(int) - for i := 0; i < triggerCount; i++ { - prefix := fmt.Sprintf("triggers.0.schedule.%d.", i) + for _, ti := range d.Get("triggers.0.schedule").(*schema.Set).List() { + triggerInput := ti.(map[string]interface{}) scheduleTrigger = append(scheduleTrigger, &vsourcepipeline.GetScheduleTrigger{ - Day: StringListPtrOrNil(d.GetOk(prefix + "day")), - Time: StringPtrOrNil(d.GetOk(prefix + "time")), - TimeZone: StringPtrOrNil(d.GetOk(prefix + "timezone")), - ScheduleOnlyWithChange: ncloud.Bool(d.Get(prefix + "execute_only_with_change").(bool)), + Day: ncloud.StringInterfaceList(triggerInput["day"].([]interface{})), + Time: ncloud.String(triggerInput["time"].(string)), + TimeZone: ncloud.String(triggerInput["timezone"].(string)), + ScheduleOnlyWithChange: ncloud.Bool(triggerInput["execute_only_with_change"].(bool)), }) } pipelineTrigger.Schedule = scheduleTrigger } if _, ok := d.GetOk("triggers.0.sourcepipeline"); ok { - triggerCount := d.Get("triggers.0.sourcepipeline.#").(int) - for i := 0; i < triggerCount; i++ { - prefix := fmt.Sprintf("triggers.0.sourcepipeline.%d.", i) + for _, ti := range d.Get("triggers.0.sourcepipeline").(*schema.Set).List() { + triggerInput := ti.(map[string]interface{}) sourcepipelineTrigger = append(sourcepipelineTrigger, &vsourcepipeline.GetPipelineTrigger{ - Id: Int32PtrOrNil(d.GetOk(prefix + "id")), + Id: ncloud.Int32(int32(triggerInput["id"].(int))), }) } pipelineTrigger.SourcePipeline = sourcepipelineTrigger