SlideShare a Scribd company logo
1 of 30
Copyright © 2020 HashiCorp
Using New Sentinel Features in
Terraform Cloud and Terraform
Enterprise
Roger Berlind
Technology Specialist
HashiCorp
Copyright © 2020 HashiCorp
▪ Sentinel in Terraform Cloud (TFC) and Terraform Enterprise (TFE)
▪ Two New Sentinel Features
– Sentinel Modules
– Terraform Sentinel v2 Imports
▪ The Evolution of Sentinel Policies
▪ Some Prototypical Third-Generation Sentinel Policies
▪ The Third-Generation Common Functions
▪ Testing and Using the Third Generation Sentinel Policies
▪ A Demo
Agenda
Copyright © 2020 HashiCorp
Sentinel in Terraform Cloud and
Terraform Enterprise
Copyright © 2020 HashiCorp
▪ HashiCorp's Sentinel is a framework for implementing governance
policies as code in the same way that Terraform implements
infrastructure as code.
▪ It includes its own language and is embedded in HashiCorp's
enterprise products.
▪ Using Sentinel ensures that your governance policies are actually
being checked rather than just being listed in a spreadsheet.
▪ It supports fine-grained policies that use conditional logic.
▪ It includes a CLI that allows you to test and run policies.
What is Sentinel?
Copyright © 2020 HashiCorp
Terraform Cloud and Terraform Enterprise
▪ A User Interface
▪ Workspace Management
▪ Team Management
▪ State Management
▪ Secure Variable Management
▪ Remote Runs and State
▪ VCS Integrations
▪ HTTP/JSON API
▪ Private Module Registry
▪ Configuration Editor
▪ Sentinel (policy as code)
▪ SSO via SAML Integration
▪ Audit Logging
Terraform Cloud (TFC) includes the following advanced functionality that
makes it easier for teams and organizations to use Terraform:
Customers can install Terraform Enterprise (TFE) servers to self-host
TFC in their own virtual private networks or in their data centers.
Copyright © 2020 HashiCorp
▪ Sentinel policies are checked between the standard plan and apply
steps of Terraform runs.
▪ Policies have different enforcement levels: advisory, soft-mandatory, and
hard-mandatory.
▪ Violations prevent runs from being applied unless a user with sufficient
authority overrides them.
▪ Sentinel policies can evaluate the attributes (arguments and exported
attributes) of existing and new resources and data sources based on
information from the current run:
– the plan, the configuration, the current state, and other run data
including cost estimates
▪ This ensures that resources comply with all policies before they are
provisioned.
Where is Sentinel Used in Terraform?
Copyright © 2020 HashiCorp
How Terraform Works Without Sentinel
VCS Terraform Infrastructureplan & apply
Copyright © 2020 HashiCorp
How Terraform Works With Sentinel
VCS Terraform
Cloud
Workspace
Infrastructureplan Sentinel
Policy
Checks
apply
If cost estimates are enabled, they run right after the plan.
Copyright © 2020 HashiCorp
All Policy Checks Passed
Copyright © 2020 HashiCorp
▪ HashiCorp customers are using Sentinel to implement governance
policies like the following in Terraform Cloud/Enterprise:
– Enforce security standards:
▪ Require all S3 buckets use the private ACL and be encrypted by KMS.
▪ Restrict which roles the AWS provider can assume.
▪ Blacklist/whitelist resources, data sources, providers, or provisioners.
– Avoid excessive costs:
▪ Limit the sizes of VMs and Kubernetes clusters in public clouds.
▪ Limit the monthly spend of each Terraform workspace.
– Enforce mandatory tags on resources provisioned by Terraform.
– Mandate that all modules come from a Private Module Registry.
– Enforce specific Terraform coding conventions.
How Customers are Using Sentinel in Terraform
Copyright © 2020 HashiCorp
Two New Sentinel
Features
Copyright © 2020 HashiCorp
▪ A Sentinel Module defines Sentinel functions and rules in a file that can
be used by Sentinel policies with a single import statement.
▪ This avoids the need to paste the functions into every policy that calls
them, improving the reusability of Sentinel functions.
▪ Sentinel modules are registered in Sentinel CLI configuration files and in
TFC/TFE policy set configuration files.
▪ The terraform-guides repository includes 5 "third-generation" modules:
– tfplan-functions, tfstate-functions, tfconfig-functions, tfrun-functions,
and aws-functions
▪ Each function is documented in a separate MD file.
▪ Note that these are NOT standard functions.
Sentinel Modules
Copyright © 2020 HashiCorp
▪ The new v2 versions of three Terraform Sentinel imports (tfplan,
tfstate, and tfconfig) are aligned more closely with native
Terraform 0.12 data structures.
▪ This makes the v2 imports easier to use than the v1 imports.
▪ Additionally, since resource instances are stored in a single flat
map that spans across all Terraform modules and resource types, it
is much easier to find all resources instances of a specific type or a
sub-collection of them.
▪ However, there is a catch:
– The v2 imports can only be used with Terraform 0.12.
New v2 Versions of the Terraform Sentinel Imports
Copyright © 2020 HashiCorp
▪ The tfplan/v2 gives data generated from Terraform plans.
– https://www.terraform.io/docs/cloud/sentinel/import/tfplan-v2.html
▪ The tfconfig/v2 import gives data about the Terraform configuration.
– https://www.terraform.io/docs/cloud/sentinel/import/tfconfig-v2.html
▪ The tfstate/v2 import gives data about the current state of a
workspace.
– https://www.terraform.io/docs/cloud/sentinel/import/tfstate-v2.html
▪ The tfrun import provides metadata for Terraform runs and their
workspaces as well as cost estimate data. (There is no v2 version of it.)
– https://www.terraform.io/docs/cloud/sentinel/import/tfrun.html
Sentinel Imports in Terraform
Copyright © 2020 HashiCorp
The Evolution of Sentinel Policies
Copyright © 2020 HashiCorp
▪ The first-generation policies were written in late 2018 and used the
original Terraform Sentinel v1 imports.
▪ They had several short-comings, including the following:
– Most of the policies did not print violation messages for resources
that violated them.
– They stopped evaluating conditions as soon as a single resource
instance violated them.
– They failed when resources that were being destroyed violated
conditions.
– Their use of default Sentinel output was overly verbose.
The First-Generation Policies
Copyright © 2020 HashiCorp
▪ The second-generation policies were written in 2019 and used the original
Terraform Sentinel v1 imports:
▪ They made the following improvements:
– They offloaded most processing from rules into some common
parameterized functions.
– Those common functions were written in a way that caused all violations
of all rules to be reported.
– They printed out the full address of each resource instance that did
violate a policy.
– By using a single main rule, they suppressed most of Sentinel’s default,
overly verbose output.
– They skipped resources that were being destroyed but not recreated.
The Second-Generation Policies
Copyright © 2020 HashiCorp
▪ The new third-generation policies were written in the spring of 2020 and
use the new Terraform Sentinel v2 imports and Sentinel modules.
▪ They have the following advantages:
– Their use of the v2 imports and the Sentinel filter expression makes it
easier to restrict policies to specific operations performed by Terraform.
– The common functions defined in Sentinel modules do not need to be
pasted into policies that use them.
– Most of the policies do not have any for loops of if/else conditionals. This
makes the policies easier to understand and copy.
– They can evaluate the value of any attribute of any resource or data
source, even those that are deeply nested.
▪ However, since they do use the v2 imports, they can only be used with
Terraform 0.12
The New Third-Generation Policies
Copyright © 2020 HashiCorp
Some Prototypical Third-
Generation Sentinel Policies
Copyright © 2020 HashiCorp
▪ I'll review four prototypical third-generation Sentinel policies in
order of increasing sophistication:
– restrict-ec2-instance-type.sentinel (AWS)
– restrict-vm-cpu-and-memory.sentinel (VMware)
– restrict-vm-disk-size.sentinel (VMware)
– restrict-publishers-of-current-vms.sentinel (Azure)
Some Prototypical Third-Generation Policies
Copyright © 2020 HashiCorp
The Third-Generation Common
Functions
Copyright © 2020 HashiCorp
▪ As mentioned earlier, there are third-generation Sentinel modules
with common functions for each of the Terraform Sentinel imports.
▪ The tfplan and tfstate modules have the following functions:
– Find functions that find resources, data sources, and blocks.
– Filter functions that filter collections of resources, data sources, or
blocks. These each return two maps: resources and messages.
– The evaluate_attribute function that can evaluate any attribute
of any resource, data source, or block, even if deeply nested.
– The to_string and print_violation functions that are used by the
other functions.
▪ There is also a Sentinel module with some AWS-specific functions.
The Third-Generation Common Functions
Copyright © 2020 HashiCorp
Testing and Using the Third-
Generation Sentinel Policies
Copyright © 2020 HashiCorp
▪ All the third-generation Sentinel policies have test cases and mocks
that support testing the policies with the Sentinel CLI
▪ Do the following:
– Download the Sentinel CLI from the Sentinel Downloads page.
– Unzip the zip file and place the sentinel binary in your path.
– Fork the terraform-guides repository and clone your fork to your
local machine.
– Navigate to any of the cloud directories (aws, azure, gcp, or
vmware) or to the cloud-agnostic directory.
– Run sentinel test to test all policies for that cloud.
– Run sentinel test -run=<partial_policy_name> -verbose to
test individual policies, using a string that partially matches name.
Testing Policies with the Sentinel CLI
Copyright © 2020 HashiCorp
{
"modules": {
"tfplan-functions": {
"path": "../../../common-functions/tfplan-functions/
tfplan-functions.sentinel"
}
},
"mock": {
"tfplan/v2": "mock-tfplan-pass.sentinel"
},
"test": {
"main": true
}
}
An Example Test Case that References a Module
Copyright © 2020 HashiCorp
▪ After successfully testing a policy with the CLI and possibly also on
TFC itself, you will want to deploy it to your TFC/TFE organizations.
▪ If you have not already added the policy to a policy set in your
organizations, do that at this time.
▪ Add the new policy to an existing policy set that is already applied
against desired workspaces, or create a new policy set for the
policy and apply that policy set to desired workspaces across your
organizations.
▪ Also add any parameters the policy requires to your policy set.
▪ And add references to any Sentinel Modules that policies in it use.
Deploying Policies in TFC or TFE
Copyright © 2020 HashiCorp
▪ Here is an example policy set:
module "tfplan-functions" {
source = "../common-functions/tfplan-functions/tfplan
-functions.sentinel"
}
policy "restrict-ec2-instance-type" {
source = "./restrict-ec2-instance-type.sentinel"
enforcement_level = "soft-mandatory"
}
Example Policy Set
Copyright © 2020 HashiCorp
Demo
Copyright © 2020 HashiCorp
▪ Here are some useful Links
▪ Documentation
– https://www.terraform.io/docs/cloud/sentinel/index.html
– https://www.terraform.io/docs/cloud/sentinel/manage-
policies.html
– https://docs.hashicorp.com/sentinel
▪ Other Resources:
– Blog for this webinar
– Sentinel in Terraform v2 Workshop (including hands-on Instruqt
track that teaches you how to write and test policies)
Some Useful Links
Thank you.
hello@hashicorp.comwww.hashicorp.com

