Link Search Menu Expand Document

local

local_file/

== local_file

hello -

preexisting_file -

destroy.sh

            #!/bin/bash
../../../bin/destroy.sh
 

main.tf

            # Summary: Create and manage a local file.

# Documentation: https://www.terraform.io/docs/language/settings/index.html
terraform {
  required_version = ">= 1.0.0"
}

# Documentation: https://registry.terraform.io/providers/hashicorp/local/latest/docs/resources/file
resource "local_file" "changeme_local_file_hello" {
  content  = "Hello terraform local!"
  filename = "${path.module}/changeme_local_file_hello_${terraform.workspace}.txt"
}
 

run.sh

            #!/bin/bash
../../../bin/apply.sh

 

changeme_preexisting_file.txt

            Some file content
 

destroy.sh

            #!/bin/bash
../../../bin/destroy.sh
 

main.tf

            # Summary: Take an existing file into a Terraform state, using data.local_file's configuration.

# Documentation: https://www.terraform.io/docs/language/settings/index.html
terraform {
  required_version = ">= 1.0.0"
}

# Documentation: https://registry.terraform.io/providers/hashicorp/local/latest/docs/data-sources/file
data "local_file" "changeme_local_file_preexisting_file" {
  filename = "${path.module}/changeme_preexisting_file.txt"
}

# Documentation: https://www.terraform.io/docs/language/values/outputs.html
output "changeme_preexisting_file_content" {
  value = data.local_file.changeme_local_file_preexisting_file.content
}
 

run.sh

            #!/bin/bash
../../../bin/apply.sh

 

local_file/hello/

destroy.sh

            #!/bin/bash
../../../bin/destroy.sh
 

main.tf

            # Summary: Create and manage a local file.

# Documentation: https://www.terraform.io/docs/language/settings/index.html
terraform {
  required_version = ">= 1.0.0"
}

# Documentation: https://registry.terraform.io/providers/hashicorp/local/latest/docs/resources/file
resource "local_file" "changeme_local_file_hello" {
  content  = "Hello terraform local!"
  filename = "${path.module}/changeme_local_file_hello_${terraform.workspace}.txt"
}
 

run.sh

            #!/bin/bash
../../../bin/apply.sh

 

local_file/preexisting_file/

changeme_preexisting_file.txt

            Some file content
 

destroy.sh

            #!/bin/bash
../../../bin/destroy.sh
 

main.tf

            # Summary: Take an existing file into a Terraform state, using data.local_file's configuration.

# Documentation: https://www.terraform.io/docs/language/settings/index.html
terraform {
  required_version = ">= 1.0.0"
}

# Documentation: https://registry.terraform.io/providers/hashicorp/local/latest/docs/data-sources/file
data "local_file" "changeme_local_file_preexisting_file" {
  filename = "${path.module}/changeme_preexisting_file.txt"
}

# Documentation: https://www.terraform.io/docs/language/values/outputs.html
output "changeme_preexisting_file_content" {
  value = data.local_file.changeme_local_file_preexisting_file.content
}
 

run.sh

            #!/bin/bash
../../../bin/apply.sh

 

null_resource/for_each/

destroy.sh

            #!/bin/bash
../../../bin/destroy.sh
 

main.tf

            # Summary: Local null resource that iterates over a map using for_each

# Documentation: https://www.terraform.io/docs/language/settings/index.html
terraform {
  required_version = ">= 1.0.0"
}


# Documentation: https://www.terraform.io/docs/language/values/locals.html
locals {
  # Documentation: https://www.terraform.io/docs/language/expressions/types.html#maps-objects
  map1 = {
    item1 = {
      name1 = "item1value1"
      name2 = "item1value2"
    }
    item2 = {
      name1 = "item2value1"
      name2 = "item2value2"
    }
  }
}

# Documentation: https://registry.terraform.io/providers/hashicorp/null/latest/docs/resources/resource
resource "null_resource" "changeme_null_resource_foreach" {
  # Documentation: https://www.terraform.io/docs/language/meta-arguments/for_each.html
  for_each = local.map1
  # Documentation: https://www.terraform.io/docs/language/resources/provisioners/local-exec.html
  provisioner "local-exec" {
    command = "echo ${each.key} ${each.value.name1} ${each.value.name2}"
  }
}
 

run.sh

            #!/bin/bash
../../../bin/apply.sh

 

null_resource/simple/

destroy.sh

            #!/bin/bash
../../../bin/destroy.sh
 

main.tf

            # Summary: Simple example of local null_resource that runs a command

# Documentation: https://www.terraform.io/docs/language/settings/index.html
terraform {
  required_version = ">= 1.0.0"
}

# Documentation: https://registry.terraform.io/providers/hashicorp/null/latest/docs/resources/resource
resource "null_resource" "changeme_null_resource_simple" {
  provisioner "local-exec" {
    command = "echo Hello World"
  }
}
 

run.sh

            #!/bin/bash
../../../bin/apply.sh