-
Notifications
You must be signed in to change notification settings - Fork 0
/
ef_jira.tf
131 lines (108 loc) · 2.75 KB
/
ef_jira.tf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
resource "snowflake_external_function" "snowalert_jira_api" {
count = contains(var.handlers, "jira") == true ? 1 : 0
provider = snowflake.alerting_role
database = local.snowalert_database_name
schema = local.results_schema
name = "SNOWALERT_JIRA_API"
# Function arguments
arg {
name = "METHOD"
type = "VARCHAR"
}
arg {
name = "PATH"
type = "VARCHAR"
}
arg {
name = "BODY"
type = "VARCHAR"
}
arg {
name = "QUERYSTRING"
type = "VARCHAR"
}
# Function headers
header {
name = "method"
value = "{0}"
}
header {
name = "base-url"
value = var.jira_url
}
header {
name = "url"
value = "{1}"
}
header {
name = "params"
value = "{3}"
}
header {
name = "data"
value = "{2}"
}
header {
name = "headers"
value = "content-type=application%2Fjson&accept=application%2Fjson"
}
header {
name = "auth"
value = var.jira_secrets_arn
}
return_null_allowed = true
return_type = "VARIANT"
return_behavior = "VOLATILE"
api_integration = module.geff_snowalert[0].api_integration_name
url_of_proxy_and_resource = "${module.geff_snowalert[0].api_gateway_invoke_url}${var.env}/https"
comment = <<COMMENT
jira_api: (method, path, body) -> api_response
https://developer.atlassian.com/cloud/jira/platform/rest/v3/
or https://developer.atlassian.com/server/jira/platform/rest-apis/
COMMENT
depends_on = [
module.snowalert_grants
]
}
resource "snowflake_function" "jira_handler" {
count = contains(var.handlers, "jira") == true ? 1 : 0
provider = snowflake.alerting_role
name = "JIRA_HANDLER"
database = local.snowalert_database_name
schema = local.results_schema
# Function arguments
arguments {
name = "ALERT"
type = "VARIANT"
}
arguments {
name = "PAYLOAD"
type = "VARIANT"
}
return_type = "VARIANT"
return_behavior = "IMMUTABLE"
statement = templatefile(
"${path.module}/handler_functions_sql/jira_handler_v${var.jira_api_version}.sql", {
default_jira_project = var.default_jira_project
default_jira_issue_type = var.default_jira_issue_type
jira_api_function = join(".", [
local.snowalert_database_name,
local.results_schema,
snowflake_external_function.snowalert_jira_api[0].name,
])
json_beautify_function = join(".", [
local.snowalert_database_name,
local.data_schema,
snowflake_function.json_beautify_with_indent.name,
])
object_assign_function = join(".", [
local.snowalert_database_name,
local.data_schema,
snowflake_function.object_assign.name,
])
}
)
depends_on = [
module.snowalert_grants
]
}