More Related Content

What's hot

Hashiconf Israel 2022 - Terraform Pull Request Automation.pptx
Hashiconf Israel 2022 - Terraform Pull Request Automation.pptxHashiconf Israel 2022 - Terraform Pull Request Automation.pptx
Hashiconf Israel 2022 - Terraform Pull Request Automation.pptxTal Hibner
 
Terraform + ansible talk
Terraform + ansible talkTerraform + ansible talk
Terraform + ansible talkJames Strong
 
Terraform -- Infrastructure as Code
Terraform -- Infrastructure as CodeTerraform -- Infrastructure as Code
Terraform -- Infrastructure as CodeMartin Schütte
 
Using HashiCorp’s Terraform to build your infrastructure on AWS - Pop-up Loft...
Using HashiCorp’s Terraform to build your infrastructure on AWS - Pop-up Loft...Using HashiCorp’s Terraform to build your infrastructure on AWS - Pop-up Loft...
Using HashiCorp’s Terraform to build your infrastructure on AWS - Pop-up Loft...Amazon Web Services
 
Infrastructure-as-Code (IaC) Using Terraform (Advanced Edition)
Infrastructure-as-Code (IaC) Using Terraform (Advanced Edition)Infrastructure-as-Code (IaC) Using Terraform (Advanced Edition)
Infrastructure-as-Code (IaC) Using Terraform (Advanced Edition)Adin Ermie
 
