Skip to content

Commit ee2279e

Browse files
Jaytee-fnSrividyaKamakshi
authored andcommitted
Added - Support for New API header property to support Dry Run of Function Invocation
1 parent a50ec09 commit ee2279e

File tree

5 files changed

+33
-38
lines changed

5 files changed

+33
-38
lines changed

examples/functions/main.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ resource "oci_functions_function" "test_function" {
103103
trace_config {
104104
is_enabled = var.function_trace_config.is_enabled
105105
}
106+
is_dry_run = var.dry_run
106107

107108
provisioned_concurrency_config {
108109
strategy = "CONSTANT"

examples/functions/variables.tf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,10 @@ variable "function_image" {
6969
variable "function_image_digest" {
7070
}
7171

72+
variable "dry_run" {
73+
default = "false"
74+
}
75+
7276
variable "function_trace_config" {
7377
type = object({
7478
is_enabled = bool

internal/integrationtest/functions_invoke_function_test.go

Lines changed: 14 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ var (
3333
"function_id": acctest.Representation{RepType: acctest.Required, Create: `${oci_functions_function.test_function.id}`},
3434
"invoke_function_body": acctest.Representation{RepType: acctest.Optional, Create: `{\"name\":\"Bob\"}`},
3535
"fn_intent": acctest.Representation{RepType: acctest.Optional, Create: `httprequest`},
36+
"is_dry_run": acctest.Representation{RepType: acctest.Optional, Create: `false`},
3637
"fn_invoke_type": acctest.Representation{RepType: acctest.Optional, Create: `sync`},
3738
}
3839

@@ -47,38 +48,8 @@ var (
4748
acctest.GenerateResourceFromRepresentationMap("oci_core_internet_gateway", "test_internet_gateway", acctest.Required, acctest.Create, CoreInternetGatewayRepresentation) +
4849
acctest.GenerateResourceFromRepresentationMap("oci_core_vcn", "test_vcn", acctest.Optional, acctest.Create, CoreVcnRepresentation) +
4950
DefinedTagsDependencies +
50-
KeyResourceDependencyConfig +
51-
`
52-
resource "oci_core_security_list" "test_security_list" {
53-
compartment_id = "${var.compartment_id}"
54-
egress_security_rules {
55-
destination = "0.0.0.0/0"
56-
protocol = "6"
57-
}
58-
ingress_security_rules {
59-
protocol = "1"
60-
source = "10.0.1.0/24"
61-
}
62-
vcn_id = "${oci_core_vcn.test_vcn.id}"
63-
}
51+
KeyResourceDependencyConfig
6452

65-
resource "oci_core_subnet" "test_subnet" {
66-
availability_domain = "${lower("${data.oci_identity_availability_domains.test_availability_domains.availability_domains.0.name}")}"
67-
cidr_block = "10.0.0.0/16"
68-
compartment_id = "${var.compartment_id}"
69-
defined_tags = "${map("${oci_identity_tag_namespace.tag-namespace1.name}.${oci_identity_tag.tag1.name}", "updatedValue")}"
70-
dhcp_options_id = "${oci_core_dhcp_options.test_dhcp_options.id}"
71-
display_name = "tf-subnet"
72-
dns_label = "dnslabel"
73-
freeform_tags = {
74-
"Department" = "Accounting"
75-
}
76-
prohibit_public_ip_on_vnic = "false"
77-
route_table_id = "${oci_core_route_table.test_route_table.id}"
78-
security_list_ids = ["${oci_core_security_list.test_security_list.id}"]
79-
vcn_id = "${oci_core_vcn.test_vcn.id}"
80-
}
81-
`
8253
sourceFile *os.File
8354
)
8455

@@ -103,7 +74,6 @@ func createTmpSourceFile() (string, error) {
10374

10475
// issue-routing-tag: functions/default
10576
func TestFunctionsInvokeFunctionResource_basic(t *testing.T) {
106-
t.Skip("Skipping test until functions support async life cycle state transitions.")
10777

10878
if httpreplay.ModeRecordReplay() {
10979
t.Skip("Skipping TestFunctionsInvokeFunctionResource_basic in HttpReplay mode till json encoding is fixed.")
@@ -143,7 +113,7 @@ func TestFunctionsInvokeFunctionResource_basic(t *testing.T) {
143113
acctest.GenerateResourceFromRepresentationMap("oci_functions_invoke_function", "test_invoke_function", acctest.Required, acctest.Create, FunctionsInvokeFunctionRepresentation),
144114
Check: acctest.ComposeAggregateTestCheckFuncWrapper(
145115
resource.TestCheckResourceAttrSet(resourceName, "function_id"),
146-
resource.TestCheckResourceAttr(resourceName, "content", "{\"message\":\"Hello v3 World\"}\n"),
116+
resource.TestCheckResourceAttr(resourceName, "content", "{\"message\": \"Hello World\"}"),
147117
),
148118
},
149119

@@ -156,7 +126,13 @@ func TestFunctionsInvokeFunctionResource_basic(t *testing.T) {
156126
Config: config + compartmentIdVariableStr + imageVariableStr + imageDigestVariableStr + FunctionsInvokeFunctionResourceDependencies +
157127
acctest.GenerateResourceFromRepresentationMap("oci_functions_invoke_function", "test_invoke_function", acctest.Optional, acctest.Create, FunctionsInvokeFunctionRepresentation),
158128
Check: acctest.ComposeAggregateTestCheckFuncWrapper(
159-
resource.TestCheckResourceAttr(resourceName, "content", "{\"message\":\"Hello v3 Bob\"}\n"),
129+
resource.TestCheckResourceAttr(resourceName, "invoke_function_body", "{\"name\":\"Bob\"}"),
130+
resource.TestCheckResourceAttr(resourceName, "fn_intent", "httprequest"),
131+
resource.TestCheckResourceAttr(resourceName, "fn_invoke_type", "sync"),
132+
resource.TestCheckResourceAttrSet(resourceName, "function_id"),
133+
resource.TestCheckResourceAttr(resourceName, "is_dry_run", "false"),
134+
135+
resource.TestCheckResourceAttr(resourceName, "content", "{\"message\": \"Hello Bob\"}"),
160136
func(s *terraform.State) (err error) {
161137
resId, err = acctest.FromInstanceState(s, resourceName, "id")
162138
if isEnableExportCompartment, _ := strconv.ParseBool(utils.GetEnvSettingWithDefault("enable_export_compartment", "true")); isEnableExportCompartment {
@@ -174,7 +150,7 @@ func TestFunctionsInvokeFunctionResource_basic(t *testing.T) {
174150
acctest.GenerateResourceFromRepresentationMap("oci_functions_invoke_function", "test_invoke_function", acctest.Optional, acctest.Create,
175151
acctest.GetUpdatedRepresentationCopy("fn_intent", acctest.Representation{RepType: acctest.Optional, Create: `cloudevent`}, FunctionsInvokeFunctionRepresentation)),
176152
Check: acctest.ComposeAggregateTestCheckFuncWrapper(
177-
resource.TestCheckResourceAttr(resourceName, "content", "{\"message\":\"Hello v3 Bob\"}\n"),
153+
resource.TestCheckResourceAttr(resourceName, "content", "{\"message\": \"Hello Bob\"}"),
178154
),
179155
},
180156
// verify Create with optionals
@@ -203,7 +179,7 @@ func TestFunctionsInvokeFunctionResource_basic(t *testing.T) {
203179
"input_body_source_path": acctest.Representation{RepType: acctest.Optional, Create: sourceFilePath},
204180
})),
205181
Check: acctest.ComposeAggregateTestCheckFuncWrapper(
206-
resource.TestCheckResourceAttr(resourceName, "content", "{\"message\":\"Hello v3 Bob\"}\n"),
182+
resource.TestCheckResourceAttr(resourceName, "content", "{\"message\": \"Hello Bob\"}"),
207183
),
208184
},
209185
// verify Create with base64 encoded input
@@ -214,7 +190,7 @@ func TestFunctionsInvokeFunctionResource_basic(t *testing.T) {
214190
"invoke_function_body_base64_encoded": acctest.Representation{RepType: acctest.Optional, Create: "eyJuYW1lIjoiQm9iIn0="},
215191
})),
216192
Check: acctest.ComposeAggregateTestCheckFuncWrapper(
217-
resource.TestCheckResourceAttr(resourceName, "content", "{\"message\":\"Hello v3 Bob\"}\n"),
193+
resource.TestCheckResourceAttr(resourceName, "content", "{\"message\": \"Hello Bob\"}"),
218194
),
219195
},
220196
// verify base64 encoded content
@@ -225,7 +201,7 @@ func TestFunctionsInvokeFunctionResource_basic(t *testing.T) {
225201
"base64_encode_content": acctest.Representation{RepType: acctest.Optional, Create: `true`},
226202
})),
227203
Check: acctest.ComposeAggregateTestCheckFuncWrapper(
228-
resource.TestCheckResourceAttr(resourceName, "content", "eyJtZXNzYWdlIjoiSGVsbG8gdjMgQm9iIn0K"),
204+
resource.TestCheckResourceAttr(resourceName, "content", "eyJtZXNzYWdlIjogIkhlbGxvIEJvYiJ9"),
229205
),
230206
},
231207
})

internal/service/functions/functions_invoke_function_resource.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,12 @@ func FunctionsInvokeFunctionResource() *schema.Resource {
6161
Computed: true,
6262
ForceNew: true,
6363
},
64+
"is_dry_run": {
65+
Type: schema.TypeBool,
66+
Optional: true,
67+
Computed: true,
68+
ForceNew: true,
69+
},
6470
"input_body_source_path": {
6571
Type: schema.TypeString,
6672
Optional: true,
@@ -190,6 +196,11 @@ func (s *FunctionsInvokeFunctionResourceCrud) Create() error {
190196
request.FunctionId = &tmp
191197
}
192198

199+
if isDryRun, ok := s.D.GetOkExists("is_dry_run"); ok {
200+
tmp := isDryRun.(bool)
201+
request.IsDryRun = &tmp
202+
}
203+
193204
request.RequestMetadata.RetryPolicy = tfresource.GetRetryPolicy(false, "functions")
194205
if endPoint, ok := s.D.GetOkExists("invoke_endpoint"); !ok {
195206
s.Client.Host = endPoint.(string)

website/docs/r/functions_invoke_function.html.markdown

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ resource "oci_functions_invoke_function" "test_invoke_function" {
2323
invoke_function_body = var.invoke_function_invoke_function_body
2424
fn_intent = var.invoke_function_fn_intent
2525
fn_invoke_type = var.invoke_function_fn_invoke_type
26+
is_dry_run = var.invoke_function_is_dry_run
2627
base64_encode_content = false
2728
}
2829
```
@@ -36,6 +37,8 @@ The following arguments are supported:
3637
* `fn_intent` - (Optional) An optional intent header that indicates to the FDK the way the event should be interpreted. E.g. 'httprequest', 'cloudevent'.
3738
* `fn_invoke_type` - (Optional) Indicates whether Oracle Functions should execute the request and return the result ('sync') of the execution, or whether Oracle Functions should return as soon as processing has begun ('detached') and leave result handling to the function.
3839
* `function_id` - (Required) The [OCID](https://docs.cloud.oracle.com/iaas/Content/General/Concepts/identifiers.htm) of this function.
40+
* `is_dry_run` - (Optional) Indicates that the request is a dry run, if set to "true". A dry run request does not execute the function.
41+
3942
* `invoke_function_body_base64_encoded` - (Optional) The Base64 encoded body of the function invocation. Base64 encoded input avoids corruption in Terraform state. Cannot be defined if `invoke_function_body` or `input_body_source_path` is defined. Note: The maximum size of the request is limited. This limit is currently 6MB and the endpoint will not accept requests that are bigger than this limit.
4043
* `input_body_source_path` - (Optional) An absolute path to a file on the local system that contains the input to be provided to the function. Cannot be defined if `invoke_function_body` or `invoke_function_body_base64_encoded` is defined. Note: The maximum size of the request is limited. This limit is currently 6MB and the endpoint will not accept requests that are bigger than this limit.
4144

0 commit comments

Comments
 (0)