diff --git a/pkg/app/piped/cloudprovider/terraform/module.go b/pkg/app/piped/cloudprovider/terraform/module.go index 205e06cd5f..fed3d86ddc 100644 --- a/pkg/app/piped/cloudprovider/terraform/module.go +++ b/pkg/app/piped/cloudprovider/terraform/module.go @@ -22,7 +22,7 @@ type FileMapping struct { type ModuleMapping struct { Name string `hcl:"name,label"` Source string `hcl:"source"` - Version string `hcl:"version"` + Version string `hcl:"version,optional"` Remain hcl.Body `hcl:",remain"` } diff --git a/pkg/app/piped/cloudprovider/terraform/module_test.go b/pkg/app/piped/cloudprovider/terraform/module_test.go index 5e8453bb93..6fc0d3cae4 100644 --- a/pkg/app/piped/cloudprovider/terraform/module_test.go +++ b/pkg/app/piped/cloudprovider/terraform/module_test.go @@ -34,6 +34,22 @@ func TestLoadTerraformFiles(t *testing.T) { }, expectedErr: false, }, + { + name: "single module with optional argument", + moduleDir: "./testdata/single_module_optional", + expected: []File{ + { + Modules: []*Module{ + { + Name: "helloworld", + Source: "helloworld", + Version: "", + }, + }, + }, + }, + expectedErr: false, + }, { name: "multi modules", moduleDir: "./testdata/multi_modules", @@ -120,6 +136,19 @@ func TestFindArticatVersions(t *testing.T) { }, expectedErr: false, }, + { + name: "single module with optional field", + moduleDir: "./testdata/single_module_optional", + expected: []*model.ArtifactVersion{ + { + Kind: model.ArtifactVersion_TERRAFORM_MODULE, + Name: "helloworld", + Url: "helloworld", + Version: "", + }, + }, + expectedErr: false, + }, { name: "multi modules", moduleDir: "./testdata/multi_modules", diff --git a/pkg/app/piped/cloudprovider/terraform/testdata/single_module_optional/helloworld/main.tf b/pkg/app/piped/cloudprovider/terraform/testdata/single_module_optional/helloworld/main.tf new file mode 100644 index 0000000000..6dadf55b5b --- /dev/null +++ b/pkg/app/piped/cloudprovider/terraform/testdata/single_module_optional/helloworld/main.tf @@ -0,0 +1,19 @@ +resource "docker_container" "helloworld" { + name = "gcr.io/pipecd/helloworld:${var.image_version}" + ports { + internal = 9376 + external = "${var.external_port}" + } +} + +variable "external_port" { + default = 80 +} + +variable "image_version" { + default = "latest" +} + +output "container" { + value = docker_image.helloworld +} diff --git a/pkg/app/piped/cloudprovider/terraform/testdata/single_module_optional/main.tf b/pkg/app/piped/cloudprovider/terraform/testdata/single_module_optional/main.tf new file mode 100644 index 0000000000..2ab0a5fa49 --- /dev/null +++ b/pkg/app/piped/cloudprovider/terraform/testdata/single_module_optional/main.tf @@ -0,0 +1,8 @@ +provider "docker" { +} + +module "helloworld" { + source = "helloworld" + image_version = "v1.0.0" + external_port = 8080 +} diff --git a/pkg/model/common.pb.go b/pkg/model/common.pb.go index 4918c9a4ea..8438d03941 100644 --- a/pkg/model/common.pb.go +++ b/pkg/model/common.pb.go @@ -643,39 +643,38 @@ var file_pkg_model_common_proto_rawDesc = []byte{ 0x1a, 0x39, 0x0a, 0x0b, 0x4c, 0x61, 0x62, 0x65, 0x6c, 0x73, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, - 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38, 0x01, 0x22, 0xf4, 0x01, 0x0a, 0x0f, + 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38, 0x01, 0x22, 0xeb, 0x01, 0x0a, 0x0f, 0x41, 0x72, 0x74, 0x69, 0x66, 0x61, 0x63, 0x74, 0x56, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x12, 0x39, 0x0a, 0x04, 0x6b, 0x69, 0x6e, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x1b, 0x2e, 0x6d, 0x6f, 0x64, 0x65, 0x6c, 0x2e, 0x41, 0x72, 0x74, 0x69, 0x66, 0x61, 0x63, 0x74, 0x56, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x2e, 0x4b, 0x69, 0x6e, 0x64, 0x42, 0x08, 0xfa, 0x42, 0x05, 0x82, - 0x01, 0x02, 0x10, 0x01, 0x52, 0x04, 0x6b, 0x69, 0x6e, 0x64, 0x12, 0x21, 0x0a, 0x07, 0x76, 0x65, - 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x42, 0x07, 0xfa, 0x42, 0x04, - 0x72, 0x02, 0x10, 0x01, 0x52, 0x07, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x12, 0x12, 0x0a, - 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, - 0x65, 0x12, 0x10, 0x0a, 0x03, 0x75, 0x72, 0x6c, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, - 0x75, 0x72, 0x6c, 0x22, 0x5d, 0x0a, 0x04, 0x4b, 0x69, 0x6e, 0x64, 0x12, 0x0b, 0x0a, 0x07, 0x55, - 0x4e, 0x4b, 0x4e, 0x4f, 0x57, 0x4e, 0x10, 0x00, 0x12, 0x13, 0x0a, 0x0f, 0x43, 0x4f, 0x4e, 0x54, - 0x41, 0x49, 0x4e, 0x45, 0x52, 0x5f, 0x49, 0x4d, 0x41, 0x47, 0x45, 0x10, 0x01, 0x12, 0x0d, 0x0a, - 0x09, 0x53, 0x33, 0x5f, 0x4f, 0x42, 0x4a, 0x45, 0x43, 0x54, 0x10, 0x02, 0x12, 0x0e, 0x0a, 0x0a, - 0x47, 0x49, 0x54, 0x5f, 0x53, 0x4f, 0x55, 0x52, 0x43, 0x45, 0x10, 0x03, 0x12, 0x14, 0x0a, 0x10, - 0x54, 0x45, 0x52, 0x52, 0x41, 0x46, 0x4f, 0x52, 0x4d, 0x5f, 0x4d, 0x4f, 0x44, 0x55, 0x4c, 0x45, - 0x10, 0x04, 0x2a, 0x53, 0x0a, 0x0f, 0x41, 0x70, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, - 0x6e, 0x4b, 0x69, 0x6e, 0x64, 0x12, 0x0e, 0x0a, 0x0a, 0x4b, 0x55, 0x42, 0x45, 0x52, 0x4e, 0x45, - 0x54, 0x45, 0x53, 0x10, 0x00, 0x12, 0x0d, 0x0a, 0x09, 0x54, 0x45, 0x52, 0x52, 0x41, 0x46, 0x4f, - 0x52, 0x4d, 0x10, 0x01, 0x12, 0x0a, 0x0a, 0x06, 0x4c, 0x41, 0x4d, 0x42, 0x44, 0x41, 0x10, 0x03, - 0x12, 0x0c, 0x0a, 0x08, 0x43, 0x4c, 0x4f, 0x55, 0x44, 0x52, 0x55, 0x4e, 0x10, 0x04, 0x12, 0x07, - 0x0a, 0x03, 0x45, 0x43, 0x53, 0x10, 0x05, 0x2a, 0x41, 0x0a, 0x17, 0x41, 0x70, 0x70, 0x6c, 0x69, - 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x41, 0x63, 0x74, 0x69, 0x76, 0x65, 0x53, 0x74, 0x61, 0x74, - 0x75, 0x73, 0x12, 0x0b, 0x0a, 0x07, 0x45, 0x4e, 0x41, 0x42, 0x4c, 0x45, 0x44, 0x10, 0x00, 0x12, - 0x0c, 0x0a, 0x08, 0x44, 0x49, 0x53, 0x41, 0x42, 0x4c, 0x45, 0x44, 0x10, 0x01, 0x12, 0x0b, 0x0a, - 0x07, 0x44, 0x45, 0x4c, 0x45, 0x54, 0x45, 0x44, 0x10, 0x02, 0x2a, 0x36, 0x0a, 0x0c, 0x53, 0x79, - 0x6e, 0x63, 0x53, 0x74, 0x72, 0x61, 0x74, 0x65, 0x67, 0x79, 0x12, 0x08, 0x0a, 0x04, 0x41, 0x55, - 0x54, 0x4f, 0x10, 0x00, 0x12, 0x0e, 0x0a, 0x0a, 0x51, 0x55, 0x49, 0x43, 0x4b, 0x5f, 0x53, 0x59, - 0x4e, 0x43, 0x10, 0x01, 0x12, 0x0c, 0x0a, 0x08, 0x50, 0x49, 0x50, 0x45, 0x4c, 0x49, 0x4e, 0x45, - 0x10, 0x02, 0x42, 0x25, 0x5a, 0x23, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, - 0x2f, 0x70, 0x69, 0x70, 0x65, 0x2d, 0x63, 0x64, 0x2f, 0x70, 0x69, 0x70, 0x65, 0x63, 0x64, 0x2f, - 0x70, 0x6b, 0x67, 0x2f, 0x6d, 0x6f, 0x64, 0x65, 0x6c, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, - 0x33, + 0x01, 0x02, 0x10, 0x01, 0x52, 0x04, 0x6b, 0x69, 0x6e, 0x64, 0x12, 0x18, 0x0a, 0x07, 0x76, 0x65, + 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x76, 0x65, 0x72, + 0x73, 0x69, 0x6f, 0x6e, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x03, 0x20, 0x01, + 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x10, 0x0a, 0x03, 0x75, 0x72, 0x6c, 0x18, + 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x75, 0x72, 0x6c, 0x22, 0x5d, 0x0a, 0x04, 0x4b, 0x69, + 0x6e, 0x64, 0x12, 0x0b, 0x0a, 0x07, 0x55, 0x4e, 0x4b, 0x4e, 0x4f, 0x57, 0x4e, 0x10, 0x00, 0x12, + 0x13, 0x0a, 0x0f, 0x43, 0x4f, 0x4e, 0x54, 0x41, 0x49, 0x4e, 0x45, 0x52, 0x5f, 0x49, 0x4d, 0x41, + 0x47, 0x45, 0x10, 0x01, 0x12, 0x0d, 0x0a, 0x09, 0x53, 0x33, 0x5f, 0x4f, 0x42, 0x4a, 0x45, 0x43, + 0x54, 0x10, 0x02, 0x12, 0x0e, 0x0a, 0x0a, 0x47, 0x49, 0x54, 0x5f, 0x53, 0x4f, 0x55, 0x52, 0x43, + 0x45, 0x10, 0x03, 0x12, 0x14, 0x0a, 0x10, 0x54, 0x45, 0x52, 0x52, 0x41, 0x46, 0x4f, 0x52, 0x4d, + 0x5f, 0x4d, 0x4f, 0x44, 0x55, 0x4c, 0x45, 0x10, 0x04, 0x2a, 0x53, 0x0a, 0x0f, 0x41, 0x70, 0x70, + 0x6c, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x4b, 0x69, 0x6e, 0x64, 0x12, 0x0e, 0x0a, 0x0a, + 0x4b, 0x55, 0x42, 0x45, 0x52, 0x4e, 0x45, 0x54, 0x45, 0x53, 0x10, 0x00, 0x12, 0x0d, 0x0a, 0x09, + 0x54, 0x45, 0x52, 0x52, 0x41, 0x46, 0x4f, 0x52, 0x4d, 0x10, 0x01, 0x12, 0x0a, 0x0a, 0x06, 0x4c, + 0x41, 0x4d, 0x42, 0x44, 0x41, 0x10, 0x03, 0x12, 0x0c, 0x0a, 0x08, 0x43, 0x4c, 0x4f, 0x55, 0x44, + 0x52, 0x55, 0x4e, 0x10, 0x04, 0x12, 0x07, 0x0a, 0x03, 0x45, 0x43, 0x53, 0x10, 0x05, 0x2a, 0x41, + 0x0a, 0x17, 0x41, 0x70, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x41, 0x63, 0x74, + 0x69, 0x76, 0x65, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x12, 0x0b, 0x0a, 0x07, 0x45, 0x4e, 0x41, + 0x42, 0x4c, 0x45, 0x44, 0x10, 0x00, 0x12, 0x0c, 0x0a, 0x08, 0x44, 0x49, 0x53, 0x41, 0x42, 0x4c, + 0x45, 0x44, 0x10, 0x01, 0x12, 0x0b, 0x0a, 0x07, 0x44, 0x45, 0x4c, 0x45, 0x54, 0x45, 0x44, 0x10, + 0x02, 0x2a, 0x36, 0x0a, 0x0c, 0x53, 0x79, 0x6e, 0x63, 0x53, 0x74, 0x72, 0x61, 0x74, 0x65, 0x67, + 0x79, 0x12, 0x08, 0x0a, 0x04, 0x41, 0x55, 0x54, 0x4f, 0x10, 0x00, 0x12, 0x0e, 0x0a, 0x0a, 0x51, + 0x55, 0x49, 0x43, 0x4b, 0x5f, 0x53, 0x59, 0x4e, 0x43, 0x10, 0x01, 0x12, 0x0c, 0x0a, 0x08, 0x50, + 0x49, 0x50, 0x45, 0x4c, 0x49, 0x4e, 0x45, 0x10, 0x02, 0x42, 0x25, 0x5a, 0x23, 0x67, 0x69, 0x74, + 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x70, 0x69, 0x70, 0x65, 0x2d, 0x63, 0x64, 0x2f, + 0x70, 0x69, 0x70, 0x65, 0x63, 0x64, 0x2f, 0x70, 0x6b, 0x67, 0x2f, 0x6d, 0x6f, 0x64, 0x65, 0x6c, + 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( diff --git a/pkg/model/common.pb.validate.go b/pkg/model/common.pb.validate.go index 0d70e418c2..0a48f6ceb5 100644 --- a/pkg/model/common.pb.validate.go +++ b/pkg/model/common.pb.validate.go @@ -513,16 +513,7 @@ func (m *ArtifactVersion) validate(all bool) error { errors = append(errors, err) } - if utf8.RuneCountInString(m.GetVersion()) < 1 { - err := ArtifactVersionValidationError{ - field: "Version", - reason: "value length must be at least 1 runes", - } - if !all { - return err - } - errors = append(errors, err) - } + // no validation rules for Version // no validation rules for Name diff --git a/pkg/model/common.proto b/pkg/model/common.proto index a1712adde7..6f1f88ca33 100644 --- a/pkg/model/common.proto +++ b/pkg/model/common.proto @@ -85,7 +85,7 @@ message ArtifactVersion { } Kind kind = 1 [(validate.rules).enum.defined_only = true]; - string version = 2 [(validate.rules).string.min_len = 1]; + string version = 2; string name = 3; string url = 4; }