Terraform Introduction
Terraform IntroductionTerraform Introduction
Terraform Introductionsoniasnowfrog
 
Terraform modules and best-practices - September 2018
Terraform modules and best-practices - September 2018Terraform modules and best-practices - September 2018
Terraform modules and best-practices - September 2018Anton Babenko
 
Terraform 0.12 + Terragrunt
Terraform 0.12 + TerragruntTerraform 0.12 + Terragrunt
Terraform 0.12 + TerragruntAnton Babenko
 
Terraform modules and (some of) best practices
Terraform modules and (some of) best practicesTerraform modules and (some of) best practices
Terraform modules and (some of) best practicesAnton Babenko
 
How Netflix Tunes EC2 Instances for Performance
How Netflix Tunes EC2 Instances for PerformanceHow Netflix Tunes EC2 Instances for Performance
How Netflix Tunes EC2 Instances for PerformanceBrendan Gregg
 
From zero to hero Backing up alfresco
From zero to hero Backing up alfrescoFrom zero to hero Backing up alfresco
From zero to hero Backing up alfrescoToni de la Fuente
 
Infrastructure-as-Code (IaC) using Terraform
Infrastructure-as-Code (IaC) using TerraformInfrastructure-as-Code (IaC) using Terraform
Infrastructure-as-Code (IaC) using TerraformAdin Ermie
 

What's hot (20)

Final terraform
Final terraformFinal terraform
Final terraform
 
Hashiconf Israel 2022 - Terraform Pull Request Automation.pptx
Hashiconf Israel 2022 - Terraform Pull Request Automation.pptxHashiconf Israel 2022 - Terraform Pull Request Automation.pptx
Hashiconf Israel 2022 - Terraform Pull Request Automation.pptx
 
Terraform + ansible talk
Terraform + ansible talkTerraform + ansible talk
Terraform + ansible talk
 
Terraform -- Infrastructure as Code
Terraform -- Infrastructure as CodeTerraform -- Infrastructure as Code
Terraform -- Infrastructure as Code
 
Terraform
TerraformTerraform
Terraform
 
Using HashiCorp’s Terraform to build your infrastructure on AWS - Pop-up Loft...
Using HashiCorp’s Terraform to build your infrastructure on AWS - Pop-up Loft...Using HashiCorp’s Terraform to build your infrastructure on AWS - Pop-up Loft...
Using HashiCorp’s Terraform to build your infrastructure on AWS - Pop-up Loft...
 
Terraform
TerraformTerraform
Terraform
 
Terraform
TerraformTerraform
Terraform
 
Infrastructure-as-Code (IaC) Using Terraform (Advanced Edition)
Infrastructure-as-Code (IaC) Using Terraform (Advanced Edition)Infrastructure-as-Code (IaC) Using Terraform (Advanced Edition)
Infrastructure-as-Code (IaC) Using Terraform (Advanced Edition)
 
Terraform
TerraformTerraform
Terraform
 
Terraform Introduction
Terraform IntroductionTerraform Introduction
Terraform Introduction
 
Terraform on Azure
Terraform on AzureTerraform on Azure
Terraform on Azure
 
Terraform
TerraformTerraform
Terraform
 
Terraform modules and best-practices - September 2018
Terraform modules and best-practices - September 2018Terraform modules and best-practices - September 2018
Terraform modules and best-practices - September 2018
 
Terraform 0.12 + Terragrunt
Terraform 0.12 + TerragruntTerraform 0.12 + Terragrunt
Terraform 0.12 + Terragrunt
 
Terraform modules and (some of) best practices
Terraform modules and (some of) best practicesTerraform modules and (some of) best practices
Terraform modules and (some of) best practices
 
How Netflix Tunes EC2 Instances for Performance
How Netflix Tunes EC2 Instances for PerformanceHow Netflix Tunes EC2 Instances for Performance
How Netflix Tunes EC2 Instances for Performance
 
From zero to hero Backing up alfresco
From zero to hero Backing up alfrescoFrom zero to hero Backing up alfresco
From zero to hero Backing up alfresco
 
Introduce to Terraform
Introduce to TerraformIntroduce to Terraform
Introduce to Terraform
 
Infrastructure-as-Code (IaC) using Terraform
Infrastructure-as-Code (IaC) using TerraformInfrastructure-as-Code (IaC) using Terraform
Infrastructure-as-Code (IaC) using Terraform
 

Similar to Using new sentinel features in terraform cloud

RIMA-Infrastructure as a code with Terraform.pptx
RIMA-Infrastructure as a code with Terraform.pptxRIMA-Infrastructure as a code with Terraform.pptx
RIMA-Infrastructure as a code with Terraform.pptxMrJustbis
 
Terraform Abstractions for Safety and Power
Terraform Abstractions for Safety and PowerTerraform Abstractions for Safety and Power
Terraform Abstractions for Safety and PowerCalvin French-Owen
 
Policy Guided Fulfillmentof Murano Applications
Policy Guided Fulfillmentof Murano ApplicationsPolicy Guided Fulfillmentof Murano Applications
Policy Guided Fulfillmentof Murano Applicationsrpospisil
 
3 Reasons to Select Time Series Platforms for Cloud Native Applications Monit...
3 Reasons to Select Time Series Platforms for Cloud Native Applications Monit...3 Reasons to Select Time Series Platforms for Cloud Native Applications Monit...
3 Reasons to Select Time Series Platforms for Cloud Native Applications Monit...DevOps.com
 
Terraform vs Pulumi
Terraform vs PulumiTerraform vs Pulumi
Terraform vs PulumiHoaiNam307
 
DevOps Online Training in Hyderabad
DevOps Online Training in HyderabadDevOps Online Training in Hyderabad
DevOps Online Training in HyderabadVisualpath Training
 
Git ops & Continuous Infrastructure with terra*
Git ops  & Continuous Infrastructure with terra*Git ops  & Continuous Infrastructure with terra*
Git ops & Continuous Infrastructure with terra*Haggai Philip Zagury
 
