Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ require (
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/monitor v1.0.199
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/postgres v1.0.199
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/redis v1.0.199
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/scf v1.0.199
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/scf v1.0.267
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/sqlserver v1.0.199
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/ssl v1.0.199
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/ssm v1.0.199
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,8 @@ github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/redis v1.0.199 h1:lXCng
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/redis v1.0.199/go.mod h1:5bwboqeXqVnRvUlKn2G9Y9DbOnWMSVQ0zWhhPZKUVZE=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/scf v1.0.199 h1:vvxCCj6RiRM4FkSdxncroAx9JGD6xBBhAnXugQrE3j8=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/scf v1.0.199/go.mod h1:Pew6DV5oBGrzHYWZ8ssiHeJS/Z39ggVv1y5ADGWdO4s=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/scf v1.0.267 h1:ipvvQOzGyUUGohsVLElJnDDZn4Xoq1axk8my+GLyRYs=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/scf v1.0.267/go.mod h1:Pew6DV5oBGrzHYWZ8ssiHeJS/Z39ggVv1y5ADGWdO4s=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/sqlserver v1.0.199 h1:Ms62XLYCuqrdG4mD5S72oj/ZxdNTxJ+Mc4w0Kxqucwo=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/sqlserver v1.0.199/go.mod h1:ySz4zbciCFruAviNMeBcu7wW2+BY9Maw8qGWawTywkM=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/ssl v1.0.199 h1:UkF3qBxMbpOf2VjxgzMgqvBCS+Hqr8XXSrtRd+rABMk=
Expand Down
111 changes: 106 additions & 5 deletions tencentcloud/resource_tc_scf_function.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,31 +207,75 @@ func resourceTencentCloudScfFunction() *schema.Resource {
"cos_bucket_name": {
Type: schema.TypeString,
Optional: true,
ConflictsWith: []string{"zip_file"},
ConflictsWith: []string{"zip_file", "image_config"},
Description: "Cos bucket name of the SCF function, such as `cos-1234567890`, conflict with `zip_file`.",
},
"cos_object_name": {
Type: schema.TypeString,
Optional: true,
ConflictsWith: []string{"zip_file"},
ConflictsWith: []string{"zip_file", "image_config"},
ValidateFunc: validateStringSuffix(".zip", ".jar"),
Description: "Cos object name of the SCF function, should have suffix `.zip` or `.jar`, conflict with `zip_file`.",
},
"cos_bucket_region": {
Type: schema.TypeString,
Optional: true,
ConflictsWith: []string{"zip_file"},
ConflictsWith: []string{"zip_file", "image_config"},
Description: "Cos bucket region of the SCF function, conflict with `zip_file`.",
},

// zip upload
"zip_file": {
Type: schema.TypeString,
Optional: true,
ConflictsWith: []string{"cos_bucket_name", "cos_object_name", "cos_bucket_region"},
ConflictsWith: []string{"cos_bucket_name", "cos_object_name", "cos_bucket_region", "image_config"},
Description: "Zip file of the SCF function, conflict with `cos_bucket_name`, `cos_object_name`, `cos_bucket_region`.",
},

// image
"image_config": {
Type: schema.TypeList,
Optional: true,
ConflictsWith: []string{"cos_bucket_name", "cos_object_name", "cos_bucket_region", "zip_file"},
Description: "Image of the SCF function, conflict with ``.",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"image_type": {
Type: schema.TypeString,
Required: true,
ValidateFunc: validateAllowedStringValue([]string{"personal", "enterprise"}),
Description: "The image type. personal or enterprise.",
},
"image_uri": {
Type: schema.TypeString,
Required: true,
Description: "The uri of image.",
},
"registry_id": {
Type: schema.TypeString,
Optional: true,
Description: "The registry id of TCR. When image type is enterprise, it must be set.",
},
"entry_point": {
Type: schema.TypeString,
Optional: true,
Description: "The entrypoint of app.",
},
"command": {
Type: schema.TypeString,
Optional: true,
Description: "The command of entrypoint.",
},
"args": {
Type: schema.TypeString,
Optional: true,
Description: "the parameters of command.",
},

},
},
},

