Skip to content

Commit

Permalink
Merge pull request #297 from duplocloud/release/0.9.43
Browse files Browse the repository at this point in the history
Release v0.9.43
  • Loading branch information
tahir-duplo authored Sep 6, 2023
2 parents be53416 + 7c12d8a commit 4a79f83
Show file tree
Hide file tree
Showing 15 changed files with 153 additions and 59 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ NAMESPACE=duplocloud

NAME=duplocloud
BINARY=terraform-provider-${NAME}
VERSION=0.9.42
VERSION=0.9.43
#mac
#OS_ARCH=darwin_amd64
#OS_ARCH=linux_amd64
Expand Down
1 change: 1 addition & 0 deletions docs/resources/aws_lambda_function.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ resource "duplocloud_aws_lambda_function" "myfunction" {

- **description** (String) A description of the lambda function.
- **environment** (Block List, Max: 1) Allow customization of the lambda execution environment. (see [below for nested schema](#nestedblock--environment))
- **ephemeral_storage** (Number) The Ephemeral Storage size, in MB, that your lambda function is allowed to use at runtime.
- **handler** (String) The [entrypoint](https://docs.aws.amazon.com/lambda/latest/dg/walkthrough-custom-events-create-test-function.html) of the lambda function in your code.
- **image_uri** (String) The docker image that holds the lambda function's code. Used (and required) only when `package_type` is `"Image"`.
- **layers** (List of String) List of Lambda Layer Version ARNs (maximum of 5) to attach to your Lambda Function.
Expand Down
31 changes: 25 additions & 6 deletions duplocloud/resource_duplo_aws_lambda_function.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,13 @@ func awsLambdaFunctionSchema() map[string]*schema.Schema {
MaxItems: 5,
Elem: &schema.Schema{Type: schema.TypeString},
},
"ephemeral_storage": {
Description: "The Ephemeral Storage size, in MB, that your lambda function is allowed to use at runtime.",
Type: schema.TypeInt,
Optional: true,
Computed: true,
ValidateFunc: validation.IntBetween(512, 10240),
},
}
}

Expand Down Expand Up @@ -260,11 +267,12 @@ func resourceAwsLambdaFunctionCreate(ctx context.Context, d *schema.ResourceData
PackageType: &duplosdk.DuploStringValue{
Value: getPackageType(d),
},
Description: d.Get("description").(string),
Timeout: d.Get("timeout").(int),
MemorySize: d.Get("memory_size").(int),
Code: duplosdk.DuploLambdaCode{}, // initial assumption
Tags: expandAwsLambdaTags(d),
Description: d.Get("description").(string),
Timeout: d.Get("timeout").(int),
MemorySize: d.Get("memory_size").(int),
Code: duplosdk.DuploLambdaCode{}, // initial assumption
Tags: expandAwsLambdaTags(d),
EphemeralStorage: &duplosdk.DuploLambdaEphemeralStorage{},
}
if v, ok := getAsStringArray(d, "layers"); ok && v != nil {
rq.Layers = v
Expand Down Expand Up @@ -295,6 +303,9 @@ func resourceAwsLambdaFunctionCreate(ctx context.Context, d *schema.ResourceData
}
rq.Environment = expandAwsLambdaEnvironment(environment)

if v, ok := d.GetOk("ephemeral_storage"); ok && v != nil && v.(int) != 0 {
rq.EphemeralStorage = &duplosdk.DuploLambdaEphemeralStorage{Size: v.(int)}
}
c := m.(*duplosdk.Client)

// Post the object to Duplo
Expand Down Expand Up @@ -411,6 +422,9 @@ func flattenAwsLambdaConfiguration(d *schema.ResourceData, duplo *duplosdk.Duplo
d.Set("handler", duplo.Handler)
d.Set("version", duplo.Version)
d.Set("layers", duplo.Layers)
if duplo.EphemeralStorage != nil {
d.Set("ephemeral_storage", duplo.EphemeralStorage.Size)
}
if duplo.Runtime != nil {
d.Set("runtime", duplo.Runtime.Value)
}
Expand Down Expand Up @@ -497,6 +511,10 @@ func updateAwsLambdaFunctionConfig(tenantID, name string, d *schema.ResourceData
}
}

if v, ok := d.GetOk("ephemeral_storage"); ok && v != nil && v.(int) != 0 {
rq.EphemeralStorage = &duplosdk.DuploLambdaEphemeralStorage{Size: v.(int)}
}

if v, ok := d.GetOk("tracing_config"); ok && len(v.([]interface{})) > 0 && v.([]interface{})[0] != nil {
rq.TracingConfig = &duplosdk.DuploLambdaTracingConfig{
Mode: duplosdk.DuploStringValue{Value: v.([]interface{})[0].(map[string]interface{})["mode"].(string)},
Expand Down Expand Up @@ -559,6 +577,7 @@ func needsAwsLambdaFunctionConfigUpdate(d *schema.ResourceData) bool {
d.HasChange("memory_size") ||
d.HasChange("environment") ||
d.HasChange("tags") ||
d.HasChange("layers") ||
d.HasChange("tracing_config") ||
d.HasChange("layers")
d.HasChange("ephemeral_storage")
}
92 changes: 50 additions & 42 deletions duplosdk/aws_lambda_function.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,23 +30,24 @@ type DuploLambdaConfiguration struct {
// NOTE: The Name field does not come from the backend - we synthesize it
Name string `json:"Name"`

CodeSha256 string `json:"CodeSha256"`
CodeSize int `json:"CodeSize"`
Description string `json:"Description,omitempty"`
Environment *DuploLambdaEnvironment `json:"Environment,omitempty"`
FunctionArn string `json:"FunctionArn,omitempty"`
FunctionName string `json:"FunctionName,omitempty"`
Handler string `json:"Handler,omitempty"`
LastModified string `json:"LastModified,omitempty"`
MemorySize int `json:"MemorySize"`
Role string `json:"Role,omitempty"`
PackageType *DuploStringValue `json:"PackageType,omitempty"`
Runtime *DuploStringValue `json:"Runtime,omitempty"`
Timeout int `json:"Timeout,omitempty"`
TracingConfig *DuploLambdaTracingConfig `json:"TracingConfig,omitempty"`
Version string `json:"Version,omitempty"`
VpcConfig *DuploLambdaVpcConfig `json:"VpcConfig,omitempty"`
Layers *[]DuploLambdaLayerGet `json:"Layers,omitempty"`
CodeSha256 string `json:"CodeSha256"`
CodeSize int `json:"CodeSize"`
Description string `json:"Description,omitempty"`
Environment *DuploLambdaEnvironment `json:"Environment,omitempty"`
FunctionArn string `json:"FunctionArn,omitempty"`
FunctionName string `json:"FunctionName,omitempty"`
Handler string `json:"Handler,omitempty"`
LastModified string `json:"LastModified,omitempty"`
MemorySize int `json:"MemorySize"`
Role string `json:"Role,omitempty"`
PackageType *DuploStringValue `json:"PackageType,omitempty"`
Runtime *DuploStringValue `json:"Runtime,omitempty"`
Timeout int `json:"Timeout,omitempty"`
TracingConfig *DuploLambdaTracingConfig `json:"TracingConfig,omitempty"`
Version string `json:"Version,omitempty"`
VpcConfig *DuploLambdaVpcConfig `json:"VpcConfig,omitempty"`
Layers *[]DuploLambdaLayerGet `json:"Layers,omitempty"`
EphemeralStorage *DuploLambdaEphemeralStorage `json:"EphemeralStorage,omitempty"`
}

// DuploLambdaCode is a Duplo SDK object that represents a lambda function's code.
Expand All @@ -56,17 +57,22 @@ type DuploLambdaCode struct {
S3Key string `json:"S3Key,omitempty"`
}

// DuploLambdaEnvironment is a Duplo SDK object that represents a lambda function's tracing config.
// DuploLambdaEnvironment is a Duplo SDK object that represents a lambda function's environment config.
type DuploLambdaEnvironment struct {
Variables map[string]string `json:"Variables,omitempty"`
}

// DuploLambdaEphemeralStorage is a Duplo SDK object that represents a lambda function's ephemeral storage config.
type DuploLambdaEphemeralStorage struct {
Size int `json:"Size"`
}

// DuploLambdaTracingConfig is a Duplo SDK object that represents a lambda function's tracing config.
type DuploLambdaTracingConfig struct {
Mode DuploStringValue `json:"Mode,omitempty"`
}

// DuploLambdaVpcConfig is a Duplo SDK object that represents a lambda function's tracing config.
// DuploLambdaVpcConfig is a Duplo SDK object that represents a lambda function's vpn config.
type DuploLambdaVpcConfig struct {
SecurityGroupIDs []string `json:"SecurityGroupIds,omitempty"`
SubnetIDs []string `json:"SubnetIds,omitempty"`
Expand All @@ -75,18 +81,19 @@ type DuploLambdaVpcConfig struct {

// DuploLambdaCreateRequest is a Duplo SDK object that represents a request to create a lambda function.
type DuploLambdaCreateRequest struct {
FunctionName string `json:"FunctionName"`
Code DuploLambdaCode `json:"Code"`
Handler string `json:"Handler,omitempty"`
Description string `json:"Description,omitempty"`
Timeout int `json:"Timeout,omitempty"`
MemorySize int `json:"MemorySize"`
PackageType *DuploStringValue `json:"PackageType,omitempty"`
Runtime *DuploStringValue `json:"Runtime,omitempty"`
Environment *DuploLambdaEnvironment `json:"Environment,omitempty"`
Tags map[string]string `json:"Tags,omitempty"`
Layers *[]string `json:"Layers,omitempty"`
TracingConfig *DuploLambdaTracingConfig `json:"TracingConfig,omitempty"`
FunctionName string `json:"FunctionName"`
Code DuploLambdaCode `json:"Code"`
Handler string `json:"Handler,omitempty"`
Description string `json:"Description,omitempty"`
Timeout int `json:"Timeout,omitempty"`
MemorySize int `json:"MemorySize"`
EphemeralStorage *DuploLambdaEphemeralStorage `json:"EphemeralStorage,omitempty"`
PackageType *DuploStringValue `json:"PackageType,omitempty"`
Runtime *DuploStringValue `json:"Runtime,omitempty"`
Environment *DuploLambdaEnvironment `json:"Environment,omitempty"`
Tags map[string]string `json:"Tags,omitempty"`
Layers *[]string `json:"Layers,omitempty"`
TracingConfig *DuploLambdaTracingConfig `json:"TracingConfig,omitempty"`
}

// DuploLambdaUpdateRequest is a Duplo SDK object that represents a request to update a lambda function's code.
Expand All @@ -99,16 +106,17 @@ type DuploLambdaUpdateRequest struct {

// DuploLambdaConfigurationRequest is a Duplo SDK object that represents a request to update a lambda function's configuration.
type DuploLambdaConfigurationRequest struct {
FunctionName string `json:"FunctionName,omitempty"`
Handler string `json:"Handler,omitempty"`
Runtime *DuploStringValue `json:"Runtime,omitempty"`
Description string `json:"Description,omitempty"`
Timeout int `json:"Timeout,omitempty"`
MemorySize int `json:"MemorySize"`
Environment *DuploLambdaEnvironment `json:"Environment,omitempty"`
Tags map[string]string `json:"Tags,omitempty"`
Layers *[]string `json:"Layers,omitempty"`
TracingConfig *DuploLambdaTracingConfig `json:"TracingConfig,omitempty"`
FunctionName string `json:"FunctionName,omitempty"`
Handler string `json:"Handler,omitempty"`
Runtime *DuploStringValue `json:"Runtime,omitempty"`
Description string `json:"Description,omitempty"`
Timeout int `json:"Timeout,omitempty"`
MemorySize int `json:"MemorySize"`
Environment *DuploLambdaEnvironment `json:"Environment,omitempty"`
EphemeralStorage *DuploLambdaEphemeralStorage `json:"EphemeralStorage,omitempty"`
Tags map[string]string `json:"Tags,omitempty"`
Layers *[]string `json:"Layers,omitempty"`
TracingConfig *DuploLambdaTracingConfig `json:"TracingConfig,omitempty"`
}

type DuploLambdaPermissionStatement struct {
Expand Down Expand Up @@ -167,7 +175,7 @@ func (c *Client) LambdaFunctionUpdate(tenantID string, rq *DuploLambdaUpdateRequ
// LambdaFunctionUpdateConfiguration updates a lambda function's configuration via the Duplo API.
func (c *Client) LambdaFunctionUpdateConfiguration(tenantID string, rq *DuploLambdaConfigurationRequest) ClientError {
return c.postAPI(
fmt.Sprintf("LambdaFunctionUpdateConfigurationg(%s, %s)", tenantID, rq.FunctionName),
fmt.Sprintf("LambdaFunctionUpdateConfiguration(%s, %s)", tenantID, rq.FunctionName),
fmt.Sprintf("subscriptions/%s/UpdateLambdaFunctionConfiguration", tenantID),
&rq,
nil,
Expand Down
2 changes: 1 addition & 1 deletion duplosdk/infrastructure.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ func (c *Client) InfrastructureGet(name string) (*DuploInfrastructureConfig, Cli
// InfrastructureGetConfig retrieves extended infrastructure configuration by name via the Duplo API.
func (c *Client) InfrastructureGetConfig(name string) (*DuploInfrastructureConfig, ClientError) {
rp := DuploInfrastructureConfig{}
err := c.getAPI(fmt.Sprintf("InfrastructureGetConfig(%s)", name), fmt.Sprintf("v3/admin/infrastructure/%s", name), &rp)
err := c.getAPI(fmt.Sprintf("InfrastructureGetConfig(%s)", name), fmt.Sprintf("adminproxy/GetInfrastructureConfig/%s", name), &rp)
if err != nil || rp.Name == "" {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion examples/aws-integration/main.tf
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
terraform {
required_providers {
duplocloud = {
version = "0.9.42" # RELEASE VERSION
version = "0.9.43" # RELEASE VERSION
source = "registry.terraform.io/duplocloud/duplocloud"
}
aws = {
Expand Down
2 changes: 1 addition & 1 deletion examples/ecs/main.tf
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
terraform {
required_providers {
duplocloud = {
version = "0.9.42" # RELEASE VERSION
version = "0.9.43" # RELEASE VERSION
source = "registry.terraform.io/duplocloud/duplocloud"
}
}
Expand Down
2 changes: 1 addition & 1 deletion examples/eks-integration/main.tf
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
terraform {
required_providers {
duplocloud = {
version = "0.9.42" # RELEASE VERSION
version = "0.9.43" # RELEASE VERSION
source = "registry.terraform.io/duplocloud/duplocloud"
}
aws = {
Expand Down
2 changes: 1 addition & 1 deletion examples/emr/files/emr_auto_scaling/main.tf
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
terraform {
required_providers {
duplocloud = {
version = "0.9.42" # RELEASE VERSION
version = "0.9.43" # RELEASE VERSION
source = "registry.terraform.io/duplocloud/duplocloud"
}
}
Expand Down
2 changes: 1 addition & 1 deletion examples/emr/files/emr_spot/main.tf
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
terraform {
required_providers {
duplocloud = {
version = "0.9.42" # RELEASE VERSION
version = "0.9.43" # RELEASE VERSION
source = "registry.terraform.io/duplocloud/duplocloud"
}
}
Expand Down
2 changes: 1 addition & 1 deletion examples/emr/main.tf
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
terraform {
required_providers {
duplocloud = {
version = "0.9.42" # RELEASE VERSION
version = "0.9.43" # RELEASE VERSION
source = "registry.terraform.io/duplocloud/duplocloud"
}
}
Expand Down
66 changes: 66 additions & 0 deletions examples/ephemeral-storage/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
terraform {
required_providers {
duplocloud = {
version = "0.9.43" # RELEASE VERSION
source = "registry.terraform.io/duplocloud/duplocloud"
}
}
}

provider "duplocloud" {
duplo_host = "https://xxx.duplocloud.net" # you can also set the duplo_host env var
duplo_token = "..." # please *ONLY* specify using a duplo_token env var (avoid checking secrets into git)
}

variable "tenant_id" {
type = string
}

# # EKS credentials retrieval
# data "duplocloud_eks_credentials" "test" { plan_id = var.plan_id }
# output "eks_creds_name" { value = data.duplocloud_eks_credentials.test.name }
# output "eks_creds_endpoint" { value = data.duplocloud_eks_credentials.test.endpoint }
# output "eks_creds_region" { value = data.duplocloud_eks_credentials.test.region }

# # AWS credentials retrieval
# data "duplocloud_tenant_aws_credentials" "test" { tenant_id = var.tenant_id }
# output "aws_creds_region" { value = data.duplocloud_tenant_aws_credentials.test.region }

# # AWS account ID retrieval
# data "duplocloud_aws_account" "test" {}
# output "aws_account_id" { value = data.duplocloud_aws_account.test.account_id }

# # AWS region retrieval
# data "duplocloud_tenant_aws_region" "test" { tenant_id = var.tenant_id }
# output "aws_region" { value = data.duplocloud_tenant_aws_region.test.aws_region }

# # Tenant secrets retrieval
# data "duplocloud_tenant_secrets" "test" { tenant_id = var.tenant_id }
# output "tenant_secrets" { value = data.duplocloud_tenant_secrets.test.secrets }

# Tenant information
data "duplocloud_tenant" "test" { name = "default" }
output "tenant" { value = data.duplocloud_tenant.test }

# Tenant listing
data "duplocloud_tenants" "test" {}
output "tenants" { value = data.duplocloud_tenants.test.tenants.*.name }

resource "duplocloud_s3_bucket" "s3bucket" {
tenant_id = var.tenant_id
name = "miketest"
}

resource "duplocloud_aws_lambda_function" "test" {
tenant_id = var.tenant_id
name = "miketest"
package_type = "Zip"
description = "miketest lambda"
s3_bucket = duplocloud_s3_bucket.s3bucket.fullname
s3_key = "file.zip"
memory_size = 128
runtime = "python3.9"
handler = "main"
ephemeral_storage = 1024
}

2 changes: 1 addition & 1 deletion examples/infrastructure/main.tf
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
terraform {
required_providers {
duplocloud = {
version = "0.9.42" # RELEASE VERSION
version = "0.9.43" # RELEASE VERSION
source = "registry.terraform.io/duplocloud/duplocloud"
}
}
Expand Down
2 changes: 1 addition & 1 deletion examples/k8/main.tf
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
terraform {
required_providers {
duplocloud = {
version = "0.9.42" # RELEASE VERSION
version = "0.9.43" # RELEASE VERSION
source = "registry.terraform.io/duplocloud/duplocloud"
}
}
Expand Down
2 changes: 1 addition & 1 deletion examples/service/main.tf
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
terraform {
required_providers {
duplocloud = {
version = "0.9.42" # RELEASE VERSION
version = "0.9.43" # RELEASE VERSION
source = "registry.terraform.io/duplocloud/duplocloud"
}
}
Expand Down

0 comments on commit 4a79f83

Please sign in to comment.