Terraform day 1
Terraform day 1Terraform day 1
Terraform day 1Kalkey
 
Unicorn Platform; Basic Usage Guide
Unicorn Platform; Basic Usage GuideUnicorn Platform; Basic Usage Guide
Unicorn Platform; Basic Usage Guideubigiannis
 
Controlling Cloud Costs with HashiCorp Terraform
Controlling Cloud Costs with HashiCorp TerraformControlling Cloud Costs with HashiCorp Terraform
Controlling Cloud Costs with HashiCorp TerraformDevOps.com
 
Installing your influx enterprise cluster
Installing your influx enterprise clusterInstalling your influx enterprise cluster
Installing your influx enterprise clusterChris Churilo
 
3 reasons to pick a time series platform for monitoring dev ops driven contai...
3 reasons to pick a time series platform for monitoring dev ops driven contai...3 reasons to pick a time series platform for monitoring dev ops driven contai...
3 reasons to pick a time series platform for monitoring dev ops driven contai...DevOps.com
 
Developing Tizen OS Based Solutions (IDF13) - Chris Norman
Developing Tizen OS Based Solutions (IDF13) - Chris NormanDeveloping Tizen OS Based Solutions (IDF13) - Chris Norman
Developing Tizen OS Based Solutions (IDF13) - Chris NormanRyo Jin
 
Self-service PR-based Terraform
Self-service PR-based TerraformSelf-service PR-based Terraform
Self-service PR-based TerraformAndrew Kirkpatrick
 
Infrastructure as Code with Terraform.pptx
Infrastructure as Code with Terraform.pptxInfrastructure as Code with Terraform.pptx
Infrastructure as Code with Terraform.pptxSamuel862293
 
The Flink - Apache Bigtop integration
The Flink - Apache Bigtop integrationThe Flink - Apache Bigtop integration
The Flink - Apache Bigtop integrationMárton Balassi
 
Build cloud native solution using open source
Build cloud native solution using open source Build cloud native solution using open source
Build cloud native solution using open source Nitesh Jadhav
 

Similar to Using new sentinel features in terraform cloud (20)

RIMA-Infrastructure as a code with Terraform.pptx
RIMA-Infrastructure as a code with Terraform.pptxRIMA-Infrastructure as a code with Terraform.pptx
RIMA-Infrastructure as a code with Terraform.pptx
 
Terraform Abstractions for Safety and Power
Terraform Abstractions for Safety and PowerTerraform Abstractions for Safety and Power
Terraform Abstractions for Safety and Power
 
Policy Guided Fulfillmentof Murano Applications
Policy Guided Fulfillmentof Murano ApplicationsPolicy Guided Fulfillmentof Murano Applications
Policy Guided Fulfillmentof Murano Applications
 
3 Reasons to Select Time Series Platforms for Cloud Native Applications Monit...
3 Reasons to Select Time Series Platforms for Cloud Native Applications Monit...3 Reasons to Select Time Series Platforms for Cloud Native Applications Monit...
3 Reasons to Select Time Series Platforms for Cloud Native Applications Monit...
 
Terraform vs Pulumi
Terraform vs PulumiTerraform vs Pulumi
Terraform vs Pulumi
 
DevOps Online Training in Hyderabad
DevOps Online Training in HyderabadDevOps Online Training in Hyderabad
DevOps Online Training in Hyderabad
 
Kafka/SMM Crash Course
Kafka/SMM Crash CourseKafka/SMM Crash Course
Kafka/SMM Crash Course
 
Git ops & Continuous Infrastructure with terra*
Git ops  & Continuous Infrastructure with terra*Git ops  & Continuous Infrastructure with terra*
Git ops & Continuous Infrastructure with terra*
 
OpenStack Murano
OpenStack MuranoOpenStack Murano
OpenStack Murano
 
Terraform day 1
Terraform day 1Terraform day 1
Terraform day 1
 
Unicorn Platform; Basic Usage Guide
Unicorn Platform; Basic Usage GuideUnicorn Platform; Basic Usage Guide
Unicorn Platform; Basic Usage Guide
 
Controlling Cloud Costs with HashiCorp Terraform
Controlling Cloud Costs with HashiCorp TerraformControlling Cloud Costs with HashiCorp Terraform
Controlling Cloud Costs with HashiCorp Terraform
 
Installing your influx enterprise cluster
Installing your influx enterprise clusterInstalling your influx enterprise cluster
Installing your influx enterprise cluster
 
3 reasons to pick a time series platform for monitoring dev ops driven contai...
3 reasons to pick a time series platform for monitoring dev ops driven contai...3 reasons to pick a time series platform for monitoring dev ops driven contai...
3 reasons to pick a time series platform for monitoring dev ops driven contai...
 
Developing Tizen OS Based Solutions (IDF13) - Chris Norman
Developing Tizen OS Based Solutions (IDF13) - Chris NormanDeveloping Tizen OS Based Solutions (IDF13) - Chris Norman
Developing Tizen OS Based Solutions (IDF13) - Chris Norman
 
Self-service PR-based Terraform
Self-service PR-based TerraformSelf-service PR-based Terraform
Self-service PR-based Terraform
 
Infrastructure as Code with Terraform.pptx
Infrastructure as Code with Terraform.pptxInfrastructure as Code with Terraform.pptx
Infrastructure as Code with Terraform.pptx
 
The Flink - Apache Bigtop integration
The Flink - Apache Bigtop integrationThe Flink - Apache Bigtop integration
The Flink - Apache Bigtop integration
 
Build cloud native solution using open source
Build cloud native solution using open source Build cloud native solution using open source
Build cloud native solution using open source
 
Online spanish meetup #2
Online spanish meetup #2Online spanish meetup #2
Online spanish meetup #2
 

More from Mitchell Pronschinske

Getting Started with Kubernetes and Consul
Getting Started with Kubernetes and ConsulGetting Started with Kubernetes and Consul
Getting Started with Kubernetes and ConsulMitchell Pronschinske
 
Multi-Cloud with Nomad and Consul Connect
Multi-Cloud with Nomad and Consul ConnectMulti-Cloud with Nomad and Consul Connect
Multi-Cloud with Nomad and Consul ConnectMitchell Pronschinske
 
