Core Platform

Manage Snowflake Semantic Views with Snowflake Terraform Provider

Snowflake has introduced the new version of the Snowflake terraform provider, adding semantic view support. This is a game-changer for Snowflake developers, finally bringing infrastructure-as-code (IaC) to metric governance. Now you can version-control, peer-review and automatically deploy your crucial semantic views, to help ensure a single, trusted source of truth for all your BI tools and AI agents. 

Snowflake's semantic view is a powerful, native schema object designed to centralize key metric definitions. This directly tackles the problem of fragmented metric logic, which often undermines data trust across BI and analytics environments.

Many organizations want to manage their crucial semantic views using the same methods they have employed for years to manage their infrastructure. Specifically, customers have asked for an ability to enforce version control, peer review and state management on their semantic views, better aligning with how they manage their other Snowflake objects.

The new snowflake_semantic_view terraform resource (currently in preview mode) enables these capabilities, allowing organizations to treat their semantic views as infrastructure.

For developers building on Snowflake, this capability is key for several reasons:

  • It addresses the challenge of version control, allowing organizations to declaratively define their semantic views using standard HCL (HashiCorp Configuration Language) and SQL. 

  • The use of terraform facilitates deeper collaboration, as semantic view definitions can now be managed like any other infrastructure, thus enabling team-based code reviews and CI/CD deployment.

Figure 1: Managing Snowflake semantic views with terraform.
Figure 1: Managing Snowflake semantic views with terraform.

Feature highlights

  1. Declarative semantic modeling: Define and manage the full structure of your Snowflake semantic view, including its entities, relationships and precise metric logic (FACTS, DIMENSIONS, METRICS), using standard terraform syntax.
resource "snowflake_semantic_view" "sample" {
  database = "DATABASE"
  schema = "SCHEMA"
  name = "SEMANTIC_VIEW"
  comment = "comment"
  tables {
    comment = "comment"
    primary_key = ["COL1"]
    unique {
      values = ["COL2"]
    }
    table_alias = "TABLE_ALIAS"
    table_name = "TABLE_NAME"
    synonym = ["synonym", "synonym"]
  }
  tables {
    comment = "comment"
    primary_key = ["COL1"]
    unique {
      values = ["COL2"]
    }
    table_alias = "TABLE_ALIAS"
    table_name = "TABLE_NAME"
    synonym = ["synonym"]
  }
  relationships {
    relationship_identifier = "RELATIONSHIP_NAME"
    table_name_or_alias {
      table_alias = "TABLE_ALIAS"
    }
    relationship_columns = ["COL1", "COL2"]
    referenced_table_name_or_alias {
      table_alias = "TABLE_ALIAS"
    }
    referenced_relationship_columns = ["COL1", "COL2"]
  }
  facts {
    comment = "comment"
    qualified_expression_name = "TABLE_ALIAS.FACT_NAME"
    sql_expression = "SQL_EXPRESSION"
    synonym = ["synonym"]
  }
  dimensions {
    comment = "comment"
    qualified_expression_name = "TABLE_ALIAS.DIMENSION_NAME"
    sql_expression = "SQL_EXPRESSION"
    synonym = ["synonym"]
  }
  metrics {
    semantic_expression {
      comment = "comment"
      qualified_expression_name = "TABLE_ALIAS.METRIC_NAME"
      sql_expression = "SQL_EXPRESSION"
      synonym = ["synonym"]
    }
  }
  metrics {
    window_function {
      metric = "METRIC_EXPRESSION"
      over_clause {
        partition_by = "PARTITION_CLAUSE"
        order_by = "ORDER_BY_CLAUSE"
        window_frame_clause = "WINDOW_FRAME_CLAUSE"
      }
      window_function = "ALIAS.WINDOW_FUNCTION_NAME"
    }
  }
}

Source: This example is sourced from the official terraform documentation.

2. State management: This further allows users to leverage terraform’s significant state management capabilities to help ensure the integrity of the semantic views and their associated infrastructure. This enables clear impact analysis, showing exactly which parts of the semantic layer will be affected before any deployment, which is crucial for maintaining the stability of dependent reports.

3. Reduced privilege requirements: Developers no longer require elevated privileges to modify semantic views. Instead, you can now leverage existing code change processes to manage semantic view definitions due to the IaC approach.This significantly enhances the stability of semantic views by adding an additional layer of control.

Benefits

  • Using the new semantic view terraform resource to create, manage and version semantic views ensures reliability and consistency due to the establishment of a single “source of truth” for metrics across an organization. 

  • The terraform provider streamlines the CI/CD process by treating semantic views as infrastructure. This further allows users to leverage terraform’s significant state management capabilities to ensure the integrity of the semantic views and their associated infrastructure. This approach not only enhances the accuracy of current BI tools but also fosters data trustworthiness, which is vital for training and feeding future AI agents.

  • Terraform can catch potential issues through `terraform plan,` enabling you to review your changes before deploying them. This means that semantic views solely managed by terraform can be reliably used without needing to worry about broken deployment pipelines.

  • A unified semantic layer isn't just a win for traditional business intelligence; it is the critical foundation for modern AI and machine learning initiatives. By codifying your core metrics (like total sales or customer lifetime value) within terraform, you can ensure that every downstream consumer — whether it's a CEO's BI dashboard or an AI agent training a new forecasting model — is consuming the exact same, mathematically verified truth. This reduces confusion, drives data trustworthiness, and allows you to quickly leverage these verified metrics as features for new AI-powered BI experiences.

Conclusion

The snowflake_semantic_view terraform resource is a foundational step toward true data governance for Snowflake developers. Managing Snowflake semantic views through terraform allows you to leverage the familiar IaC process, including version control, peer reviews and CI/CD to enforce a single, consistent source of truth. The result is a unified semantic view that helps ensure that all consumers, from BI tools to AI applications, operate on trusted data. It gives data governance teams code-level control over metric definitions; allows analytics engineers to deploy metrics faster; and enables every consumer to work from the exact same trusted truth. Please refer to this guide to get started.

Ready to build the future of metric governance? Connect with our experts to discuss deploying semantic views across your enterprise, or learn more about the snowflake_semantic_view terraform resource to start version-controlling your metrics today.

Subscribe to our blog newsletter

Get the best, coolest and latest delivered to your inbox each week

Where Data Does More

  • 30-day free trial
  • No credit card required
  • Cancel anytime