Resource Blocks #
Everything you can set is defined as a Resource Block. Resource blocks have the following format.
resource "resource_type" "resource_name" {
ensure = "present"
... other key = value entries ...
}
For resources that are identified using a single string (Logins, Agent Operators, Databases, etc.), the resource_name is often used to identify the resource. It can be overridden using the appropriate attribute. Please see the Resource Block Schema section.
This is an example Resource Block that creates a SQL Server agent operator:
resource "agent_operator" "june" {
ensure = "present"
name = "june"
email_address = "june@test.com"
}
A shortened version might look like this:
resource "agent_operator" "june" {
email_address = "june@test.com"
}
A fake sample showing more data types:
resource "fake_resource" "fake" {
ensure = "present"
string_val = "value"
int_val = 37
bool_val = true
string_array = ["a", "b", "c"]
}
Multiline strings #
These can be constructed using a heredoc format. Avoid any spaces after the <<EOF.
resource "agent_job_step" "step two" {
job = "test"
id = 1
name = "step 2"
command = <<EOF
SELECT 1
SELECT 2
EOF
}
Notes:
- Avoid any spaces before or after the
EOFor between the<<and theEOF. This often trips me up but it’s buried in the library I use. - The
EOFcan be any unique string not appearing incommand. - The ending
EOFneeds to be on a line by itself but can have leading white space. - The
commandtext will be “dedented” to remove consistent white space at the start of each line. That makes it easier to format the command. You can indent it in theHCLfile and consistent leading white space will be removed before passing to SQL Server.