Dynamic Azure Credentials for Applications and CI/CD Pipelines
Dynamic Azure Credentials for Applications and CI/CD PipelinesDynamic Azure Credentials for Applications and CI/CD Pipelines
Dynamic Azure Credentials for Applications and CI/CD PipelinesMitchell Pronschinske
 
Migrating from VMs to Kubernetes using HashiCorp Consul Service on Azure
Migrating from VMs to Kubernetes using HashiCorp Consul Service on AzureMigrating from VMs to Kubernetes using HashiCorp Consul Service on Azure
Migrating from VMs to Kubernetes using HashiCorp Consul Service on AzureMitchell Pronschinske
 
Empowering developers and operators through Gitlab and HashiCorp
Empowering developers and operators through Gitlab and HashiCorpEmpowering developers and operators through Gitlab and HashiCorp
Empowering developers and operators through Gitlab and HashiCorpMitchell Pronschinske
 
Automate and simplify multi cloud complexity with f5 and hashi corp
Automate and simplify multi cloud complexity with f5 and hashi corpAutomate and simplify multi cloud complexity with f5 and hashi corp
Automate and simplify multi cloud complexity with f5 and hashi corpMitchell Pronschinske
 
Military Edge Computing with Vault and Consul
Military Edge Computing with Vault and ConsulMilitary Edge Computing with Vault and Consul
Military Edge Computing with Vault and ConsulMitchell Pronschinske
 
Unlocking the Cloud operating model with GitHub Actions
Unlocking the Cloud operating model with GitHub ActionsUnlocking the Cloud operating model with GitHub Actions
Unlocking the Cloud operating model with GitHub ActionsMitchell Pronschinske
 
Vault 1.4 integrated storage overview
Vault 1.4 integrated storage overviewVault 1.4 integrated storage overview
Vault 1.4 integrated storage overviewMitchell Pronschinske
 
Cisco ACI with HashiCorp Terraform (APAC)
Cisco ACI with HashiCorp Terraform (APAC)Cisco ACI with HashiCorp Terraform (APAC)
Cisco ACI with HashiCorp Terraform (APAC)Mitchell Pronschinske
 
Governance for Multiple Teams Sharing a Nomad Cluster
Governance for Multiple Teams Sharing a Nomad ClusterGovernance for Multiple Teams Sharing a Nomad Cluster
Governance for Multiple Teams Sharing a Nomad ClusterMitchell Pronschinske
 
Unlocking the Cloud Operating Model: Deployment
Unlocking the Cloud Operating Model: DeploymentUnlocking the Cloud Operating Model: Deployment
Unlocking the Cloud Operating Model: DeploymentMitchell Pronschinske
 
Keeping a Secret with HashiCorp Vault
Keeping a Secret with HashiCorp VaultKeeping a Secret with HashiCorp Vault
Keeping a Secret with HashiCorp VaultMitchell Pronschinske
 
Modern Scheduling for Modern Applications with Nomad
Modern Scheduling for Modern Applications with NomadModern Scheduling for Modern Applications with Nomad
Modern Scheduling for Modern Applications with NomadMitchell Pronschinske
 
Moving to a Microservice World: Leveraging Consul on Azure
Moving to a Microservice World: Leveraging Consul on AzureMoving to a Microservice World: Leveraging Consul on Azure
Moving to a Microservice World: Leveraging Consul on AzureMitchell Pronschinske
 

More from Mitchell Pronschinske (20)

Getting Started with Kubernetes and Consul
Getting Started with Kubernetes and ConsulGetting Started with Kubernetes and Consul
Getting Started with Kubernetes and Consul
 
Multi-Cloud with Nomad and Consul Connect
Multi-Cloud with Nomad and Consul ConnectMulti-Cloud with Nomad and Consul Connect
Multi-Cloud with Nomad and Consul Connect
 
Code quality for Terraform
Code quality for TerraformCode quality for Terraform
Code quality for Terraform
 
Dynamic Azure Credentials for Applications and CI/CD Pipelines
Dynamic Azure Credentials for Applications and CI/CD PipelinesDynamic Azure Credentials for Applications and CI/CD Pipelines
Dynamic Azure Credentials for Applications and CI/CD Pipelines
 
Migrating from VMs to Kubernetes using HashiCorp Consul Service on Azure
Migrating from VMs to Kubernetes using HashiCorp Consul Service on AzureMigrating from VMs to Kubernetes using HashiCorp Consul Service on Azure
Migrating from VMs to Kubernetes using HashiCorp Consul Service on Azure
 
Empowering developers and operators through Gitlab and HashiCorp
Empowering developers and operators through Gitlab and HashiCorpEmpowering developers and operators through Gitlab and HashiCorp
Empowering developers and operators through Gitlab and HashiCorp
 
Automate and simplify multi cloud complexity with f5 and hashi corp
Automate and simplify multi cloud complexity with f5 and hashi corpAutomate and simplify multi cloud complexity with f5 and hashi corp
Automate and simplify multi cloud complexity with f5 and hashi corp
 
Vault 1.5 Overview
Vault 1.5 OverviewVault 1.5 Overview
Vault 1.5 Overview
 
Military Edge Computing with Vault and Consul
Military Edge Computing with Vault and ConsulMilitary Edge Computing with Vault and Consul
Military Edge Computing with Vault and Consul
 
Unlocking the Cloud operating model with GitHub Actions
Unlocking the Cloud operating model with GitHub ActionsUnlocking the Cloud operating model with GitHub Actions
Unlocking the Cloud operating model with GitHub Actions
 
Vault 1.4 integrated storage overview
Vault 1.4 integrated storage overviewVault 1.4 integrated storage overview
Vault 1.4 integrated storage overview
 
Unlocking the Cloud Operating Model
Unlocking the Cloud Operating ModelUnlocking the Cloud Operating Model
Unlocking the Cloud Operating Model
 
Cisco ACI with HashiCorp Terraform (APAC)
Cisco ACI with HashiCorp Terraform (APAC)Cisco ACI with HashiCorp Terraform (APAC)
Cisco ACI with HashiCorp Terraform (APAC)
 
Governance for Multiple Teams Sharing a Nomad Cluster
Governance for Multiple Teams Sharing a Nomad ClusterGovernance for Multiple Teams Sharing a Nomad Cluster
Governance for Multiple Teams Sharing a Nomad Cluster
 
