diff --git a/docs/data-sources/sourcepipeline_project.md b/docs/data-sources/sourcepipeline_project.md index da23e4006..55ab4e1cd 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. + * `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/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..fe5afcd67 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)" + execute_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)" + execute_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. 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. + * `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. ## 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..5a2c6dd11 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)" + execute_only_with_change = false + } + sourcepipeline { + id = data.ncloud_sourcepipeline_projects.test-sourcepipeline.projects[0].id } } } diff --git a/go.mod b/go.mod index 7898f48b9..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.5 + 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 diff --git a/ncloud/data_source_ncloud_sourcepipeline_project.go b/ncloud/data_source_ncloud_sourcepipeline_project.go index 161614ed3..9f0c85ff7 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, + }, + "execute_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..7bcf407fa 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)" + execute_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..2178727af 100644 --- a/ncloud/resource_ncloud_sourcepipeline_project.go +++ b/ncloud/resource_ncloud_sourcepipeline_project.go @@ -141,16 +141,20 @@ func resourceNcloudSourcePipeline() *schema.Resource { }, "triggers": { Type: schema.TypeList, - Required: true, + Optional: true, MaxItems: 1, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ - "sourcecommit": { - Type: schema.TypeList, + "repository": { + Type: schema.TypeSet, 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.TypeSet, + 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, + }, + "execute_only_with_change": { + Type: schema.TypeBool, + Required: true, + }, + }, + }, + }, + "sourcepipeline": { + Type: schema.TypeSet, + 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,83 @@ func makeVpcPipelineTaskParams(d *schema.ResourceData) ([]*vsourcepipeline.Creat } func makeClassicPipelineTriggerParams(d *schema.ResourceData) *sourcepipeline.CreateProjectTrigger { - var triggerTargets []*sourcepipeline.GetScTargetInfo - setting := false - - if _, ok := d.GetOk("triggers.0.sourcecommit"); ok { - setting = true - triggerCount := d.Get("triggers.0.sourcecommit.#").(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")), + var repositoryTrigger []*sourcepipeline.GetRepositoryTrigger + var scheduleTrigger []*sourcepipeline.GetScheduleTrigger + var sourcepipelineTrigger []*sourcepipeline.GetPipelineTrigger + pipelineTrigger := &sourcepipeline.CreateProjectTrigger{} + + if _, ok := d.GetOk("triggers.0.repository"); ok { + for _, ti := range d.Get("triggers.0.repository").(*schema.Set).List() { + triggerInput := ti.(map[string]interface{}) + repositoryTrigger = append(repositoryTrigger, &sourcepipeline.GetRepositoryTrigger{ + Type_: ncloud.String(triggerInput["type"].(string)), + Name: ncloud.String(triggerInput["name"].(string)), + Branch: ncloud.String(triggerInput["branch"].(string)), }) } + pipelineTrigger.Repository = repositoryTrigger } - - pipelineTrigger := &sourcepipeline.CreateProjectTrigger{ - Setting: ncloud.Bool(setting), - Sourcecommit: triggerTargets, + if _, ok := d.GetOk("triggers.0.schedule"); ok { + for _, ti := range d.Get("triggers.0.schedule").(*schema.Set).List() { + triggerInput := ti.(map[string]interface{}) + scheduleTrigger = append(scheduleTrigger, &sourcepipeline.GetScheduleTrigger{ + 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 { + for _, ti := range d.Get("triggers.0.sourcepipeline").(*schema.Set).List() { + triggerInput := ti.(map[string]interface{}) + sourcepipelineTrigger = append(sourcepipelineTrigger, &sourcepipeline.GetPipelineTrigger{ + Id: ncloud.Int32(int32(triggerInput["id"].(int))), + }) + } + pipelineTrigger.SourcePipeline = sourcepipelineTrigger } return pipelineTrigger } func makeVpcPipelineTriggerParams(d *schema.ResourceData) *vsourcepipeline.CreateProjectTrigger { - var triggerTargets []*vsourcepipeline.GetScTargetInfo - setting := false - - if _, ok := d.GetOk("triggers.0.sourcecommit"); ok { - setting = true - triggerCount := d.Get("triggers.0.sourcecommit.#").(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")), + var repositoryTrigger []*vsourcepipeline.GetRepositoryTrigger + var scheduleTrigger []*vsourcepipeline.GetScheduleTrigger + var sourcepipelineTrigger []*vsourcepipeline.GetPipelineTrigger + pipelineTrigger := &vsourcepipeline.CreateProjectTrigger{} + + if _, ok := d.GetOk("triggers.0.repository"); ok { + for _, ti := range d.Get("triggers.0.repository").(*schema.Set).List() { + triggerInput := ti.(map[string]interface{}) + repositoryTrigger = append(repositoryTrigger, &vsourcepipeline.GetRepositoryTrigger{ + Type_: ncloud.String(triggerInput["type"].(string)), + Name: ncloud.String(triggerInput["name"].(string)), + Branch: ncloud.String(triggerInput["branch"].(string)), }) } + pipelineTrigger.Repository = repositoryTrigger } - - pipelineTrigger := &vsourcepipeline.CreateProjectTrigger{ - Setting: ncloud.Bool(setting), - Sourcecommit: triggerTargets, + if _, ok := d.GetOk("triggers.0.schedule"); ok { + for _, ti := range d.Get("triggers.0.schedule").(*schema.Set).List() { + triggerInput := ti.(map[string]interface{}) + scheduleTrigger = append(scheduleTrigger, &vsourcepipeline.GetScheduleTrigger{ + 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 { + for _, ti := range d.Get("triggers.0.sourcepipeline").(*schema.Set).List() { + triggerInput := ti.(map[string]interface{}) + sourcepipelineTrigger = append(sourcepipelineTrigger, &vsourcepipeline.GetPipelineTrigger{ + Id: ncloud.Int32(int32(triggerInput["id"].(int))), + }) + } + pipelineTrigger.SourcePipeline = sourcepipelineTrigger } return pipelineTrigger } @@ -691,21 +774,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{}{ - "repository_name": ncloud.StringValue(repo.RepositoryName), - "branch": ncloud.StringValue(repo.Branch), + "type": ncloud.StringValue(repo.Type_), + "name": ncloud.StringValue(repo.Name), + "branch": ncloud.StringValue(repo.Branch), } - triggerRepository = append(triggerRepository, mapping) + 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), + "execute_only_with_change": ncloud.BoolValue(schedule.ExecuteOnlyWithChange), + } + scheduleTrigger = append(scheduleTrigger, mapping) + } + for _, pipeline := range triggerData.SourcePipeline { + mapping := map[string]interface{}{ + "id": ncloud.Int32Value(pipeline.Id), + "name": ncloud.StringValue(pipeline.Name), + } + 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,23 +870,38 @@ 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, } + trigger.Repository = append(trigger.Repository, ri) + } + for _, scheduleInfo := range r.Trigger.Schedule { + ri := &PipelineTriggerSchedule{ + Day: scheduleInfo.Day, + Time: scheduleInfo.Time, + TimeZone: scheduleInfo.TimeZone, + ExecuteOnlyWithChange: 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) + } - triggers.Sourcecommit = append(triggers.Sourcecommit, ri) + if len(r.Trigger.Repository) != 0 || len(r.Trigger.Schedule) != 0 || len(r.Trigger.SourcePipeline) != 0 { + project.Triggers = trigger } } - project.Triggers = triggers - return project } @@ -838,23 +956,38 @@ 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, } + trigger.Repository = append(trigger.Repository, ri) + } + for _, scheduleInfo := range r.Trigger.Schedule { + ri := &PipelineTriggerSchedule{ + Day: scheduleInfo.Day, + Time: scheduleInfo.Time, + TimeZone: scheduleInfo.TimeZone, + ExecuteOnlyWithChange: 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) + } - triggers.Sourcecommit = append(triggers.Sourcecommit, ri) + if len(r.Trigger.Repository) != 0 || len(r.Trigger.Schedule) != 0 || len(r.Trigger.SourcePipeline) != 0 { + project.Triggers = trigger } } - project.Triggers = triggers - return project } @@ -921,13 +1054,33 @@ type BitbucketWorkspace struct { } type PipelineTrigger struct { - Setting *bool `json:"setting,omitempty"` + Repository []*PipelineTriggerRepository `json:"repository,omitempty"` - Sourcecommit []*PipelineTriggerSourceCommit `json:"sourcecommit,omitempty"` + Schedule []*PipelineTriggerSchedule `json:"schedule,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"` + + ExecuteOnlyWithChange *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" } } }