"triggers": {
Type: schema.TypeSet,
Optional: true,
Expand Down Expand Up @@ -423,6 +467,7 @@ func resourceTencentCloudScfFunctionCreate(d *schema.ResourceData, m interface{}
const (
scfFunctionCosCode scfFunctionCodeType = iota + 1 // start at 1 so we can check if codeType set or not
scfFunctionZipFileCode
scfFunctionImageCode
)

var codeType scfFunctionCodeType
Expand Down Expand Up @@ -496,14 +541,42 @@ func resourceTencentCloudScfFunctionCreate(d *schema.ResourceData, m interface{}
functionInfo.zipFile = &content
}

var imageConfigs = make([]*scf.ImageConfig, 0)

if raw, ok := d.GetOk("image_config"); ok {
configs := raw.([]interface{})
for _, v := range configs {
value := v.(map[string]interface{})
imageType := value["image_type"].(string)
imageUri := value["image_uri"].(string)
registryId := value["registry_id"].(string)
entryPoint := value["entry_point"].(string)
command := value["command"].(string)
args := value["args"].(string)

config := &scf.ImageConfig{
ImageType : &imageType,
ImageUri: &imageUri,
RegistryId: &registryId,
EntryPoint: &entryPoint,
Command: &command,
Args: &args,
}
imageConfigs = append(imageConfigs, config)
}
codeType = scfFunctionImageCode
}

functionInfo.imageConfig = imageConfigs[0]

switch codeType {
case scfFunctionCosCode:
if err := helper.CheckIfSetTogether(d, "cos_bucket_name", "cos_object_name", "cos_bucket_region"); err != nil {
return err
}

case scfFunctionZipFileCode:

case scfFunctionImageCode:
default:
return errors.New("no function code set")
}
Expand Down Expand Up @@ -764,6 +837,34 @@ func resourceTencentCloudScfFunctionUpdate(d *schema.ResourceData, m interface{}
functionInfo.zipFile = &content
}

if d.HasChange("image_config") {
updateAttrs = append(updateAttrs, "image_config")
if raw, ok := d.GetOk("image_config"); ok {
var imageConfigs = make([]*scf.ImageConfig, 0)
configs := raw.([]interface{})
for _, v := range configs {
value := v.(map[string]interface{})
imageType := value["image_type"].(string)
imageUri := value["image_uri"].(string)
registryId := value["registry_id"].(string)
entryPoint := value["entry_point"].(string)
command := value["command"].(string)
args := value["args"].(string)

config := &scf.ImageConfig{
ImageType : &imageType,
ImageUri: &imageUri,
RegistryId: &registryId,
EntryPoint: &entryPoint,
Command: &command,
Args: &args,
}
imageConfigs = append(imageConfigs, config)
}
functionInfo.imageConfig = imageConfigs[0]
}
}

// update function code
if len(updateAttrs) > 0 {
if len(updateAttrs) == 0 && updateAttrs[0] == "handler" {
Expand Down
4 changes: 4 additions & 0 deletions tencentcloud/service_tencentcloud_scf.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ type scfFunctionInfo struct {
cosBucketRegion *string

zipFile *string

imageConfig *scf.ImageConfig
}

type scfTrigger struct {
Expand Down Expand Up @@ -86,6 +88,7 @@ func (me *ScfService) CreateFunction(ctx context.Context, info scfFunctionInfo)
CosObjectName: info.cosObjectName,
CosBucketRegion: info.cosBucketRegion,
ZipFile: info.zipFile,
ImageConfig: info.imageConfig,
}

if err := resource.Retry(writeRetryTimeout, func() *resource.RetryError {
Expand Down Expand Up @@ -194,6 +197,7 @@ func (me *ScfService) ModifyFunctionCode(ctx context.Context, info scfFunctionIn
CosObjectName: info.cosObjectName,
CosBucketRegion: info.cosBucketRegion,
ZipFile: info.zipFile,
ImageConfig: info.imageConfig,
}

if err := resource.Retry(writeRetryTimeout, func() *resource.RetryError {
Expand Down
Loading