Integrating Terraform and Consul
Integrating Terraform and ConsulIntegrating Terraform and Consul
Integrating Terraform and Consul
 
Unlocking the Cloud Operating Model: Deployment
Unlocking the Cloud Operating Model: DeploymentUnlocking the Cloud Operating Model: Deployment
Unlocking the Cloud Operating Model: Deployment
 
Keeping a Secret with HashiCorp Vault
Keeping a Secret with HashiCorp VaultKeeping a Secret with HashiCorp Vault
Keeping a Secret with HashiCorp Vault
 
Modern Scheduling for Modern Applications with Nomad
Modern Scheduling for Modern Applications with NomadModern Scheduling for Modern Applications with Nomad
Modern Scheduling for Modern Applications with Nomad
 
Moving to a Microservice World: Leveraging Consul on Azure
Moving to a Microservice World: Leveraging Consul on AzureMoving to a Microservice World: Leveraging Consul on Azure
Moving to a Microservice World: Leveraging Consul on Azure
 
Remote Culture at HashiCorp
Remote Culture at HashiCorpRemote Culture at HashiCorp
Remote Culture at HashiCorp
 

Recently uploaded

ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...Christina Lin
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVshikhaohhpro
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...OnePlan Solutions
 
chapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptchapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptkotipi9215
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...MyIntelliSource, Inc.
 
XpertSolvers: Your Partner in Building Innovative Software Solutions
XpertSolvers: Your Partner in Building Innovative Software SolutionsXpertSolvers: Your Partner in Building Innovative Software Solutions
XpertSolvers: Your Partner in Building Innovative Software SolutionsMehedi Hasan Shohan
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...gurkirankumar98700
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...stazi3110
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideChristina Lin
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software DevelopersVinodh Ram
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxTier1 app
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackVICTOR MAESTRE RAMIREZ
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEOrtus Solutions, Corp
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdfWave PLM
 
The Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfThe Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfPower Karaoke
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...kellynguyen01
 
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfThe Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfkalichargn70th171
 
why an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfwhy an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfjoe51371421
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...soniya singh
 
Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...aditisharan08
 

Recently uploaded (20)

ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...
 
chapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptchapter--4-software-project-planning.ppt
chapter--4-software-project-planning.ppt
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
 
XpertSolvers: Your Partner in Building Innovative Software Solutions
XpertSolvers: Your Partner in Building Innovative Software SolutionsXpertSolvers: Your Partner in Building Innovative Software Solutions
XpertSolvers: Your Partner in Building Innovative Software Solutions
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software Developers
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStack
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf
 
The Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfThe Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdf
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
 
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfThe Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
 
why an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfwhy an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdf
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
 
Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...
 

