pub struct TerraformConfig { /* private fields */ }Expand description
Builder for constructing Terraform JSON configuration.
Produces a .tf.json file that Terraform can process identically
to an HCL .tf file.
Implementations§
Source§impl TerraformConfig
impl TerraformConfig
Sourcepub fn required_provider(self, name: &str, source: &str, version: &str) -> Self
pub fn required_provider(self, name: &str, source: &str, version: &str) -> Self
Add a required provider.
let config = TerraformConfig::new()
.required_provider("aws", "hashicorp/aws", "~> 5.0")
.required_provider("null", "hashicorp/null", "~> 3.0");Sourcepub fn backend(self, backend_type: &str, config: Value) -> Self
pub fn backend(self, backend_type: &str, config: Value) -> Self
Configure a backend for remote state storage.
let config = TerraformConfig::new()
.backend("s3", json!({
"bucket": "my-tf-state",
"key": "terraform.tfstate",
"region": "us-west-2"
}));Sourcepub fn provider(self, name: &str, config: Value) -> Self
pub fn provider(self, name: &str, config: Value) -> Self
Configure a provider.
let config = TerraformConfig::new()
.provider("aws", json!({ "region": "us-west-2" }));Sourcepub fn resource(self, resource_type: &str, name: &str, config: Value) -> Self
pub fn resource(self, resource_type: &str, name: &str, config: Value) -> Self
Add a managed resource.
let config = TerraformConfig::new()
.resource("aws_instance", "web", json!({
"ami": "ami-0c55b159",
"instance_type": "t3.micro"
}));Sourcepub fn data(self, data_type: &str, name: &str, config: Value) -> Self
pub fn data(self, data_type: &str, name: &str, config: Value) -> Self
Add a data source.
let config = TerraformConfig::new()
.data("aws_ami", "latest", json!({
"most_recent": true,
"owners": ["amazon"]
}));Sourcepub fn variable(self, name: &str, config: Value) -> Self
pub fn variable(self, name: &str, config: Value) -> Self
Add a variable.
let config = TerraformConfig::new()
.variable("region", json!({
"type": "string",
"default": "us-west-2",
"description": "AWS region"
}));Sourcepub fn output(self, name: &str, config: Value) -> Self
pub fn output(self, name: &str, config: Value) -> Self
Add an output.
let config = TerraformConfig::new()
.output("instance_id", json!({
"value": "${aws_instance.web.id}",
"description": "The instance ID"
}));Sourcepub fn local(self, name: &str, value: Value) -> Self
pub fn local(self, name: &str, value: Value) -> Self
Add a local value.
let config = TerraformConfig::new()
.local("common_tags", json!({
"Environment": "production",
"ManagedBy": "terraform-wrapper"
}));Sourcepub fn module(self, name: &str, config: Value) -> Self
pub fn module(self, name: &str, config: Value) -> Self
Add a module reference.
let config = TerraformConfig::new()
.module("vpc", json!({
"source": "terraform-aws-modules/vpc/aws",
"version": "~> 5.0",
"cidr": "10.0.0.0/16"
}));Sourcepub fn to_json_pretty(&self) -> Result<String>
pub fn to_json_pretty(&self) -> Result<String>
Serialize to a pretty-printed JSON string.
Sourcepub fn write_to(&self, path: impl AsRef<Path>) -> Result<()>
pub fn write_to(&self, path: impl AsRef<Path>) -> Result<()>
Write the configuration to a file as main.tf.json.
Creates parent directories if they don’t exist.
Sourcepub fn write_to_tempdir(&self) -> Result<TempDir>
pub fn write_to_tempdir(&self) -> Result<TempDir>
Write the configuration to a temporary directory as main.tf.json.
Returns the TempDir which will be cleaned up when dropped.
Use .path() to get the directory path for Terraform::builder().working_dir().
Trait Implementations§
Source§impl Clone for TerraformConfig
impl Clone for TerraformConfig
Source§fn clone(&self) -> TerraformConfig
fn clone(&self) -> TerraformConfig
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for TerraformConfig
impl Debug for TerraformConfig
Source§impl Default for TerraformConfig
impl Default for TerraformConfig
Source§fn default() -> TerraformConfig
fn default() -> TerraformConfig
Returns the “default value” for a type. Read more
Auto Trait Implementations§
impl Freeze for TerraformConfig
impl RefUnwindSafe for TerraformConfig
impl Send for TerraformConfig
impl Sync for TerraformConfig
impl Unpin for TerraformConfig
impl UnsafeUnpin for TerraformConfig
impl UnwindSafe for TerraformConfig
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more