Skip to content

Commit

Permalink
Merge pull request #1851 from kconvey/kms-encryption
Browse files Browse the repository at this point in the history
Add a configuration option `kms_key_name` to dbt_project.yml for BigQ…
  • Loading branch information
beckjake authored Nov 8, 2019
2 parents 9400958 + 83de6b1 commit 58b2955
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
3 changes: 2 additions & 1 deletion plugins/bigquery/dbt/adapters/bigquery/impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ class BigQueryAdapter(BaseAdapter):
Column = BigQueryColumn
ConnectionManager = BigQueryConnectionManager

AdapterSpecificConfigs = frozenset({"cluster_by", "partition_by"})
AdapterSpecificConfigs = frozenset({"cluster_by", "partition_by",
"kms_key_name"})

###
# Implementations of abstract methods
Expand Down
8 changes: 6 additions & 2 deletions plugins/bigquery/dbt/include/bigquery/macros/adapters.sql
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

{%- endmacro -%}

{% macro bigquery_table_options(persist_docs, temporary) %}
{% macro bigquery_table_options(persist_docs, temporary, kms_key_name) %}
{% set opts = {} %}

{% set description = get_relation_comment(persist_docs, model) %}
Expand All @@ -36,6 +36,9 @@
{% if temporary %}
{% do opts.update({'expiration_timestamp': 'TIMESTAMP_ADD(CURRENT_TIMESTAMP(), INTERVAL 12 hour)'}) %}
{% endif %}
{% if kms_key_name %}
{% do opts.update({'kms_key_name': "'" ~ kms_key_name ~ "'"}) %}
{% endif %}

{% set options -%}
OPTIONS({% for opt_key, opt_val in opts.items() %}
Expand All @@ -49,11 +52,12 @@
{%- set raw_partition_by = config.get('partition_by', none) -%}
{%- set raw_cluster_by = config.get('cluster_by', none) -%}
{%- set raw_persist_docs = config.get('persist_docs', {}) -%}
{%- set raw_kms_key_name = config.get('kms_key_name', none) -%}

create or replace table {{ relation }}
{{ partition_by(raw_partition_by) }}
{{ cluster_by(raw_cluster_by) }}
{{ bigquery_table_options(persist_docs=raw_persist_docs, temporary=temporary) }}
{{ bigquery_table_options(persist_docs=raw_persist_docs, temporary=temporary, kms_key_name=raw_kms_key_name) }}
as (
{{ sql }}
);
Expand Down

0 comments on commit 58b2955

Please sign in to comment.