Using new sentinel features in terraform cloud

  • 1. Copyright © 2020 HashiCorp Using New Sentinel Features in Terraform Cloud and Terraform Enterprise Roger Berlind Technology Specialist HashiCorp
  • 2. Copyright © 2020 HashiCorp ▪ Sentinel in Terraform Cloud (TFC) and Terraform Enterprise (TFE) ▪ Two New Sentinel Features – Sentinel Modules – Terraform Sentinel v2 Imports ▪ The Evolution of Sentinel Policies ▪ Some Prototypical Third-Generation Sentinel Policies ▪ The Third-Generation Common Functions ▪ Testing and Using the Third Generation Sentinel Policies ▪ A Demo Agenda
  • 3. Copyright © 2020 HashiCorp Sentinel in Terraform Cloud and Terraform Enterprise
  • 4. Copyright © 2020 HashiCorp ▪ HashiCorp's Sentinel is a framework for implementing governance policies as code in the same way that Terraform implements infrastructure as code. ▪ It includes its own language and is embedded in HashiCorp's enterprise products. ▪ Using Sentinel ensures that your governance policies are actually being checked rather than just being listed in a spreadsheet. ▪ It supports fine-grained policies that use conditional logic. ▪ It includes a CLI that allows you to test and run policies. What is Sentinel?
  • 5. Copyright © 2020 HashiCorp Terraform Cloud and Terraform Enterprise ▪ A User Interface ▪ Workspace Management ▪ Team Management ▪ State Management ▪ Secure Variable Management ▪ Remote Runs and State ▪ VCS Integrations ▪ HTTP/JSON API ▪ Private Module Registry ▪ Configuration Editor ▪ Sentinel (policy as code) ▪ SSO via SAML Integration ▪ Audit Logging Terraform Cloud (TFC) includes the following advanced functionality that makes it easier for teams and organizations to use Terraform: Customers can install Terraform Enterprise (TFE) servers to self-host TFC in their own virtual private networks or in their data centers.
  • 6. Copyright © 2020 HashiCorp ▪ Sentinel policies are checked between the standard plan and apply steps of Terraform runs. ▪ Policies have different enforcement levels: advisory, soft-mandatory, and hard-mandatory. ▪ Violations prevent runs from being applied unless a user with sufficient authority overrides them. ▪ Sentinel policies can evaluate the attributes (arguments and exported attributes) of existing and new resources and data sources based on information from the current run: – the plan, the configuration, the current state, and other run data including cost estimates ▪ This ensures that resources comply with all policies before they are provisioned. Where is Sentinel Used in Terraform?
  • 7. Copyright © 2020 HashiCorp How Terraform Works Without Sentinel VCS Terraform Infrastructureplan & apply
  • 8. Copyright © 2020 HashiCorp How Terraform Works With Sentinel VCS Terraform Cloud Workspace Infrastructureplan Sentinel Policy Checks apply If cost estimates are enabled, they run right after the plan.
  • 9. Copyright © 2020 HashiCorp All Policy Checks Passed
  • 10. Copyright © 2020 HashiCorp ▪ HashiCorp customers are using Sentinel to implement governance policies like the following in Terraform Cloud/Enterprise: – Enforce security standards: ▪ Require all S3 buckets use the private ACL and be encrypted by KMS. ▪ Restrict which roles the AWS provider can assume. ▪ Blacklist/whitelist resources, data sources, providers, or provisioners. – Avoid excessive costs: ▪ Limit the sizes of VMs and Kubernetes clusters in public clouds. ▪ Limit the monthly spend of each Terraform workspace. – Enforce mandatory tags on resources provisioned by Terraform. – Mandate that all modules come from a Private Module Registry. – Enforce specific Terraform coding conventions. How Customers are Using Sentinel in Terraform
  • 11. Copyright © 2020 HashiCorp Two New Sentinel Features
  • 12. Copyright © 2020 HashiCorp ▪ A Sentinel Module defines Sentinel functions and rules in a file that can be used by Sentinel policies with a single import statement. ▪ This avoids the need to paste the functions into every policy that calls them, improving the reusability of Sentinel functions. ▪ Sentinel modules are registered in Sentinel CLI configuration files and in TFC/TFE policy set configuration files. ▪ The terraform-guides repository includes 5 "third-generation" modules: – tfplan-functions, tfstate-functions, tfconfig-functions, tfrun-functions, and aws-functions ▪ Each function is documented in a separate MD file. ▪ Note that these are NOT standard functions. Sentinel Modules
  • 13. Copyright © 2020 HashiCorp ▪ The new v2 versions of three Terraform Sentinel imports (tfplan, tfstate, and tfconfig) are aligned more closely with native Terraform 0.12 data structures. ▪ This makes the v2 imports easier to use than the v1 imports. ▪ Additionally, since resource instances are stored in a single flat map that spans across all Terraform modules and resource types, it is much easier to find all resources instances of a specific type or a sub-collection of them. ▪ However, there is a catch: – The v2 imports can only be used with Terraform 0.12. New v2 Versions of the Terraform Sentinel Imports
  • 14. Copyright © 2020 HashiCorp ▪ The tfplan/v2 gives data generated from Terraform plans. – https://www.terraform.io/docs/cloud/sentinel/import/tfplan-v2.html ▪ The tfconfig/v2 import gives data about the Terraform configuration. – https://www.terraform.io/docs/cloud/sentinel/import/tfconfig-v2.html ▪ The tfstate/v2 import gives data about the current state of a workspace. – https://www.terraform.io/docs/cloud/sentinel/import/tfstate-v2.html ▪ The tfrun import provides metadata for Terraform runs and their workspaces as well as cost estimate data. (There is no v2 version of it.) – https://www.terraform.io/docs/cloud/sentinel/import/tfrun.html Sentinel Imports in Terraform
  • 15. Copyright © 2020 HashiCorp The Evolution of Sentinel Policies
  • 16. Copyright © 2020 HashiCorp ▪ The first-generation policies were written in late 2018 and used the original Terraform Sentinel v1 imports. ▪ They had several short-comings, including the following: – Most of the policies did not print violation messages for resources that violated them. – They stopped evaluating conditions as soon as a single resource instance violated them. – They failed when resources that were being destroyed violated conditions. – Their use of default Sentinel output was overly verbose. The First-Generation Policies
  • 17. Copyright © 2020 HashiCorp ▪ The second-generation policies were written in 2019 and used the original Terraform Sentinel v1 imports: ▪ They made the following improvements: – They offloaded most processing from rules into some common parameterized functions. – Those common functions were written in a way that caused all violations of all rules to be reported. – They printed out the full address of each resource instance that did violate a policy. – By using a single main rule, they suppressed most of Sentinel’s default, overly verbose output. – They skipped resources that were being destroyed but not recreated. The Second-Generation Policies
  • 18. Copyright © 2020 HashiCorp ▪ The new third-generation policies were written in the spring of 2020 and use the new Terraform Sentinel v2 imports and Sentinel modules. ▪ They have the following advantages: – Their use of the v2 imports and the Sentinel filter expression makes it easier to restrict policies to specific operations performed by Terraform. – The common functions defined in Sentinel modules do not need to be pasted into policies that use them. – Most of the policies do not have any for loops of if/else conditionals. This makes the policies easier to understand and copy. – They can evaluate the value of any attribute of any resource or data source, even those that are deeply nested. ▪ However, since they do use the v2 imports, they can only be used with Terraform 0.12 The New Third-Generation Policies
  • 19. Copyright © 2020 HashiCorp Some Prototypical Third- Generation Sentinel Policies
  • 20. Copyright © 2020 HashiCorp ▪ I'll review four prototypical third-generation Sentinel policies in order of increasing sophistication: – restrict-ec2-instance-type.sentinel (AWS) – restrict-vm-cpu-and-memory.sentinel (VMware) – restrict-vm-disk-size.sentinel (VMware) – restrict-publishers-of-current-vms.sentinel (Azure) Some Prototypical Third-Generation Policies
  • 21. Copyright © 2020 HashiCorp The Third-Generation Common Functions
  • 22. Copyright © 2020 HashiCorp ▪ As mentioned earlier, there are third-generation Sentinel modules with common functions for each of the Terraform Sentinel imports. ▪ The tfplan and tfstate modules have the following functions: – Find functions that find resources, data sources, and blocks. – Filter functions that filter collections of resources, data sources, or blocks. These each return two maps: resources and messages. – The evaluate_attribute function that can evaluate any attribute of any resource, data source, or block, even if deeply nested. – The to_string and print_violation functions that are used by the other functions. ▪ There is also a Sentinel module with some AWS-specific functions. The Third-Generation Common Functions
  • 23. Copyright © 2020 HashiCorp Testing and Using the Third- Generation Sentinel Policies
  • 24. Copyright © 2020 HashiCorp ▪ All the third-generation Sentinel policies have test cases and mocks that support testing the policies with the Sentinel CLI ▪ Do the following: – Download the Sentinel CLI from the Sentinel Downloads page. – Unzip the zip file and place the sentinel binary in your path. – Fork the terraform-guides repository and clone your fork to your local machine. – Navigate to any of the cloud directories (aws, azure, gcp, or vmware) or to the cloud-agnostic directory. – Run sentinel test to test all policies for that cloud. – Run sentinel test -run=<partial_policy_name> -verbose to test individual policies, using a string that partially matches name. Testing Policies with the Sentinel CLI
  • 25. Copyright © 2020 HashiCorp { "modules": { "tfplan-functions": { "path": "../../../common-functions/tfplan-functions/ tfplan-functions.sentinel" } }, "mock": { "tfplan/v2": "mock-tfplan-pass.sentinel" }, "test": { "main": true } } An Example Test Case that References a Module
  • 26. Copyright © 2020 HashiCorp ▪ After successfully testing a policy with the CLI and possibly also on TFC itself, you will want to deploy it to your TFC/TFE organizations. ▪ If you have not already added the policy to a policy set in your organizations, do that at this time. ▪ Add the new policy to an existing policy set that is already applied against desired workspaces, or create a new policy set for the policy and apply that policy set to desired workspaces across your organizations. ▪ Also add any parameters the policy requires to your policy set. ▪ And add references to any Sentinel Modules that policies in it use. Deploying Policies in TFC or TFE
  • 27. Copyright © 2020 HashiCorp ▪ Here is an example policy set: module "tfplan-functions" { source = "../common-functions/tfplan-functions/tfplan -functions.sentinel" } policy "restrict-ec2-instance-type" { source = "./restrict-ec2-instance-type.sentinel" enforcement_level = "soft-mandatory" } Example Policy Set
  • 28. Copyright © 2020 HashiCorp Demo
  • 29. Copyright © 2020 HashiCorp ▪ Here are some useful Links ▪ Documentation – https://www.terraform.io/docs/cloud/sentinel/index.html – https://www.terraform.io/docs/cloud/sentinel/manage- policies.html – https://docs.hashicorp.com/sentinel ▪ Other Resources: – Blog for this webinar – Sentinel in Terraform v2 Workshop (including hands-on Instruqt track that teaches you how to write and test policies) Some Useful Links

