Skip to content

Commit 599bdea

Browse files
committed
Apply default values in Terraform and CloudRun plugin
Signed-off-by: Rawad Hossain <rawad.hossain00@gmail.com>
1 parent 1c045f7 commit 599bdea

File tree

2 files changed

+45
-2
lines changed

2 files changed

+45
-2
lines changed

pkg/app/pipedv1/plugin/cloudrun/config/application.go

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,12 @@
1414

1515
package config
1616

17-
import "github.com/pipe-cd/piped-plugin-sdk-go/unit"
17+
import (
18+
"encoding/json"
19+
20+
"github.com/creasty/defaults"
21+
"github.com/pipe-cd/piped-plugin-sdk-go/unit"
22+
)
1823

1924
type CloudRunApplicationSpec struct {
2025
// Input for CloudRun deployment such as docker image...
@@ -23,10 +28,26 @@ type CloudRunApplicationSpec struct {
2328
QuickSync CloudRunSyncStageOptions `json:"quickSync"`
2429
}
2530

31+
func (s *CloudRunApplicationSpec) UnmarshalJSON(data []byte) error {
32+
type alias CloudRunApplicationSpec
33+
34+
var a alias
35+
if err := json.Unmarshal(data, &a); err != nil {
36+
return err
37+
}
38+
39+
*s = CloudRunApplicationSpec(a)
40+
if err := defaults.Set(s); err != nil {
41+
return err
42+
}
43+
44+
return nil
45+
}
46+
2647
type CloudRunDeploymentInput struct {
2748
// The name of service manifest file placing in application directory.
2849
// Default is service.yaml
29-
ServiceManifestFile string `json:"serviceManifestFile"`
50+
ServiceManifestFile string `json:"serviceManifestFile" default:"service.yaml"`
3051
}
3152

3253
// CloudRunSyncStageOptions contains all configurable values for a CLOUDRUN_SYNC stage.

pkg/app/pipedv1/plugin/terraform/config/config.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@
1414

1515
package config
1616

17+
import (
18+
"encoding/json"
19+
20+
"github.com/creasty/defaults"
21+
)
22+
1723
// Config represents the plugin-scoped configuration.
1824
type Config struct{}
1925

@@ -30,6 +36,22 @@ type DeployTargetConfig struct {
3036
DriftDetectionEnabled *bool `json:"driftDetectionEnabled" default:"true"`
3137
}
3238

39+
func (c *DeployTargetConfig) UnmarshalJSON(data []byte) error {
40+
type alias DeployTargetConfig
41+
42+
var a alias
43+
if err := json.Unmarshal(data, &a); err != nil {
44+
return err
45+
}
46+
47+
*c = DeployTargetConfig(a)
48+
if err := defaults.Set(c); err != nil {
49+
return err
50+
}
51+
52+
return nil
53+
}
54+
3355
// ApplicationConfigSpec represents the application-scoped plugin config.
3456
type ApplicationConfigSpec struct {
3557
// The terraform workspace name.

0 commit comments

Comments
 (0)