-
Notifications
You must be signed in to change notification settings - Fork 71
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 #252 from Cloud-SH/master
update: sourcepipeline(trigger) resources and data
- Loading branch information
Showing
11 changed files
with
515 additions
and
106 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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. |
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
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
79 changes: 79 additions & 0 deletions
79
ncloud/data_source_ncloud_sourcepipeline_trigger_timezone.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,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 | ||
} |
44 changes: 44 additions & 0 deletions
44
ncloud/data_source_ncloud_sourcepipeline_trigger_timezone_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,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" { | ||
} | ||
`) | ||
} |
Oops, something went wrong.