Editor's Notes

  1. These slides are intended to accompany the Sentinel for Terraform v2 workshop They should be used with the Sentinel for Terraform v2 Instruqt track: https://instruqt.com/hashicorp/tracks/sentinel-for-terraform-v2
  2. Let's talk about Sentinel and how it fits into Terraform Cloud and Terraform Enterprise. We'll also discuss how customers are using Sentinel in TFC and TFE.
  3. Sentinel is a framework for implementing governance policies as code It has its own language It has a CLI for testing and running policies
  4. Let's level set about Terraform Cloud and Terraform Enterprise Note that Terraform Cloud (TFC) refers both to the actual application used and the implementation hosted by HashiCorp at app.terraform.io. Since TFE uses the TFC application, we will mostly just talk about TFC. But anything we say about TFC is true of TFE too except when we discuss very new features that have been released to TFC. But those new features generally end up in TFE within 4-6 weeks.
  5. Let's talk about where Sentinel is used in TFC and TFE. It is run between the plan and the apply of a run. If cost estimates are enabled for a workspace, the Sentinel policies are checked after the cost estimates are collected. "Arguments" are the inputs to Terraform resources and data sources. Each resource and data source also exports certain attributes that are computed during the apply. These are called "exported attributes". But since the arguments or a resource are also exported, it is common to use "attributes" to refer to the union of a resource's arguments and exported attributes.
  6. Here is how Terraform works without Sentinel.
  7. Here is how Terraform works with Sentinel. Note that if cost estimates are enabled for the workspace, they will run right after the plan.
  8. A screenshot from TFC showing that all policy checks passed for a run.
  9. Let's talk about some use cases for Sentinel in TFC and TFE.
  10. Let's spend some time discussing the Sentinel language.
  11. Sentinel modules allow for the reuse of Sentinel functions and rules. They are registered in Sentinel CLI configuration files and in TFC/TFE policy set configuration files.
  12. Sentinel has some builtin functions that you can use in any policy.
  13. This is a good point to discuss the Terraform-specific Sentinel imports. Terraform Cloud/Enterprise adds 4 Sentinel imports beyond the standard ones. This version of the workshop uses the v2 versions of the tfplan, tfconfig, and tfstate imports. The v2 versions are more closely aligned to Terraform 0.12's internal data structures. There is only 1 version of the tfrun import.
  14. Now we will do the first two workshop challenges on the Instruqt platform
  15. The first-generation policies had several limitations.
  16. The second-generation policies made many improvements.
  17. The new workshop exercises leverage the Instruqt platform and make solving the exercises much easier. Be sure to use the Sentinel Instruqt track that ends in v2, not the one that ends in v1.
  18. Now let's walk through the basic 8 step methodology of the Writing and Testing Sentinel Policies for Terraform guide.
  19. This slide gives the basic 8 step methodology of writing and testing Sentinel policies from the Writing and Testing Sentinel Policies for Terraform guide. We will focus on 5-7 in this workshop.
  20. Now let's walk through the basic 8 step methodology of the Writing and Testing Sentinel Policies for Terraform guide.
  21. After testing new Sentinel policies with the Sentinel CLI, you can test them in an organization on a TFC or TFE server.
  22. While we won't be using Sentinel in Terraform Cloud or Terraform Enterprise today, we did want to review this topic After all, that is where your Sentinel policies will really be running. You'll get a chance to complete and test some more Sentinel policies with the Sentinel CLI after this section.
  23. After testing new Sentinel policies with the Sentinel CLI, you can test them in an organization on a TFC or TFE server.
  24. The stanza at the top declares a Sentinel Modules with functions that can be called by Sentinel policies that import them. In this case, the file "tfplan-functions.sentinel" is being declared as the module "tfplan-functions". Recall that when we imported it in our policy, we gave it the alias "plan". We also indicate that the test case should use the mock-tfplan-pass.sentinel mock and that the main rule should evaluate to true. If using tfconfig/v2, tfstate/v2, or tfrun mock files, you need to specify the mock type accordingly (instead of using "tfplan/v2").
  25. After testing a policy with the Sentinel CLI and possibly in a TFC/TFE organization, you'll want to deploy it to your TFC organizations.
  26. You'll need to create policy sets that contain the policies you want to use in TFC or TFE You can now specify Sentinel modules in your policy sets, but the modules must be in or under the directory with the sentinel.hcl file at this time. In the near future, we will support loading of modules from remote locations.
  27. While we won't be using Sentinel in Terraform Cloud or Terraform Enterprise today, we did want to review this topic After all, that is where your Sentinel policies will really be running. You'll get a chance to complete and test some more Sentinel policies with the Sentinel CLI after this section.
  28. Thanks for attending the Sentinel in Terraform Workshop or reviewing these slides.