Skip to content

Commit d444afd

Browse files
authored
Add support for sovereign cloud ARN format. (#84)
* Add support for sovereign cloud ARN format. * Fixing blank line. * Fix spacing. * Fix PR Terraform init check. * Fix example TF versioning. * Remove arn format from example. * Add snowsql provider to example. * Fix snowsql provider on example.
1 parent 91354c5 commit d444afd

File tree

10 files changed

+50
-37
lines changed

10 files changed

+50
-37
lines changed

api_gateway.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ resource "aws_api_gateway_rest_api_policy" "ef_to_lambda" {
2222
{
2323
Effect = "Allow"
2424
Principal = {
25-
AWS = "arn:${var.arn_format}:sts::${local.account_id}:assumed-role/${local.api_gw_caller_role_name}/snowflake"
25+
AWS = "arn:${local.aws_partition}:sts::${local.account_id}:assumed-role/${local.api_gw_caller_role_name}/snowflake"
2626
}
2727
Action = "execute-api:Invoke"
2828
Resource = "${aws_api_gateway_rest_api.ef_to_lambda.execution_arn}/*/*/*"

api_integration.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ resource "snowflake_api_integration" "geff_api_integration" {
55
enabled = true
66
api_provider = length(regexall(".*gov.*", local.aws_region)) > 0 ? "aws_gov_api_gateway" : "aws_api_gateway"
77
api_allowed_prefixes = [local.inferred_api_gw_invoke_url]
8-
api_aws_role_arn = "arn:${var.arn_format}:iam::${local.account_id}:role/${local.api_gw_caller_role_name}"
8+
api_aws_role_arn = "arn:${local.aws_partition}:iam::${local.account_id}:role/${local.api_gw_caller_role_name}"
99
}
1010

1111
resource "snowflake_integration_grant" "geff_api_integration_grant" {

examples/complete/main.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ module "geff" {
66
env = var.env
77

88
# AWS
9-
arn_format = var.arn_format
109
aws_cloudwatch_metric_namespace = var.aws_cloudwatch_metric_namespace
1110
aws_region = var.aws_region
1211

@@ -27,6 +26,7 @@ module "geff" {
2726
providers = {
2827
snowflake.api_integration_role = snowflake.api_integration_role
2928
snowflake.storage_integration_role = snowflake.storage_integration_role
29+
snowsql.storage_integration_role = snowsql.storage_integration_role
3030
aws = aws
3131
}
3232
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
provider "snowsql" {
2+
alias = "storage_integration_role"
3+
4+
account = var.snowflake_account
5+
role = var.snowflake_storage_integration_owner_role
6+
username = "example_user"
7+
}

examples/complete/versions.tf

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,24 @@
11
terraform {
2-
required_version = "~> 1.4.6"
2+
required_version = ">= 1.4.6"
33

44
required_providers {
55
aws = {
66
source = "hashicorp/aws"
7-
version = "~> 4.38.0"
7+
version = "~> 5.72.0"
88
}
99

1010
snowflake = {
1111
source = "Snowflake-Labs/snowflake"
12-
version = "~> 0.64.0"
12+
version = "~> 0.73.0"
13+
}
14+
15+
snowsql = {
16+
source = "aidanmelen/snowsql"
17+
version = ">= 1.3.3"
18+
19+
configuration_aliases = [
20+
snowsql.storage_integration_role,
21+
]
1322
}
1423
}
1524
}

iam.tf

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ resource "aws_iam_role" "geff_api_gateway_assume_role" {
2525

2626
resource "aws_iam_role_policy_attachment" "gateway_logger_policy_attachment" {
2727
role = aws_iam_role.geff_api_gateway_assume_role.id
28-
policy_arn = "arn:${var.arn_format}:iam::aws:policy/service-role/AmazonAPIGatewayPushToCloudWatchLogs"
28+
policy_arn = "arn:${local.aws_partition}:iam::aws:policy/service-role/AmazonAPIGatewayPushToCloudWatchLogs"
2929
}
3030

3131
resource "aws_api_gateway_account" "api_gateway" {
@@ -100,7 +100,7 @@ data "aws_iam_policy_document" "geff_lambda_policy_doc" {
100100
sid = "WriteCloudWatchLogs"
101101
effect = "Allow"
102102
resources = [
103-
"arn:${var.arn_format}:logs:${data.aws_region.current.name}:${data.aws_caller_identity.current.account_id}:log-group:/aws/lambda/${local.lambda_function_name}:*"
103+
"arn:${local.aws_partition}:logs:${data.aws_region.current.name}:${data.aws_caller_identity.current.account_id}:log-group:/aws/lambda/${local.lambda_function_name}:*"
104104
]
105105

106106
actions = [
@@ -196,7 +196,7 @@ resource "aws_iam_role_policy" "geff_lambda_policy" {
196196

197197
data "aws_iam_policy" "geff_lambda_vpc_policy" {
198198
count = var.deploy_lambda_in_vpc ? 1 : 0
199-
arn = "arn:${var.arn_format}:iam::aws:policy/service-role/AWSLambdaENIManagementAccess"
199+
arn = "arn:${local.aws_partition}:iam::aws:policy/service-role/AWSLambdaENIManagementAccess"
200200
}
201201

202202
resource "aws_iam_policy_attachment" "geff_lambda_vpc_policy_attachment" {

kms.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ resource "aws_kms_key" "prod" {
99
Action = "kms:*"
1010
Effect = "Allow"
1111
Principal = {
12-
AWS = "arn:${var.arn_format}:iam::${local.account_id}:root"
12+
AWS = "arn:${local.aws_partition}:iam::${local.account_id}:root"
1313
}
1414
Resource = "*"
1515
Sid = "Enable IAM User Permissions"

storage_integration.tf

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
module "storage_integration" {
2-
source = "Snowflake-Labs/storage-integration-aws/snowflake"
2+
source = "Snowflake-Labs/storage-integration-aws/snowflake"
3+
version = "0.2.11"
34

45
# General
56
prefix = var.prefix
67
env = var.env
78

89
# AWS
9-
arn_format = var.arn_format
1010
data_bucket_arns = var.data_bucket_arns
1111
snowflake_integration_user_roles = var.snowflake_integration_user_roles
1212

1313
providers = {
1414
snowflake.storage_integration_role = snowflake.storage_integration_role
15+
snowsql.storage_integration_role = snowsql.storage_integration_role
1516
aws = aws
1617
}
1718
}

variables.tf

Lines changed: 10 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -88,12 +88,6 @@ variable "sentry_driver_dsn" {
8888
default = ""
8989
}
9090

91-
variable "arn_format" {
92-
type = string
93-
description = "ARN format could be aws or aws-us-gov. Defaults to non-gov."
94-
default = "aws"
95-
}
96-
9791
variable "create_dynamodb_table" {
9892
type = bool
9993
description = "Boolean for if a DynamoDB table is to be created for batch locking."
@@ -117,25 +111,18 @@ data "aws_region" "current" {}
117111
data "aws_partition" "current" {}
118112

119113
locals {
120-
account_id = data.aws_caller_identity.current.account_id
121-
aws_region = data.aws_region.current.name
122-
}
123-
124-
locals {
125-
lambda_image_repo = "${local.account_id}.dkr.ecr.${local.aws_region}.amazonaws.com/geff"
126-
}
114+
account_id = data.aws_caller_identity.current.account_id
115+
aws_region = data.aws_region.current.name
116+
aws_partition = data.aws_partition.current.partition
117+
aws_dns_suffix = data.aws_partition.current.dns_suffix
127118

128-
locals {
119+
lambda_image_repo = "${local.account_id}.dkr.ecr.${local.aws_region}.${local.aws_dns_suffix}/geff"
129120
lambda_image_repo_version = "${local.lambda_image_repo}:${var.geff_image_version}"
130-
}
121+
lambda_function_name = "${local.geff_prefix}-lambda"
131122

132-
locals {
133-
inferred_api_gw_invoke_url = "https://${aws_api_gateway_rest_api.ef_to_lambda.id}.execute-api.${local.aws_region}.amazonaws.com/"
134-
geff_prefix = "${var.prefix}-geff"
135-
}
123+
geff_prefix = "${var.prefix}-geff"
136124

137-
locals {
138-
lambda_function_name = "${local.geff_prefix}-lambda"
139-
api_gw_caller_role_name = "${local.geff_prefix}-api-gateway-caller"
140-
api_gw_logger_role_name = "${local.geff_prefix}-api-gateway-logger"
125+
inferred_api_gw_invoke_url = "https://${aws_api_gateway_rest_api.ef_to_lambda.id}.execute-api.${local.aws_region}.${local.aws_dns_suffix}/"
126+
api_gw_caller_role_name = "${local.geff_prefix}-api-gateway-caller"
127+
api_gw_logger_role_name = "${local.geff_prefix}-api-gateway-logger"
141128
}

versions.tf

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,26 @@ terraform {
44
required_providers {
55
aws = {
66
source = "hashicorp/aws"
7-
version = ">= 4.38.0"
7+
version = ">= 5.72.0"
88
}
99

1010
snowflake = {
1111
source = "Snowflake-Labs/snowflake"
12-
version = ">= 0.64.0"
12+
version = ">= 0.73.0"
1313

1414
configuration_aliases = [
1515
snowflake.api_integration_role,
1616
snowflake.storage_integration_role,
1717
]
1818
}
19+
20+
snowsql = {
21+
source = "aidanmelen/snowsql"
22+
version = ">= 1.3.3"
23+
24+
configuration_aliases = [
25+
snowsql.storage_integration_role,
26+
]
27+
}
1928
}
2029
}

0 commit comments

Comments
 (0)