Terraform and Infrastructure as Code
This page covers three tools: Terraform, Packer, and Crossplane. The practice run uses Terraform with local files, builds a Docker image with Packer, and renders a Crossplane composition on your own machine. It needs no cloud account. It comes after AWS Databases and Serverless and before Ansible.
52 min read52 মিনিটে পড়া যায় · 7 sections7টি সেকশন · 57 sources57টি সোর্স · updated Nov 2026আপডেট: Nov 2026
Plan before you applyapply-এর আগে plan দেখুন
Follow write, plan and apply, then edit the config and see the same plan command show different counts.write, plan আর apply অনুসরণ করুন, তারপর config বদলান আর দেখুন একই plan command আলাদা সংখ্যা দেখায়।
You’ll learnআপনি শিখবেন
- Plan compares the config to the stateplan config-কে state-এর সঙ্গে তুলনা করে
- What 1 to add, 0 to change, 0 to destroy means1 to add, 0 to change, 0 to destroy-এর মানে
- Apply changes the real world and the stateapply বাস্তব জগৎ আর state বদলায়
- The same plan command gives different countsএকই plan command আলাদা সংখ্যা দেয়
- Why the state file is sensitivestate file কেন সংবেদনশীল
What it is
Terraform. Terraform is an infrastructure as code tool that lets you build, change, and version cloud and on-prem resources safely and efficiently Source 1সোর্স 1. You define the resources in human-readable configuration files that you can version, reuse, and share Source 1সোর্স 1. Terraform creates and manages the resources through the APIs of cloud platforms and other services Source 1সোর্স 1.
The Terraform workflow. The core workflow has three stages: write, plan, and apply Source 1সোর্স 1. In the plan stage, Terraform describes the infrastructure that it will create, update, or destroy Source 1সোর্স 1. In the apply stage, Terraform performs the proposed operations after approval, in the correct order Source 1সোর্স 1.
Packer. Packer is a community tool for creating identical machine images for multiple platforms from a single source configuration Source 30সোর্স 30. A machine image is a single static unit that contains a pre-configured operating system and installed software Source 30সোর্স 30. Packer does not replace configuration management like Chef or Puppet Source 30সোর্স 30.
Crossplane. Crossplane is a control plane framework for platform engineering Source 43সোর্স 43. It lets you build control planes to manage your cloud native software Source 43সোর্স 43. A control plane is software that controls other software Source 43সোর্স 43.
সহজ English
Terraform. Terraform is an infrastructure as code tool that lets you build, change, and version cloud and on-prem resources safely and efficiently Source 1সোর্স 1. You define the resources in human-readable configuration files that you can version, reuse, and share Source 1সোর্স 1. Terraform creates and manages the resources through the APIs of cloud platforms and other services Source 1সোর্স 1.
The Terraform workflow. The core workflow has three stages: write, plan, and apply Source 1সোর্স 1. In the plan stage, Terraform describes the infrastructure that it will create, update, or destroy Source 1সোর্স 1. In the apply stage, Terraform performs the proposed operations after approval, in the correct order Source 1সোর্স 1.
Packer. Packer is a community tool for creating identical machine images for multiple platforms from a single source configuration Source 30সোর্স 30. A machine image is a single static unit that contains a pre-configured operating system and installed software Source 30সোর্স 30. Packer does not replace configuration management like Chef or Puppet Source 30সোর্স 30.
Crossplane. Crossplane is a control plane framework for platform engineering Source 43সোর্স 43. It lets you build control planes to manage your cloud native software Source 43সোর্স 43. A control plane is software that controls other software Source 43সোর্স 43.
বাংলা ব্যাখ্যা
Terraform। Terraform হলো একটা infrastructure as code tool, যা দিয়ে আপনি cloud আর on-prem resource নিরাপদে ও দক্ষভাবে build, change আর version করতে পারেন Source 1সোর্স 1। আপনি resource-গুলো এমন মানুষ-পাঠযোগ্য configuration file-এ লেখেন, যা version করা, আবার ব্যবহার করা আর অন্যদের সঙ্গে ভাগ করা যায় Source 1সোর্স 1। Terraform cloud platform আর অন্য service-এর API দিয়ে resource তৈরি ও পরিচালনা করে Source 1সোর্স 1।
Terraform-এর workflow। মূল workflow-এর তিনটা ধাপ: write, plan আর apply Source 1সোর্স 1। plan ধাপে Terraform বর্ণনা করে, সে কোন infrastructure তৈরি, update বা destroy করবে Source 1সোর্স 1। apply ধাপে Terraform অনুমোদনের পর প্রস্তাবিত কাজগুলো সঠিক ক্রমে করে Source 1সোর্স 1।
Packer। Packer হলো একটা community tool, যা একটাই source configuration থেকে একাধিক platform-এর জন্য identical machine image তৈরি করে Source 30সোর্স 30। machine image হলো একটা একক static unit, যাতে আগে থেকে সাজানো operating system আর install করা software থাকে Source 30সোর্স 30। Packer Chef বা Puppet-এর মতো configuration management-এর জায়গা নেয় না Source 30সোর্স 30।
Crossplane। Crossplane হলো platform engineering-এর জন্য একটা control plane framework Source 43সোর্স 43। এটা দিয়ে আপনি আপনার cloud native software পরিচালনার জন্য control plane বানাতে পারেন Source 43সোর্স 43। control plane হলো এমন software, যা অন্য software-কে নিয়ন্ত্রণ করে Source 43সোর্স 43।
How it works
The configuration language. The main purpose of the Terraform language is declaring resources, which represent infrastructure objects Source 2সোর্স 2. Blocks are containers for other content Source 2সোর্স 2. Arguments assign a value to a name Source 2সোর্স 2. Expressions represent a value, either literally or by referencing and combining other values Source 2সোর্স 2. The language is declarative, describing an intended goal rather than the steps to reach that goal Source 2সোর্স 2.
The resource block defines a piece of infrastructure Source 3সোর্স 3. The arguments that an individual resource supports are determined by the provider Source 3সোর্স 3. The variable block is similar to a function argument in other programming languages Source 7সোর্স 7. A validation block can refuse a value Source 7সোর্স 7. The output block lets you expose information about your infrastructure Source 8সোর্স 8. One use of an output is passing information from a Terraform operation to an automation tool Source 8সোর্স 8. The locals block is similar to function-scoped variables in other programming languages Source 9সোর্স 9. The data block fetches data about a resource from the provider without provisioning an associated infrastructure object Source 10সোর্স 10.
Providers and the lock file. Terraform relies on plugins called providers to interact with cloud providers, SaaS providers, and other APIs Source 4সোর্স 4. Every resource type is implemented by a provider Source 4সোর্স 4. Providers are distributed separately from Terraform itself, and each has its own version numbers Source 4সোর্স 4. A configuration declares the providers that it requires in a required_providers block Source 5সোর্স 5. Running terraform init locally installs a provider and updates the dependency lock file Source 5সোর্স 5. The lock file is always named .terraform.lock.hcl Source 6সোর্স 6. You should include it in your version control repository Source 6সোর্স 6. In production, HashiCorp recommends constraining the acceptable provider versions Source 4সোর্স 4.
The commands. The terraform init command initializes a working directory that contains Terraform configuration files Source 18সোর্স 18. It is the first command that you should run after writing a new configuration or cloning an existing one Source 18সোর্স 18. It is safe to run it multiple times Source 18সোর্স 18. The terraform fmt command formats configuration files to the canonical format and style Source 20সোর্স 20. The terraform validate command checks that a configuration is syntactically valid and internally consistent Source 19সোর্স 19. It does not validate remote services Source 19সোর্স 19. It needs an initialized working directory Source 19সোর্স 19. HashiCorp's style guide says to run terraform fmt and terraform validate before committing code Source 28সোর্স 28.
The terraform plan command creates an execution plan, which lets you preview the changes that Terraform plans to make Source 21সোর্স 21. By default, it reads the current state of existing remote objects Source 21সোর্স 21. It compares the configuration to the prior state Source 21সোর্স 21. It proposes a set of change actions that should, if applied, make the remote objects match the configuration Source 21সোর্স 21. Without the -out option, it creates a speculative plan Source 21সোর্স 21. You should always re-check the final non-speculative plan before applying Source 21সোর্স 21. With -detailed-exitcode, the command returns a detailed exit code when it exits Source 21সোর্স 21. The terraform apply command executes the operations of a plan Source 22সোর্স 22. Without a saved plan file, it creates a new plan and prompts you to approve it Source 22সোর্স 22. With a saved plan file, it does not prompt Source 22সোর্স 22. The terraform destroy command deprovisions all objects that a configuration manages Source 23সোর্স 23.
State. Terraform must store state about your workspace's managed infrastructure and configuration Source 11সোর্স 11. It uses state to map real world resources to your configuration Source 11সোর্স 11. Before any operation, Terraform does a refresh to update the state with the real infrastructure Source 11সোর্স 11. By default, the state is a local file named terraform.tfstate Source 11সোর্স 11. It is a JSON text file, and you should not edit it directly Source 11সোর্স 11. With remote state, Terraform writes the state data to a remote data store that a whole team can share Source 12সোর্স 12. If the backend supports it, Terraform locks the state for all operations that could write state Source 13সোর্স 13. The lock prevents others from corrupting the state Source 13সোর্স 13. If locking fails, Terraform does not continue Source 13সোর্স 13.
State and plan files can hold secrets Source 14সোর্স 14. A local state file is a plaintext file Source 14সোর্স 14. HashiCorp says to treat it as sensitive data and to keep it out of Git workflows Source 14সোর্স 14. It also says to avoid storing the state in a version control system or other storage that does not support state locking and secure access control Source 11সোর্স 11.
Reuse and control. A module is a collection of resources that Terraform manages together Source 15সোর্স 15. The configuration in the root directory is the root module Source 15সোর্স 15. Modules that you call with module blocks are child modules Source 15সোর্স 15. The for_each meta-argument manages several similar objects without a separate block for each Source 17সোর্স 17. It accepts a map or a set of strings Source 17সোর্স 17.
By default, when an argument cannot change in place, Terraform destroys the object and then creates a replacement Source 16সোর্স 16. The create_before_destroy rule reverses that order Source 16সোর্স 16. With prevent_destroy set to true, Terraform rejects plans that would destroy the object Source 16সোর্স 16. That rule does not stop the destruction when you remove the resource's configuration Source 16সোর্স 16. The ignore_changes argument lists attributes that Terraform should ignore when it plans updates Source 16সোর্স 16.
Reading a plan, and tests. The terraform show command provides human-readable output from a state or plan file Source 24সোর্স 24. The apply page says to inspect a saved plan file with it before applying Source 22সোর্স 22. With the -json flag, it generates machine-readable output Source 24সোর্স 24. For a plan file, the JSON holds the plan, the configuration, and the current state Source 24সোর্স 24. With -json, sensitive values in the state show in plain text Source 24সোর্স 24. Terraform can output a machine-readable JSON representation of a plan file's changes Source 25সোর্স 25. The same page says to use terraform show -json to produce it Source 25সোর্স 25.
Terraform tests let authors validate that module configuration updates do not introduce breaking changes Source 26সোর্স 26. Tests run against test-specific, short-lived resources Source 26সোর্স 26. Terraform finds test files by their extension, .tftest.hcl or .tftest.json Source 26সোর্স 26. A test file has one or more run blocks Source 26সোর্স 26. A run block can hold assert blocks Source 26সোর্স 26. By default, a run block applies the configuration, which creates real infrastructure Source 26সোর্স 26. With command = plan, a run block creates no infrastructure Source 26সোর্স 26. The expect_failures attribute lists objects that should fail their custom conditions Source 26সোর্স 26. Terraform v1.7.0 added the ability to mock data that providers return during a test Source 26সোর্স 26.
The terraform test command searches the current directory and the testing directory for test files and runs them Source 27সোর্স 27. The default testing directory is named tests Source 27সোর্স 27. Each test file keeps its state in memory, apart from the state of the configuration under test Source 27সোর্স 27. After a test file has run, Terraform tries to destroy any infrastructure that is left Source 27সোর্স 27. The command can create real infrastructure that can cost money Source 27সোর্স 27. The -json option displays machine-readable JSON output, and the -junit-xml option saves a test report in JUnit XML format Source 27সোর্স 27.
Packer. Packer reads and applies configurations defined in HCL template files Source 32সোর্স 32. When you pass a directory, Packer parses every file whose name ends in .pkr.hcl or .pkr.json Source 32সোর্স 32. A template defines one or more builds Source 31সোর্স 31. A build is a single task that produces an artifact for a single platform Source 31সোর্স 31. A builder creates a machine image for a single platform Source 31সোর্স 31. Provisioners install and configure software in a running machine before it becomes a static artifact Source 31সোর্স 31. A post-processor takes the result of a builder or another post-processor and creates a new artifact Source 31সোর্স 31. An artifact is the result of a single build Source 31সোর্স 31.
The source block defines reusable builder configuration Source 33সোর্স 33. The build block says which builders to run, how to provision them, and what post-processing to do Source 34সোর্স 34. The provisioner block defines how to configure a provisioner Source 35সোর্স 35. The post-processor block defines how to configure a post-processor Source 36সোর্স 36. The packer init command downloads and installs the plugins that the required_plugins block lists Source 37সোর্স 37. The packer validate command checks the syntax and configuration of a template Source 39সোর্স 39. It returns a zero exit status on success and a non-zero exit status on failure Source 39সোর্স 39. The packer build command runs all the builds of a template Source 38সোর্স 38. The builds run in parallel unless the template says otherwise Source 38সোর্স 38.
The shell provisioner runs shell scripts on the machine that Packer builds Source 40সোর্স 40. The docker builder builds Docker images using Docker Source 41সোর্স 41. It starts a container, runs the provisioners in it, then exports the container or commits the image Source 41সোর্স 41. Packer builds the container without a Dockerfile Source 41সোর্স 41. The builder needs a machine with Docker Engine installed Source 41সোর্স 41. With commit set to true, Packer commits the container to an image instead of exporting it Source 41সোর্স 41. The pull option defaults to true, so Packer pulls the base image first Source 41সোর্স 41. The docker-tag post-processor tags a committed artifact of the docker builder into a repository Source 42সোর্স 42.
Crossplane. Control planes expose an API Source 43সোর্স 43. You use the API to tell the control plane what software to configure and how, which is your desired state Source 43সোর্স 43. If the software drifts from the desired state, the control plane corrects the drift Source 43সোর্স 43. Crossplane is built on Kubernetes Source 43সোর্স 43. It has four major components: Composition, managed resources, operations, and a package manager Source 43সোর্স 43. Composition lets you build custom APIs Source 43সোর্স 43. With Crossplane you configure a pipeline of functions instead of writing a controller Source 43সোর্স 43. The functions return declarative configuration that Crossplane should apply Source 43সোর্স 43.
A composite resource definition (XRD) defines the schema for a custom API Source 44সোর্স 44. Users create composite resources (XRs) with the schema of an XRD Source 44সোর্স 44. A composition is a template for creating several Kubernetes resources as a single composite resource Source 45সোর্স 45. A composite resource represents a set of Kubernetes resources as a single Kubernetes object Source 46সোর্স 46. Providers enable Crossplane to provision infrastructure on an external service Source 47সোর্স 47. A managed resource represents an external service in a provider Source 49সোর্স 49. Functions extend Crossplane with new ways to configure composition Source 48সোর্স 48. The tutorial of the Crossplane docs creates an App custom resource that Crossplane turns into a Deployment and a Service Source 50সোর্স 50.
The Crossplane CLI is a single standalone binary Source 51সোর্স 51. Most Crossplane CLI commands are independent of Kubernetes Source 51সোর্স 51. The composition render command shows what resources a composition would create or change Source 52সোর্স 52. By default, it runs composition functions using Docker Source 52সোর্স 52. The resource validate command checks resources against the schemas of XRDs, CRDs, providers, functions, and configurations Source 52সোর্স 52. It also detects unknown fields Source 52সোর্স 52. The docs mark the command as beta Source 52সোর্স 52.
সহজ English
The configuration language. The main purpose of the Terraform language is declaring resources, which represent infrastructure objects Source 2সোর্স 2. Blocks are containers for other content Source 2সোর্স 2. Arguments assign a value to a name Source 2সোর্স 2. Expressions represent a value, either literally or by referencing and combining other values Source 2সোর্স 2. The language is declarative, describing an intended goal rather than the steps to reach that goal Source 2সোর্স 2.
The resource block defines a piece of infrastructure Source 3সোর্স 3. The arguments that an individual resource supports are determined by the provider Source 3সোর্স 3. The variable block is similar to a function argument in other programming languages Source 7সোর্স 7. A validation block can refuse a value Source 7সোর্স 7. The output block lets you expose information about your infrastructure Source 8সোর্স 8. One use of an output is passing information from a Terraform operation to an automation tool Source 8সোর্স 8. The locals block is similar to function-scoped variables in other programming languages Source 9সোর্স 9. The data block fetches data about a resource from the provider without provisioning an associated infrastructure object Source 10সোর্স 10.
Providers and the lock file. Terraform relies on plugins called providers to interact with cloud providers, SaaS providers, and other APIs Source 4সোর্স 4. Every resource type is implemented by a provider Source 4সোর্স 4. Providers are distributed separately from Terraform itself, and each has its own version numbers Source 4সোর্স 4. A configuration declares the providers that it requires in a required_providers block Source 5সোর্স 5. Running terraform init locally installs a provider and updates the dependency lock file Source 5সোর্স 5. The lock file is always named .terraform.lock.hcl Source 6সোর্স 6. You should include it in your version control repository Source 6সোর্স 6. In production, HashiCorp recommends constraining the acceptable provider versions Source 4সোর্স 4.
The commands. The terraform init command initializes a working directory that contains Terraform configuration files Source 18সোর্স 18. It is the first command that you should run after writing a new configuration or cloning an existing one Source 18সোর্স 18. It is safe to run it multiple times Source 18সোর্স 18. The terraform fmt command formats configuration files to the canonical format and style Source 20সোর্স 20. The terraform validate command checks that a configuration is syntactically valid and internally consistent Source 19সোর্স 19. It does not validate remote services Source 19সোর্স 19. It needs an initialized working directory Source 19সোর্স 19. HashiCorp's style guide says to run terraform fmt and terraform validate before committing code Source 28সোর্স 28.
The terraform plan command creates an execution plan, which lets you preview the changes that Terraform plans to make Source 21সোর্স 21. By default, it reads the current state of existing remote objects Source 21সোর্স 21. It compares the configuration to the prior state Source 21সোর্স 21. It proposes a set of change actions that should, if applied, make the remote objects match the configuration Source 21সোর্স 21. Without the -out option, it creates a speculative plan Source 21সোর্স 21. You should always re-check the final non-speculative plan before applying Source 21সোর্স 21. With -detailed-exitcode, the command returns a detailed exit code when it exits Source 21সোর্স 21. The terraform apply command executes the operations of a plan Source 22সোর্স 22. Without a saved plan file, it creates a new plan and prompts you to approve it Source 22সোর্স 22. With a saved plan file, it does not prompt Source 22সোর্স 22. The terraform destroy command deprovisions all objects that a configuration manages Source 23সোর্স 23.
State. Terraform must store state about your workspace's managed infrastructure and configuration Source 11সোর্স 11. It uses state to map real world resources to your configuration Source 11সোর্স 11. Before any operation, Terraform does a refresh to update the state with the real infrastructure Source 11সোর্স 11. By default, the state is a local file named terraform.tfstate Source 11সোর্স 11. It is a JSON text file, and you should not edit it directly Source 11সোর্স 11. With remote state, Terraform writes the state data to a remote data store that a whole team can share Source 12সোর্স 12. If the backend supports it, Terraform locks the state for all operations that could write state Source 13সোর্স 13. The lock prevents others from corrupting the state Source 13সোর্স 13. If locking fails, Terraform does not continue Source 13সোর্স 13.
State and plan files can hold secrets Source 14সোর্স 14. A local state file is a plaintext file Source 14সোর্স 14. HashiCorp says to treat it as sensitive data and to keep it out of Git workflows Source 14সোর্স 14. It also says to avoid storing the state in a version control system or other storage that does not support state locking and secure access control Source 11সোর্স 11.
Reuse and control. A module is a collection of resources that Terraform manages together Source 15সোর্স 15. The configuration in the root directory is the root module Source 15সোর্স 15. Modules that you call with module blocks are child modules Source 15সোর্স 15. The for_each meta-argument manages several similar objects without a separate block for each Source 17সোর্স 17. It accepts a map or a set of strings Source 17সোর্স 17.
By default, when an argument cannot change in place, Terraform destroys the object and then creates a replacement Source 16সোর্স 16. The create_before_destroy rule reverses that order Source 16সোর্স 16. With prevent_destroy set to true, Terraform rejects plans that would destroy the object Source 16সোর্স 16. That rule does not stop the destruction when you remove the resource's configuration Source 16সোর্স 16. The ignore_changes argument lists attributes that Terraform should ignore when it plans updates Source 16সোর্স 16.
Reading a plan, and tests. The terraform show command provides human-readable output from a state or plan file Source 24সোর্স 24. The apply page says to inspect a saved plan file with it before applying Source 22সোর্স 22. With the -json flag, it generates machine-readable output Source 24সোর্স 24. For a plan file, the JSON holds the plan, the configuration, and the current state Source 24সোর্স 24. With -json, sensitive values in the state show in plain text Source 24সোর্স 24. Terraform can output a machine-readable JSON representation of a plan file's changes Source 25সোর্স 25. The same page says to use terraform show -json to produce it Source 25সোর্স 25.
Terraform tests let authors validate that module configuration updates do not introduce breaking changes Source 26সোর্স 26. Tests run against test-specific, short-lived resources Source 26সোর্স 26. Terraform finds test files by their extension, .tftest.hcl or .tftest.json Source 26সোর্স 26. A test file has one or more run blocks Source 26সোর্স 26. A run block can hold assert blocks Source 26সোর্স 26. By default, a run block applies the configuration, which creates real infrastructure Source 26সোর্স 26. With command = plan, a run block creates no infrastructure Source 26সোর্স 26. The expect_failures attribute lists objects that should fail their custom conditions Source 26সোর্স 26. Terraform v1.7.0 added the ability to mock data that providers return during a test Source 26সোর্স 26.
The terraform test command searches the current directory and the testing directory for test files and runs them Source 27সোর্স 27. The default testing directory is named tests Source 27সোর্স 27. Each test file keeps its state in memory, apart from the state of the configuration under test Source 27সোর্স 27. After a test file has run, Terraform tries to destroy any infrastructure that is left Source 27সোর্স 27. The command can create real infrastructure that can cost money Source 27সোর্স 27. The -json option displays machine-readable JSON output, and the -junit-xml option saves a test report in JUnit XML format Source 27সোর্স 27.
Packer. Packer reads and applies configurations defined in HCL template files Source 32সোর্স 32. When you pass a directory, Packer parses every file whose name ends in .pkr.hcl or .pkr.json Source 32সোর্স 32. A template defines one or more builds Source 31সোর্স 31. A build is a single task that produces an artifact for a single platform Source 31সোর্স 31. A builder creates a machine image for a single platform Source 31সোর্স 31. Provisioners install and configure software in a running machine before it becomes a static artifact Source 31সোর্স 31. A post-processor takes the result of a builder or another post-processor and creates a new artifact Source 31সোর্স 31. An artifact is the result of a single build Source 31সোর্স 31.
The source block defines reusable builder configuration Source 33সোর্স 33. The build block says which builders to run, how to provision them, and what post-processing to do Source 34সোর্স 34. The provisioner block defines how to configure a provisioner Source 35সোর্স 35. The post-processor block defines how to configure a post-processor Source 36সোর্স 36. The packer init command downloads and installs the plugins that the required_plugins block lists Source 37সোর্স 37. The packer validate command checks the syntax and configuration of a template Source 39সোর্স 39. It returns a zero exit status on success and a non-zero exit status on failure Source 39সোর্স 39. The packer build command runs all the builds of a template Source 38সোর্স 38. The builds run in parallel unless the template says otherwise Source 38সোর্স 38.
The shell provisioner runs shell scripts on the machine that Packer builds Source 40সোর্স 40. The docker builder builds Docker images using Docker Source 41সোর্স 41. It starts a container, runs the provisioners in it, then exports the container or commits the image Source 41সোর্স 41. Packer builds the container without a Dockerfile Source 41সোর্স 41. The builder needs a machine with Docker Engine installed Source 41সোর্স 41. With commit set to true, Packer commits the container to an image instead of exporting it Source 41সোর্স 41. The pull option defaults to true, so Packer pulls the base image first Source 41সোর্স 41. The docker-tag post-processor tags a committed artifact of the docker builder into a repository Source 42সোর্স 42.
Crossplane. Control planes expose an API Source 43সোর্স 43. You use the API to tell the control plane what software to configure and how, which is your desired state Source 43সোর্স 43. If the software drifts from the desired state, the control plane corrects the drift Source 43সোর্স 43. Crossplane is built on Kubernetes Source 43সোর্স 43. It has four major components: Composition, managed resources, operations, and a package manager Source 43সোর্স 43. Composition lets you build custom APIs Source 43সোর্স 43. With Crossplane you configure a pipeline of functions instead of writing a controller Source 43সোর্স 43. The functions return declarative configuration that Crossplane should apply Source 43সোর্স 43.
A composite resource definition (XRD) defines the schema for a custom API Source 44সোর্স 44. Users create composite resources (XRs) with the schema of an XRD Source 44সোর্স 44. A composition is a template for creating several Kubernetes resources as a single composite resource Source 45সোর্স 45. A composite resource represents a set of Kubernetes resources as a single Kubernetes object Source 46সোর্স 46. Providers enable Crossplane to provision infrastructure on an external service Source 47সোর্স 47. A managed resource represents an external service in a provider Source 49সোর্স 49. Functions extend Crossplane with new ways to configure composition Source 48সোর্স 48. The tutorial of the Crossplane docs creates an App custom resource that Crossplane turns into a Deployment and a Service Source 50সোর্স 50.
The Crossplane CLI is a single standalone binary Source 51সোর্স 51. Most Crossplane CLI commands are independent of Kubernetes Source 51সোর্স 51. The composition render command shows what resources a composition would create or change Source 52সোর্স 52. By default, it runs composition functions using Docker Source 52সোর্স 52. The resource validate command checks resources against the schemas of XRDs, CRDs, providers, functions, and configurations Source 52সোর্স 52. It also detects unknown fields Source 52সোর্স 52. The docs mark the command as beta Source 52সোর্স 52.
বাংলা ব্যাখ্যা
configuration language। Terraform language-এর মূল উদ্দেশ্য resource ঘোষণা করা, যা infrastructure object-কে বোঝায় Source 2সোর্স 2। block হলো অন্য content-এর container Source 2সোর্স 2। argument একটা নামে একটা মান বসায় Source 2সোর্স 2। expression একটা মান বোঝায়, সরাসরি লিখে বা অন্য মান উল্লেখ ও জোড়া দিয়ে Source 2সোর্স 2। language-টা declarative: লক্ষ্যে পৌঁছানোর ধাপ নয়, কাঙ্ক্ষিত লক্ষ্য বর্ণনা করে Source 2সোর্স 2।
resource block একটা infrastructure-এর অংশ সংজ্ঞায়িত করে Source 3সোর্স 3। একটা resource কোন argument সমর্থন করে, তা provider ঠিক করে Source 3সোর্স 3। variable block অন্য programming language-এর function argument-এর মতো Source 7সোর্স 7। একটা validation block কোনো মান নাকচ করতে পারে Source 7সোর্স 7। output block আপনার infrastructure সম্পর্কে তথ্য প্রকাশ করে Source 8সোর্স 8। output-এর একটা ব্যবহার হলো Terraform-এর একটা operation থেকে একটা automation tool-এ তথ্য পাঠানো Source 8সোর্স 8। locals block অন্য programming language-এর function-scoped variable-এর মতো Source 9সোর্স 9। data block provider থেকে একটা resource সম্পর্কে data আনে, কোনো infrastructure object তৈরি না করে Source 10সোর্স 10।
provider আর lock file। Terraform cloud provider, SaaS provider আর অন্য API-এর সঙ্গে কাজ করতে provider নামের plugin-এর ওপর নির্ভর করে Source 4সোর্স 4। প্রতিটা resource type একটা provider বাস্তবায়ন করে Source 4সোর্স 4। provider-গুলো Terraform থেকে আলাদাভাবে বিতরণ হয়, আর প্রতিটার নিজের version number আছে Source 4সোর্স 4। একটা configuration যে provider-গুলো চায়, তা required_providers block-এ ঘোষণা করে Source 5সোর্স 5। স্থানীয়ভাবে terraform init চালালে একটা provider install হয় আর dependency lock file update হয় Source 5সোর্স 5। lock file-এর নাম সবসময় .terraform.lock.hcl Source 6সোর্স 6। এটা আপনার version control repository-তে রাখা উচিত Source 6সোর্স 6। production-এ HashiCorp গ্রহণযোগ্য provider version সীমাবদ্ধ করার পরামর্শ দেয় Source 4সোর্স 4।
command-গুলো। terraform init command Terraform configuration file আছে এমন একটা working directory প্রস্তুত করে Source 18সোর্স 18। নতুন configuration লেখার পর বা আগের একটা configuration clone করার পর এটাই প্রথম command, যা চালানো উচিত Source 18সোর্স 18। এটা একাধিকবার চালানো নিরাপদ Source 18সোর্স 18। terraform fmt command configuration file-কে canonical format ও style-এ সাজায় Source 20সোর্স 20। terraform validate command যাচাই করে, configuration syntax-এর দিক থেকে বৈধ আর ভেতরে সামঞ্জস্যপূর্ণ কি না Source 19সোর্স 19। এটা remote service যাচাই করে না Source 19সোর্স 19। এর জন্য একটা প্রস্তুত করা (initialized) working directory লাগে Source 19সোর্স 19। HashiCorp-এর style guide বলে, code commit করার আগে terraform fmt আর terraform validate চালাতে Source 28সোর্স 28।
terraform plan command একটা execution plan তৈরি করে, যা দিয়ে Terraform কী কী পরিবর্তন করতে চায়, তা আগে দেখা যায় Source 21সোর্স 21। by default এটা আগে থেকে থাকা remote object-এর বর্তমান state পড়ে Source 21সোর্স 21। এটা configuration-কে আগের state-এর সঙ্গে তুলনা করে Source 21সোর্স 21। এটা এমন একটা পরিবর্তনের তালিকা প্রস্তাব করে, যা প্রয়োগ করলে remote object-গুলো configuration-এর সঙ্গে মেলা উচিত Source 21সোর্স 21। -out option না দিলে এটা একটা speculative plan তৈরি করে Source 21সোর্স 21। apply করার আগে চূড়ান্ত plan আবার দেখে নেওয়া উচিত Source 21সোর্স 21। -detailed-exitcode দিলে command exit করার সময় একটা বিস্তারিত exit code দেয় Source 21সোর্স 21। terraform apply command একটা plan-এর কাজগুলো চালায় Source 22সোর্স 22। saved plan file ছাড়া এটা একটা নতুন plan বানায় আর আপনার অনুমোদন চায় Source 22সোর্স 22। saved plan file দিলে এটা অনুমোদন চায় না Source 22সোর্স 22। terraform destroy command একটা configuration যে সব object পরিচালনা করে, সেগুলো সরিয়ে দেয় Source 23সোর্স 23।
state। Terraform-কে আপনার workspace-এর পরিচালিত infrastructure আর configuration সম্পর্কে state সংরক্ষণ করতে হয় Source 11সোর্স 11। state দিয়ে সে বাস্তব resource-গুলোকে আপনার configuration-এর সঙ্গে মেলায় Source 11সোর্স 11। যেকোনো operation-এর আগে Terraform একটা refresh করে, যাতে state বাস্তব infrastructure-এর সঙ্গে হালনাগাদ হয় Source 11সোর্স 11। by default state একটা স্থানীয় file, নাম terraform.tfstate Source 11সোর্স 11। এটা একটা JSON text file, আর এটা সরাসরি edit করা উচিত নয় Source 11সোর্স 11। remote state-এ Terraform state data একটা remote data store-এ লেখে, যা পুরো team ভাগ করে নিতে পারে Source 12সোর্স 12। backend সমর্থন করলে Terraform state লিখতে পারে এমন সব operation-এর জন্য state lock করে Source 13সোর্স 13। lock অন্যদের state নষ্ট করা থেকে আটকায় Source 13সোর্স 13। lock নিতে ব্যর্থ হলে Terraform এগোয় না Source 13সোর্স 13।
state আর plan file-এ গোপন তথ্য থাকতে পারে Source 14সোর্স 14। স্থানীয় state file সাধারণ text Source 14সোর্স 14। HashiCorp বলে, একে সংবেদনশীল data হিসেবে ধরতে আর Git workflow-এর বাইরে রাখতে Source 14সোর্স 14। এটা আরও বলে, state এমন version control system বা অন্য storage-এ রাখা এড়াতে, যা state locking আর নিরাপদ access control সমর্থন করে না Source 11সোর্স 11।
পুনর্ব্যবহার আর নিয়ন্ত্রণ। module হলো resource-এর একটা সংগ্রহ, যা Terraform একসঙ্গে পরিচালনা করে Source 15সোর্স 15। root directory-র configuration হলো root module Source 15সোর্স 15। যে module-গুলো আপনি module block দিয়ে ডাকেন, সেগুলো child module Source 15সোর্স 15। for_each meta-argument একই ধরনের একাধিক object পরিচালনা করে, প্রতিটার জন্য আলাদা block না লিখে Source 17সোর্স 17। এটা একটা map বা string-এর set নেয় Source 17সোর্স 17।
by default, একটা argument জায়গায় থেকে বদলানো না গেলে Terraform পুরোনো object destroy করে, তারপর একটা প্রতিস্থাপন বানায় Source 16সোর্স 16। create_before_destroy rule এই ক্রম উল্টে দেয় Source 16সোর্স 16। prevent_destroy true হলে Terraform এমন plan নাকচ করে, যা object-টা destroy করবে Source 16সোর্স 16। আপনি resource-এর configuration সরিয়ে দিলে এই rule destroy আটকায় না Source 16সোর্স 16। ignore_changes argument এমন attribute-এর তালিকা দেয়, যেগুলো Terraform update-এর plan করার সময় উপেক্ষা করা উচিত Source 16সোর্স 16।
plan পড়া, আর test। terraform show command একটা state বা plan file থেকে মানুষ-পাঠযোগ্য output দেয় Source 24সোর্স 24। apply page বলে, apply করার আগে এটা দিয়ে একটা saved plan file দেখে নিতে Source 22সোর্স 22। -json দিলে এটা machine-readable output দেয় Source 24সোর্স 24। plan file-এর জন্য JSON-এ থাকে plan, configuration আর বর্তমান state Source 24সোর্স 24। -json দিলে state-এর sensitive মান সাধারণ text-এ দেখা যায় Source 24সোর্স 24। Terraform একটা plan file-এর পরিবর্তনের machine-readable JSON রূপ দিতে পারে Source 25সোর্স 25। একই page বলে, সেটা বানাতে terraform show -json ব্যবহার করতে Source 25সোর্স 25।
Terraform test-এর সাহায্যে লেখকেরা যাচাই করতে পারেন, module configuration-এর হালনাগাদ কোনো ভাঙনকারী পরিবর্তন আনছে কি না Source 26সোর্স 26। test চলে test-এর নিজস্ব, অল্পস্থায়ী resource-এর বিরুদ্ধে Source 26সোর্স 26। Terraform test file চেনে এর extension দিয়ে, .tftest.hcl বা .tftest.json Source 26সোর্স 26। একটা test file-এ এক বা একাধিক run block থাকে Source 26সোর্স 26। একটা run block-এ assert block থাকতে পারে Source 26সোর্স 26। by default একটা run block configuration apply করে, যাতে বাস্তব infrastructure তৈরি হয় Source 26সোর্স 26। command = plan দিলে run block কোনো infrastructure তৈরি করে না Source 26সোর্স 26। expect_failures attribute এমন object-এর তালিকা দেয়, যেগুলোর তাদের custom condition-এ ব্যর্থ হওয়া উচিত Source 26সোর্স 26। Terraform v1.7.0 এমন ক্ষমতা যোগ করেছে, যাতে test চলার সময় provider-এর ফেরত দেওয়া data mock করা যায় Source 26সোর্স 26।
terraform test command বর্তমান directory আর testing directory-তে test file খোঁজে আর সেগুলো চালায় Source 27সোর্স 27। testing directory-র default নাম tests Source 27সোর্স 27। প্রতিটা test file তার state memory-তে রাখে, যা পরীক্ষাধীন configuration-এর state থেকে আলাদা Source 27সোর্স 27। একটা test file চলার পর Terraform বাকি থাকা infrastructure destroy করার চেষ্টা করে Source 27সোর্স 27। command বাস্তব infrastructure তৈরি করতে পারে, যাতে টাকা খরচ হতে পারে Source 27সোর্স 27। -json option machine-readable JSON output দেখায়, আর -junit-xml option JUnit XML format-এ একটা test report save করে Source 27সোর্স 27।
Packer। Packer HCL template file-এ সংজ্ঞায়িত configuration পড়ে ও প্রয়োগ করে Source 32সোর্স 32। আপনি একটা directory দিলে Packer এমন প্রতিটা file parse করে, যার নাম .pkr.hcl বা .pkr.json দিয়ে শেষ Source 32সোর্স 32। একটা template এক বা একাধিক build সংজ্ঞায়িত করে Source 31সোর্স 31। build হলো একটা একক কাজ, যা একটা platform-এর জন্য একটা artifact বানায় Source 31সোর্স 31। builder একটা platform-এর জন্য একটা machine image তৈরি করে Source 31সোর্স 31। provisioner একটা চলমান machine-এ software install ও configure করে, machine-টা static artifact হওয়ার আগে Source 31সোর্স 31। post-processor একটা builder বা আরেকটা post-processor-এর ফল নিয়ে একটা নতুন artifact বানায় Source 31সোর্স 31। artifact হলো একটা build-এর ফল Source 31সোর্স 31।
source block পুনর্ব্যবহারযোগ্য builder configuration সংজ্ঞায়িত করে Source 33সোর্স 33। build block বলে, কোন builder চালাতে হবে, সেগুলো কীভাবে provision করতে হবে, আর কী post-processing করতে হবে Source 34সোর্স 34। provisioner block একটা provisioner কীভাবে configure হবে তা সংজ্ঞায়িত করে Source 35সোর্স 35। post-processor block একটা post-processor কীভাবে configure হবে তা সংজ্ঞায়িত করে Source 36সোর্স 36। packer init command required_plugins block-এ তালিকাভুক্ত plugin download ও install করে Source 37সোর্স 37। packer validate command একটা template-এর syntax আর configuration যাচাই করে Source 39সোর্স 39। সফল হলে এটা শূন্য exit status দেয়, ব্যর্থ হলে শূন্য নয় এমন exit status Source 39সোর্স 39। packer build command একটা template-এর সব build চালায় Source 38সোর্স 38। template অন্যভাবে না বললে build-গুলো একসঙ্গে (parallel) চলে Source 38সোর্স 38।
shell provisioner Packer যে machine বানায়, তাতে shell script চালায় Source 40সোর্স 40। docker builder Docker ব্যবহার করে Docker image বানায় Source 41সোর্স 41। এটা একটা container চালু করে, তাতে provisioner চালায়, তারপর container export করে বা image commit করে Source 41সোর্স 41। Packer Dockerfile ছাড়াই container বানায় Source 41সোর্স 41। builder-এর জন্য এমন একটা machine লাগে, যাতে Docker Engine install করা আছে Source 41সোর্স 41। commit true হলে Packer container export না করে একটা image-এ commit করে Source 41সোর্স 41। pull option-এর default true, তাই Packer আগে base image pull করে Source 41সোর্স 41। docker-tag post-processor docker builder-এর একটা committed artifact-কে একটা repository-তে tag করে Source 42সোর্স 42।
Crossplane। control plane একটা API প্রকাশ করে Source 43সোর্স 43। আপনি API দিয়ে control plane-কে বলেন, কোন software কীভাবে configure করতে হবে, এটাই আপনার কাঙ্ক্ষিত অবস্থা (desired state) Source 43সোর্স 43। software কাঙ্ক্ষিত অবস্থা থেকে সরে গেলে control plane সেই সরে যাওয়া (drift) ঠিক করে দেয় Source 43সোর্স 43। Crossplane Kubernetes-এর ওপর তৈরি Source 43সোর্স 43। এর চারটা প্রধান অংশ: Composition, managed resource, operation আর একটা package manager Source 43সোর্স 43। Composition আপনাকে custom API বানাতে দেয় Source 43সোর্স 43। Crossplane দিয়ে আপনি controller না লিখে function-এর একটা pipeline configure করেন Source 43সোর্স 43। function-গুলো declarative configuration ফেরত দেয়, যা Crossplane-এর প্রয়োগ করা উচিত Source 43সোর্স 43।
একটা composite resource definition (XRD) একটা custom API-র schema সংজ্ঞায়িত করে Source 44সোর্স 44। ব্যবহারকারীরা একটা XRD-র schema ব্যবহার করে composite resource (XR) তৈরি করেন Source 44সোর্স 44। composition হলো একটা template, যা একাধিক Kubernetes resource-কে একটা composite resource হিসেবে তৈরি করে Source 45সোর্স 45। একটা composite resource একসেট Kubernetes resource-কে একটা Kubernetes object হিসেবে উপস্থাপন করে Source 46সোর্স 46। provider Crossplane-কে একটা বাইরের service-এ infrastructure provision করতে সক্ষম করে Source 47সোর্স 47। একটা managed resource একটা provider-এর ভেতরে একটা বাইরের service-কে উপস্থাপন করে Source 49সোর্স 49। function composition configure করার নতুন উপায় দিয়ে Crossplane-কে বাড়ায় Source 48সোর্স 48। Crossplane docs-এর tutorial একটা App custom resource বানায়, যাকে Crossplane একটা Deployment আর একটা Service-এ পরিণত করে Source 50সোর্স 50।
Crossplane CLI একটা একক standalone binary Source 51সোর্স 51। Crossplane CLI-র বেশির ভাগ command Kubernetes-এর ওপর নির্ভর করে না Source 51সোর্স 51। composition render command দেখায়, একটা composition কোন resource তৈরি বা বদলাবে Source 52সোর্স 52। by default এটা Docker ব্যবহার করে composition function চালায় Source 52সোর্স 52। resource validate command resource-গুলোকে XRD, CRD, provider, function আর configuration-এর schema-র বিপরীতে যাচাই করে Source 52সোর্স 52। এটা অজানা field-ও ধরে Source 52সোর্স 52। docs এই command-টাকে beta বলে চিহ্নিত করে Source 52সোর্স 52।
Try it
The tutorial ran steps 1 to 9 on 2026-11-19 at 15:22 (+06) on Linux 7.0.0-43-generic, with Terraform v1.17.2, Packer v1.16.2, the Crossplane CLI v2.5.0, Docker 29.10.0, and bash 5.3.9. The output on this page is from the tutorial's run. Each step ran in its own shell, in a copy of the practice folder, with a new, empty HOME. The page shows the folder of the run as /work. Before the steps, no variable was set whose name starts with TF_, PACKER_, CHECKPOINT_, XP_, or CROSSPLANE_. After the run, the tutorial compared the top-level entries of the real home folder with the list from before, and none was new. The tutorial did not watch the network.
Steps 1 to 6 use Terraform with the local provider. They write one text file on your machine, and they need no cloud account. terraform init downloaded the provider hashicorp/local v2.9.1 over the network. Step 7 builds a Docker image with Packer. packer init downloaded the Docker plugin v1.1.5. The provisioner installed curl in the image from the package repository of Alpine, so this step uses the network too. The base image alpine:latest (sha256:f59abe656b69) was already on the machine, and Packer did not pull it. The tutorial removed the image that Packer built.
Steps 8 and 9 run the Crossplane CLI, and they need no cluster. During them, Docker pulled two images: xpkg.crossplane.io/crossplane/crossplane:stable (181MB, digest sha256:00ec53eefb39, created 2026-11-18) and xpkg.crossplane.io/crossplane-contrib/function-patch-and-transform:v0.8.2 (87MB). The tutorial removed both images after the run. The four manifest files of these steps come from the page "Get started with composition" Source 50সোর্স 50. The tutorial compared their lines with the page, without the indentation, and every line was there, in order.
The choices that no source gives are the tutorial's own: the file names, the names inside the files, the versions >= 1.6 and >= 2.5, the base image, the commands of the provisioner, the wrong test of step 5, and the typo of step 9.
Install the tools. On 2026-11-19, the install page of Terraform showed 1.17.2 as the latest version Source 55সোর্স 55, and the install page of Packer showed 1.16.2 Source 56সোর্স 56. Both pages list package-manager commands and a binary download Source 55সোর্স 55 Source 56সোর্স 56. The tutorial took the binary downloads, for one user, in ~/.local/bin, with no sudo. It installed Terraform at 14:52 and Packer at 14:52 on 2026-11-19.
A binary can hide malicious code. HashiCorp says to verify that HashiCorp created and signed the binary before you run it Source 54সোর্স 54. HashiCorp uses a public PGP key to sign the checksums of its product archives Source 54সোর্স 54. The page gives the fingerprint of the key Source 54সোর্স 54. For each tool, the tutorial checked three things before it installed anything. The key file from hashicorp.com has that fingerprint. The signature of the SHA256SUMS file is valid, and that key made it. The SHA-256 of the zip file is the one in the SHA256SUMS file. The SHA-256 of the Terraform zip starts with e6f16b2f, and the one of the Packer zip starts with abbfe0cf.
The Crossplane CLI is a single standalone binary Source 51সোর্স 51. Some of its commands, such as crossplane composition render, need a container runtime that works with Docker Source 51সোর্স 51. The tutorial downloaded the binary by hand, as the page describes Source 51সোর্স 51. The page says to move it to a folder in your PATH, for example /usr/local/bin Source 51সোর্স 51. The tutorial put it in ~/.local/bin, at 15:00. It compared the binary with the .sha256 file that sits next to it, and its SHA-256 starts with 065dd6b4. That file comes from the same host, and the tutorial found no signature for it. So the check shows only that the download is whole.
1. Write the configuration, and check it. Save this as main.tf in a folder named tf:
terraform {
required_version = ">= 1.6"
required_providers {
local = {
source = "hashicorp/local"
version = ">= 2.5"
}
}
}
variable "env_name" {
type = string
description = "Name of the test environment."
default = "qa"
validation {
condition = can(regex("^[a-z]+$", var.env_name))
error_message = "env_name must be lower-case letters only."
}
}
variable "base_url" {
type = string
description = "Address of the application under test."
default = "http://localhost:8080"
}
locals {
settings = "env=${var.env_name}\nbase_url=${var.base_url}\n"
}
resource "local_file" "settings" {
filename = "${path.module}/out/${var.env_name}.env"
content = local.settings
}
output "settings_path" {
value = local_file.settings.filename
}The file is the tutorial's own, and it has no comment. The terraform block names the provider in the required_providers block Source 5সোর্স 5. A variable block is like a function argument Source 7সোর্স 7. The validation block of env_name refuses capital letters. The locals block holds the text of the settings Source 9সোর্স 9. The local_file resource generates a local file with the given content Source 29সোর্স 29. The output block exposes the path of the file Source 8সোর্স 8.
Run:
cd tf
terraform version
terraform init -no-color
head -n 9 .terraform.lock.hcl
terraform fmt -check -diff
echo "fmt exit status: $?"
terraform validate -no-color
echo "validate exit status: $?"
printf 'variable "x" {\ntype = string\n}\n' > bad.tf
terraform fmt -check -diff
echo "fmt exit status: $?"
rm bad.tfOutput of the tutorial's run:
Terraform v1.17.2
on linux_amd64
Initializing the backend...
Initializing provider plugins...
- Finding hashicorp/local versions matching ">= 2.5.0"...
- Installing hashicorp/local v2.9.1...
- Installed hashicorp/local v2.9.1 (signed by HashiCorp)
Terraform has created a lock file .terraform.lock.hcl to record the provider
selections it made above. Include this file in your version control repository
so that Terraform can guarantee to make the same selections by default when
you run "terraform init" in the future.
Terraform has been successfully initialized!
You may now begin working with Terraform. Try running "terraform plan" to see
any changes that are required for your infrastructure. All Terraform commands
should now work.
If you ever set or change modules or backend configuration for Terraform,
rerun this command to reinitialize your working directory. If you forget, other
commands will detect it and remind you to do so if necessary.
# This file is maintained automatically by "terraform init".
# Manual edits may be lost in future updates.
provider "registry.terraform.io/hashicorp/local" {
version = "2.9.1"
constraints = ">= 2.5.0"
hashes = [
"h1:qGLHCuYSus+uHNnoEL4SuJqOs5yrNOcB7gnuHoVqizo=",
"zh:25606c7a5e308144fb627f6e31611bb52ff72bb9ae2d27af39673ab1a6b3c1bf",
fmt exit status: 0
Success! The configuration is valid.
validate exit status: 0
bad.tf
--- old/bad.tf
+++ new/bad.tf
@@ -1,3 +1,3 @@
variable "x" {
-type = string
+ type = string
}
fmt exit status: 3terraform initinstalled the provider and created.terraform.lock.hclSource 5সোর্স 5. The lock file is how Terraform remembers its choice of version Source 6সোর্স 6. The lines thatheadshows are the provider address, the version2.9.1, the constraint>= 2.5.0, and the start of the list of hashes. The tutorial wrote the constraint as>= 2.5, and Terraform wrote>= 2.5.0. The list holds checksums for your platform and for other platforms Source 6সোর্স 6. On a laterinit, Terraform returns an error if an installed package matches none of the recorded checksums Source 6সোর্স 6.- The first
terraform fmt -check -diffprinted nothing, and its exit status was 0. The exit status is 0 if the input is properly formatted, and non-zero otherwise, with a list of the file names Source 20সোর্স 20. Then the tutorial wrote a badly formatted file,bad.tf, on purpose. The secondfmtlistedbad.tf, showed the diff, and the exit status was 3. The tutorial removedbad.tfafter that. terraform validateprintedSuccess! The configuration is valid., and its exit status was 0. It checks that a configuration is syntactically valid and internally consistent Source 19সোর্স 19.
2. Plan, apply, and plan again. Run:
cd tf
terraform plan -no-color -out=tfplan -detailed-exitcode
echo "plan exit status: $?"
terraform show -json tfplan | python3 -c 'import json, sys; plan = json.load(sys.stdin); print([(c["address"], c["change"]["actions"]) for c in plan["resource_changes"]])'
terraform apply -no-color tfplan
echo "apply exit status: $?"
cat out/qa.env
terraform plan -no-color -detailed-exitcode
echo "plan exit status: $?"Output of the tutorial's run:
Terraform used the selected providers to generate the following execution
plan. Resource actions are indicated with the following symbols:
+ create
Terraform will perform the following actions:
# local_file.settings will be created
+ resource "local_file" "settings" {
+ content = <<-EOT
env=qa
base_url=http://localhost:8080
EOT
+ content_base64sha256 = (known after apply)
+ content_base64sha512 = (known after apply)
+ content_md5 = (known after apply)
+ content_sha1 = (known after apply)
+ content_sha256 = (known after apply)
+ content_sha512 = (known after apply)
+ directory_permission = "0777"
+ file_permission = "0777"
+ filename = "./out/qa.env"
+ id = (known after apply)
}
Plan: 1 to add, 0 to change, 0 to destroy.
Changes to Outputs:
+ settings_path = "./out/qa.env"
─────────────────────────────────────────────────────────────────────────────
Saved the plan to: tfplan
To perform exactly these actions, run the following command to apply:
terraform apply "tfplan"
plan exit status: 2
[('local_file.settings', ['create'])]
local_file.settings: Creating...
local_file.settings: Creation complete after 0s [id=ea8fed73fdf0af945662466adbb1135880656d6d]
Apply complete! Resources: 1 added, 0 changed, 0 destroyed.
Outputs:
settings_path = "./out/qa.env"
apply exit status: 0
env=qa
base_url=http://localhost:8080
local_file.settings: Refreshing state... [id=ea8fed73fdf0af945662466adbb1135880656d6d]
No changes. Your infrastructure matches the configuration.
Terraform has compared your real infrastructure against your configuration
and found no differences, so no changes are needed.
plan exit status: 0- The first plan saves the plan to the file
tfplanwith-out. It lists+ createfor one resource, and it ends withPlan: 1 to add, 0 to change, 0 to destroy.The values ofidand of the hashes areknown after apply. The plan showsfile_permission = "0777", which is the default of the provider Source 29সোর্স 29. -detailed-exitcodemade the exit status 2. That means that the command succeeded and that changes are present Source 21সোর্স 21.- The Python line of the tutorial reads the JSON of the saved plan. It prints the address and the
actionsof each item ofresource_changesSource 25সোর্স 25. The output shows one item, with the actioncreate. The valid values ofactionsareno-op,create,read,update,delete, and two replace pairs Source 25সোর্স 25. terraform apply tfplangot a saved plan, so it did not ask for approval Source 22সোর্স 22. It ended withApply complete! Resources: 1 added, 0 changed, 0 destroyed.The fileout/qa.envholds the two lines of the settings.- The second plan printed
No changes. Your infrastructure matches the configuration.Its exit status was 0, which means success with no changes Source 21সোর্স 21.
3. Change the file by hand, and let Terraform fix it. Run:
cd tf
printf 'env=changed-by-hand\n' > out/qa.env
terraform apply -no-color -auto-approve
cat out/qa.env
terraform plan -no-color -var env_name=QA
echo "plan exit status: $?"Output of the tutorial's run:
local_file.settings: Refreshing state... [id=ea8fed73fdf0af945662466adbb1135880656d6d]
Terraform used the selected providers to generate the following execution
plan. Resource actions are indicated with the following symbols:
+ create
Terraform will perform the following actions:
# local_file.settings will be created
+ resource "local_file" "settings" {
+ content = <<-EOT
env=qa
base_url=http://localhost:8080
EOT
+ content_base64sha256 = (known after apply)
+ content_base64sha512 = (known after apply)
+ content_md5 = (known after apply)
+ content_sha1 = (known after apply)
+ content_sha256 = (known after apply)
+ content_sha512 = (known after apply)
+ directory_permission = "0777"
+ file_permission = "0777"
+ filename = "./out/qa.env"
+ id = (known after apply)
}
Plan: 1 to add, 0 to change, 0 to destroy.
local_file.settings: Creating...
local_file.settings: Creation complete after 0s [id=ea8fed73fdf0af945662466adbb1135880656d6d]
Apply complete! Resources: 1 added, 0 changed, 0 destroyed.
Outputs:
settings_path = "./out/qa.env"
env=qa
base_url=http://localhost:8080
Planning failed. Terraform encountered an error while generating this plan.
Error: Invalid value for variable
on main.tf line 12:
12: variable "env_name" {
├────────────────
│ var.env_name is "QA"
env_name must be lower-case letters only.
This was checked by the validation rule at main.tf:17,3-13.
plan exit status: 1- The tutorial overwrote
out/qa.envby hand. The apply began withRefreshing state.... Before any operation, Terraform does a refresh to update the state with the real infrastructure Source 11সোর্স 11. - The plan then said
local_file.settings will be created, withPlan: 1 to add, 0 to change, 0 to destroy.It did not say that the file would be updated. No page that the tutorial read says why. After the apply,catshows the original two lines, so Terraform put the file back. -auto-approveskipped the question. The docs say to make sure that no one can change your infrastructure outside of your Terraform workflow when you use it Source 22সোর্স 22. The tutorial used it for a file that it can lose.- The last command passed
-var env_name=QA. Terraform refused, withError: Invalid value for variable, the message of thevalidationblock, and the exit status 1. Terraform checks the validations while it creates a plan, and it stops the operation when a condition is false Source 7সোর্স 7. The exit status 1 means an error Source 21সোর্স 21.
4. Look at the state. Run:
cd tf
terraform state list
ls terraform.tfstate*
grep -n '"content"' terraform.tfstateOutput of the tutorial's run:
local_file.settings
terraform.tfstate
terraform.tfstate.backup
22: "content": "env=qa\nbase_url=http://localhost:8080\n",terraform state listlists resources within a state Source 57সোর্স 57. It printed the one resource of the state,local_file.settings.- The folder holds
terraform.tfstateandterraform.tfstate.backup. By default, Terraform stores the state in a local file named terraform.tfstate, and a backup of the previous state in terraform.tfstate.backup Source 11সোর্স 11. - The
grepline shows the content of the file inside the state, in plain text. A local state is a plaintext file that includes any secret values you defined in your configuration Source 14সোর্স 14. The settings of this file are not secret. For sensitive content, the provider says to use thelocal_sensitive_fileresource Source 29সোর্স 29.
5. Test the configuration. Save this as tests/settings.tftest.hcl:
run "default_settings" {
command = plan
assert {
condition = local_file.settings.content == "env=qa\nbase_url=http://localhost:8080\n"
error_message = "The default settings are not what the tests expect."
}
}
run "name_with_capitals_is_refused" {
command = plan
variables {
env_name = "QA"
}
expect_failures = [var.env_name]
}
run "file_is_created_and_removed" {
command = apply
variables {
env_name = "scratch"
}
assert {
condition = output.settings_path == "./out/scratch.env"
error_message = "The file is not where the test expects it."
}
}Run it. Then the tutorial wrote a test with a wrong expectation on purpose, ran only that file, and removed it:
cd tf
terraform test -no-color
echo "test exit status: $?"
cat > tests/wrong.tftest.hcl <<'TEST'
run "wrong_expectation" {
command = plan
assert {
condition = local_file.settings.content == "env=prod\n"
error_message = "The settings are not the production settings."
}
}
TEST
terraform test -no-color -filter=tests/wrong.tftest.hcl
echo "test exit status: $?"
rm tests/wrong.tftest.hclOutput of the tutorial's run:
tests/settings.tftest.hcl... in progress
run "default_settings"... pass
run "name_with_capitals_is_refused"... pass
run "file_is_created_and_removed"... pass
tests/settings.tftest.hcl... tearing down
tests/settings.tftest.hcl... pass
Success! 3 passed, 0 failed.
test exit status: 0
tests/wrong.tftest.hcl... in progress
run "wrong_expectation"... fail
Error: Test assertion failed
on tests/wrong.tftest.hcl line 5, in run "wrong_expectation":
5: condition = local_file.settings.content == "env=prod\n"
├────────────────
│ Diff:
│ --- actual
│ +++ expected
│ - "env=qa\nbase_url=http://localhost:8080\n"
│ + "env=prod\n"
The settings are not the production settings.
tests/wrong.tftest.hcl... tearing down
tests/wrong.tftest.hcl... fail
Failure! 0 passed, 1 failed.
test exit status: 1- By default, the directory with the test files is named
testsSource 27সোর্স 27. A test file has one or morerunblocks Source 26সোর্স 26. - The first two
runblocks usecommand = plan, so they create no infrastructure Source 26সোর্স 26. The first one asserts the default content of the file. The second one setsenv_name = "QA". Itsexpect_failures = [var.env_name]lists a variable that should fail its custom condition Source 26সোর্স 26. It passes, becauseQAbreaks thevalidationrule. - The third
runblock uses the default, which applies the configuration. By default, tests create real infrastructure Source 26সোর্স 26. Here it created./out/scratch.env, and it checked the output. The output showstearing down. After a test file has run, Terraform tries to destroy what is left Source 27সোর্স 27. - The result was
Success! 3 passed, 0 failed., and the exit status was 0. - A test file keeps its own state, apart from the state of the configuration Source 27সোর্স 27. The file
out/qa.envof step 3 was still there, and step 6 destroys it. - The wrong test asserts
env=prod, and it failed. Terraform printedTest assertion failed, theDiffof the actual and the expected value, and theerror_message. The exit status was 1.-filterlimits the run to the given test file Source 27সোর্স 27.
6. Destroy it. Run:
cd tf
terraform destroy -no-color -auto-approve
ls out
terraform state list
echo "state list exit status: $?"Output of the tutorial's run:
local_file.settings: Refreshing state... [id=ea8fed73fdf0af945662466adbb1135880656d6d]
Terraform used the selected providers to generate the following execution
plan. Resource actions are indicated with the following symbols:
- destroy
Terraform will perform the following actions:
# local_file.settings will be destroyed
- resource "local_file" "settings" {
- content = <<-EOT
env=qa
base_url=http://localhost:8080
EOT -> null
- content_base64sha256 = "O3FCs3DMCHcVvw4jqt5VgiQLrnoBpfbzXYTgwrb2xdw=" -> null
- content_base64sha512 = "dr4Aa0ooINRuEdBv6qMIMiEdeMzD70f1k+vSzr/OA9tO4kTf/iNCLA4AjpaSAg8Au6vZ0ayK3IWB9XOgobl9uA==" -> null
- content_md5 = "71a00ff38b756e3d0971971589dfeffc" -> null
- content_sha1 = "ea8fed73fdf0af945662466adbb1135880656d6d" -> null
- content_sha256 = "3b7142b370cc087715bf0e23aade5582240bae7a01a5f6f35d84e0c2b6f6c5dc" -> null
- content_sha512 = "76be006b4a2820d46e11d06feaa30832211d78ccc3ef47f593ebd2cebfce03db4ee244dffe23422c0e008e9692020f00bbabd9d1ac8adc8581f573a0a1b97db8" -> null
- directory_permission = "0777" -> null
- file_permission = "0777" -> null
- filename = "./out/qa.env" -> null
- id = "ea8fed73fdf0af945662466adbb1135880656d6d" -> null
}
Plan: 0 to add, 0 to change, 1 to destroy.
Changes to Outputs:
- settings_path = "./out/qa.env" -> null
local_file.settings: Destroying... [id=ea8fed73fdf0af945662466adbb1135880656d6d]
local_file.settings: Destruction complete after 0s
Destroy complete! Resources: 1 destroyed.
state list exit status: 0terraform destroydeprovisions all objects that the configuration manages Source 23সোর্স 23. The plan lists- destroy, and it ends withPlan: 0 to add, 0 to change, 1 to destroy.The apply ended withDestroy complete! Resources: 1 destroyed.ls outprinted nothing, so the file is gone.terraform state listprinted nothing, and its exit status was 0. The state holds no resource.- The runner of the tutorial then removed the whole folder of the run.
7. Build a Docker image with Packer. Save this as image.pkr.hcl in a folder named pk:
packer {
required_plugins {
docker = {
version = ">= 1.1.0"
source = "github.com/hashicorp/docker"
}
}
}
source "docker" "alpine" {
image = "alpine:latest"
pull = false
commit = true
}
build {
name = "qa-base"
sources = ["source.docker.alpine"]
provisioner "shell" {
inline = [
"echo 'built by Packer' > /etc/qa-image.txt",
"apk add --no-cache curl",
]
}
post-processor "docker-tag" {
repository = "packer-practice-qa-base"
tags = ["1.0"]
}
}The file is the tutorial's own, and it has no comment. The packer block lists the Docker plugin in required_plugins Source 37সোর্স 37. The source block holds the builder Source 33সোর্স 33. commit = true makes Packer commit the container to an image Source 41সোর্স 41. pull = false makes Packer use the image that is already on the machine Source 41সোর্স 41. The build block names the build qa-base and picks the source. A provisioner block defines how to configure a provisioner Source 35সোর্স 35. The docker-tag post-processor takes an artifact from the docker builder that was committed, and tags it into a repository Source 42সোর্স 42. The name, the tag, and the two commands of the provisioner are the tutorial's own choice.
Run:
cd pk
packer version
packer init .
packer fmt -check .
echo "fmt exit status: $?"
packer validate .
echo "validate exit status: $?"
packer build -color=false .
docker run --rm packer-practice-qa-base:1.0 cat /etc/qa-image.txt
docker run --rm packer-practice-qa-base:1.0 curl --version
docker rmi packer-practice-qa-base:1.0Output of the tutorial's run:
Packer v1.16.2
[1;36mInstalled plugin github.com/hashicorp/docker v1.1.5 in "/work/home/.config/packer/plugins/github.com/hashicorp/docker/packer-plugin-docker_v1.1.5_x5.0_linux_amd64"[0m
fmt exit status: 0
The configuration is valid.
validate exit status: 0
==> qa-base.docker.alpine: Creating a temporary directory for sharing data...
==> qa-base.docker.alpine: Starting docker container...
==> qa-base.docker.alpine: Run command: docker run -v /work/home/.config/packer/tmp460997856:/packer-files -d -i -t --entrypoint=/bin/sh -- alpine:latest
==> qa-base.docker.alpine: Container ID: eef29ce691014a83fbc715656cc8c39c4de4496baefd9876a8b53aee648a7471
==> qa-base.docker.alpine: Provisioning with shell script: /work/tmp/packer-shell4200093466
==> qa-base.docker.alpine: (1/9) Installing brotli-libs (1.2.1-r0)
==> qa-base.docker.alpine: (2/9) Installing c-ares (1.34.9-r0)
==> qa-base.docker.alpine: (3/9) Installing libunistring (1.4.2-r0)
==> qa-base.docker.alpine: (4/9) Installing libidn2 (2.3.8-r0)
==> qa-base.docker.alpine: (5/9) Installing nghttp2-libs (1.70.0-r0)
==> qa-base.docker.alpine: (6/9) Installing libpsl (0.21.5-r3)
==> qa-base.docker.alpine: (7/9) Installing zstd-libs (1.5.7-r2)
==> qa-base.docker.alpine: (8/9) Installing libcurl (8.23.0-r0)
==> qa-base.docker.alpine: (9/9) Installing curl (8.23.0-r0)
==> qa-base.docker.alpine: Executing busybox-1.37.0-r31.trigger
==> qa-base.docker.alpine: OK: 13.1 MiB in 25 packages
==> qa-base.docker.alpine: Committing the container
==> qa-base.docker.alpine: Image ID: sha256:43b55b1018aeab608ed6ca143e9b73c28aa3b677a418ebef52f6e7f62c4ce9f4
==> qa-base.docker.alpine: Killing the container: eef29ce691014a83fbc715656cc8c39c4de4496baefd9876a8b53aee648a7471
==> qa-base.docker.alpine: Running post-processor: (type docker-tag)
==> qa-base.docker.alpine (docker-tag): Tagging image: sha256:43b55b1018aeab608ed6ca143e9b73c28aa3b677a418ebef52f6e7f62c4ce9f4
==> qa-base.docker.alpine (docker-tag): Repository: packer-practice-qa-base:1.0
Build 'qa-base.docker.alpine' finished after 2 seconds 828 milliseconds.
==> Wait completed after 2 seconds 829 milliseconds
==> Builds finished. The artifacts of successful builds are:
--> qa-base.docker.alpine: Imported Docker image: sha256:43b55b1018aeab608ed6ca143e9b73c28aa3b677a418ebef52f6e7f62c4ce9f4
--> qa-base.docker.alpine: Imported Docker image: packer-practice-qa-base:1.0 with tags packer-practice-qa-base:1.0
built by Packer
curl 8.23.0 (x86_64-alpine-linux-musl) libcurl/8.23.0 OpenSSL/3.5.9 zlib/1.3.2 brotli/1.2.1 zstd/1.5.7 c-ares/1.34.9 libidn2/2.3.8 libpsl/0.21.5 nghttp2/1.70.0
Release-Date: 2026-10-14
Protocols: dict file ftp ftps gopher gophers http https imap imaps ipfs ipns mqtt mqtts pop3 pop3s rtsp smtp smtps telnet tftp ws wss
Features: alt-svc AsynchDNS brotli HSTS HTTP2 HTTPS-proxy IDN IPv6 Largefile libz PSL SSL threadsafe UnixSockets zstd
Untagged: packer-practice-qa-base:1.0
Deleted: sha256:43b55b1018aeab608ed6ca143e9b73c28aa3b677a418ebef52f6e7f62c4ce9f4packer initinstalled the plugingithub.com/hashicorp/dockerSource 37সোর্স 37. The path in the output is in the empty home folder of the run, which the page shows as/work/home.packer fmt -check .andpacker validate .both ended with the exit status 0.packer fmtformats HCL2 files to a canonical format and style Source 53সোর্স 53. With-check, the exit status is 0 only if all input is properly formatted Source 53সোর্স 53.packer validateprintedThe configuration is valid.It returns a zero exit status on success Source 39সোর্স 39.packer buildstarted a container fromalpine:latest, ran the provisioner in it, and committed the container Source 41সোর্স 41. Thedocker-tagpost-processor then tagged the imagepacker-practice-qa-base:1.0Source 42সোর্স 42. It used no Dockerfile Source 41সোর্স 41.- The two
docker runcommands used the new image.cat /etc/qa-image.txtprintedbuilt by Packer, andcurl --versionprinted the version of thecurlthat the provisioner installed. This is the tutorial's own check of the image. docker rmiremoved the tag and the image.
8. Render a Crossplane composition. Save this as app.yaml in a folder named xp:
apiVersion: example.crossplane.io/v1
kind: App
metadata:
namespace: default
name: my-app
spec:
image: nginxThis is an App that asks for the image nginx. The other three files are xrd.yaml (step 9 shows it), fn-patch-and-transform.yaml (6 lines, the function), and composition-yaml.yaml (72 lines). Take them from the page "Get started with composition" Source 50সোর্স 50. The composition has one pipeline step. It uses the function crossplane-contrib-function-patch-and-transform. It builds a Deployment with replicas: 2 and a Service with the port 8080 for the port 80. A patch copies spec.image of the App into the image of the Deployment. A composition is a template for creating several Kubernetes resources as one composite resource Source 45সোর্স 45.
Run:
cd xp
crossplane version --client
crossplane composition render app.yaml composition-yaml.yaml fn-patch-and-transform.yaml
echo "render exit status: $?"Output of the tutorial's run:
Client Version: v2.5.0
---
apiVersion: example.crossplane.io/v1
kind: App
metadata:
name: my-app
namespace: default
spec:
crossplane:
resourceRefs:
- apiVersion: apps/v1
kind: Deployment
name: my-app-3ebefffb6666
- apiVersion: v1
kind: Service
name: my-app-bb6a52963bfb
status:
conditions:
- lastTransitionTime: "2024-01-01T00:00:00Z"
reason: WatchCircuitClosed
status: "True"
type: Responsive
- lastTransitionTime: "2024-01-01T00:00:00Z"
reason: ReconcileSuccess
status: "True"
type: Synced
- lastTransitionTime: "2024-01-01T00:00:00Z"
message: 'Unready resources: deployment, service'
reason: Creating
status: "False"
type: Ready
---
apiVersion: apps/v1
kind: Deployment
metadata:
annotations:
crossplane.io/composition-resource-name: deployment
generateName: my-app-
labels:
crossplane.io/composite: my-app
example.crossplane.io/app: my-app
name: my-app-3ebefffb6666
namespace: default
ownerReferences:
- apiVersion: example.crossplane.io/v1
blockOwnerDeletion: true
controller: true
kind: App
name: my-app
uid: 9de988c4-8410-5318-8780-2295cef818ff
spec:
replicas: 2
selector:
matchLabels:
example.crossplane.io/app: my-app
template:
metadata:
labels:
example.crossplane.io/app: my-app
spec:
containers:
- image: nginx
name: app
ports:
- containerPort: 80
---
apiVersion: v1
kind: Service
metadata:
annotations:
crossplane.io/composition-resource-name: service
generateName: my-app-
labels:
crossplane.io/composite: my-app
example.crossplane.io/app: my-app
name: my-app-bb6a52963bfb
namespace: default
ownerReferences:
- apiVersion: example.crossplane.io/v1
blockOwnerDeletion: true
controller: true
kind: App
name: my-app
uid: 9de988c4-8410-5318-8780-2295cef818ff
spec:
ports:
- port: 8080
protocol: TCP
targetPort: 80
selector:
example.crossplane.io/app: my-app
render exit status: 0crossplane version --clientprinted the client version, and it needs no server Source 52সোর্স 52.composition renderneeds a container runtime that works with Docker Source 51সোর্স 51. By default, it pulls and runs the composition functions with Docker Source 52সোর্স 52.composition renderprinted three documents: theAppwithresourceRefs, a Deployment, and a Service. It shows what resources the composition would create or change Source 52সোর্স 52. The Deployment hasreplicas: 2andimage: nginx, the value ofspec.imageof theApp. The Service maps the port 8080 to the port 80.- The status of the
AppsaysUnready resources: deployment, service, and eachlastTransitionTimeis2024-01-01T00:00:00Z. Nothing was created, becauserenderruns locally. No page that the tutorial read says why the time is fixed. The exit status was 0.
9. Validate the App against its schema. Save this as xrd.yaml:
apiVersion: apiextensions.crossplane.io/v2
kind: CompositeResourceDefinition
metadata:
name: apps.example.crossplane.io
spec:
scope: Namespaced
group: example.crossplane.io
names:
kind: App
plural: apps
versions:
- name: v1
served: true
referenceable: true
schema:
openAPIV3Schema:
type: object
properties:
spec:
type: object
properties:
image:
description: The app's OCI container image.
type: string
required:
- image
status:
type: object
properties:
replicas:
description: The number of available app replicas.
type: integer
address:
description: The app's IP address.
type: stringThe XRD defines the schema of the custom API Source 44সোর্স 44. In it, spec.image is a string, and it is required.
Run:
cd xp
crossplane resource validate xrd.yaml app.yaml
echo "validate exit status: $?"
sed 's/image: nginx/imagee: nginx/' app.yaml > bad-app.yaml
crossplane resource validate xrd.yaml bad-app.yaml
echo "validate exit status: $?"
crossplane composition render bad-app.yaml composition-yaml.yaml fn-patch-and-transform.yaml | grep -c "image:"
echo "render exit status: ${PIPESTATUS[0]}"Output of the tutorial's run:
schemas does not exist, downloading: xpkg.crossplane.io/crossplane/crossplane:stable
[✓] example.crossplane.io/v1, Kind=App, my-app validated successfully
Total 1 resources: 0 missing schemas, 1 success cases, 0 failure cases
validate exit status: 0
[x] schema validation error example.crossplane.io/v1, Kind=App, my-app : spec.image: Required value
[x] schema validation error example.crossplane.io/v1, Kind=App, my-app : spec.imagee: Invalid value: "imagee": unknown field: "imagee"
Total 1 resources: 0 missing schemas, 0 success cases, 1 failure cases
crossplane: error: could not validate all resources
validate exit status: 1
0
render exit status: 0- The first
crossplane resource validateprintedschemas does not exist, downloading: xpkg.crossplane.io/crossplane/crossplane:stable, and thenvalidated successfully. The summary says1 success cases, and the exit status was 0. The command checks resources against the schemas of XRDs, CRDs, providers, functions, and configurations Source 52সোর্স 52. No page that the tutorial read says what was downloaded. - Then the tutorial copied
app.yamltobad-app.yaml, with a typo:imageeforimage.validateprinted two errors,spec.image: Required valueandunknown field: "imagee", and the exit status was 1. The command detects unknown fields Source 52সোর্স 52. renderof the same file exited with 0, andgrep -c "image:"counted 0 lines in its output. Sorenderdid not refuse the typo, and the Deployment that it printed has no image. The docs markresource validateas beta Source 52সোর্স 52.
সহজ English
The tutorial ran steps 1 to 9 on 2026-11-19 at 15:22 (+06) on Linux 7.0.0-43-generic, with Terraform v1.17.2, Packer v1.16.2, the Crossplane CLI v2.5.0, Docker 29.10.0, and bash 5.3.9. The output on this page is from the tutorial's run. Each step ran in its own shell, in a copy of the practice folder, with a new, empty HOME. The page shows the folder of the run as /work. Before the steps, no variable was set whose name starts with TF_, PACKER_, CHECKPOINT_, XP_, or CROSSPLANE_. After the run, the tutorial compared the top-level entries of the real home folder with the list from before, and none was new. The tutorial did not watch the network.
Steps 1 to 6 use Terraform with the local provider. They write one text file on your machine, and they need no cloud account. terraform init downloaded the provider hashicorp/local v2.9.1 over the network. Step 7 builds a Docker image with Packer. packer init downloaded the Docker plugin v1.1.5. The provisioner installed curl in the image from the package repository of Alpine, so this step uses the network too. The base image alpine:latest (sha256:f59abe656b69) was already on the machine, and Packer did not pull it. The tutorial removed the image that Packer built.
Steps 8 and 9 run the Crossplane CLI, and they need no cluster. During them, Docker pulled two images: xpkg.crossplane.io/crossplane/crossplane:stable (181MB, digest sha256:00ec53eefb39, created 2026-11-18) and xpkg.crossplane.io/crossplane-contrib/function-patch-and-transform:v0.8.2 (87MB). The tutorial removed both images after the run. The four manifest files of these steps come from the page "Get started with composition" Source 50সোর্স 50. The tutorial compared their lines with the page, without the indentation, and every line was there, in order.
The choices that no source gives are the tutorial's own: the file names, the names inside the files, the versions >= 1.6 and >= 2.5, the base image, the commands of the provisioner, the wrong test of step 5, and the typo of step 9.
Install the tools. On 2026-11-19, the install page of Terraform showed 1.17.2 as the latest version Source 55সোর্স 55, and the install page of Packer showed 1.16.2 Source 56সোর্স 56. Both pages list package-manager commands and a binary download Source 55সোর্স 55 Source 56সোর্স 56. The tutorial took the binary downloads, for one user, in ~/.local/bin, with no sudo. It installed Terraform at 14:52 and Packer at 14:52 on 2026-11-19.
A binary can hide malicious code. HashiCorp says to verify that HashiCorp created and signed the binary before you run it Source 54সোর্স 54. HashiCorp uses a public PGP key to sign the checksums of its product archives Source 54সোর্স 54. The page gives the fingerprint of the key Source 54সোর্স 54. For each tool, the tutorial checked three things before it installed anything. The key file from hashicorp.com has that fingerprint. The signature of the SHA256SUMS file is valid, and that key made it. The SHA-256 of the zip file is the one in the SHA256SUMS file. The SHA-256 of the Terraform zip starts with e6f16b2f, and the one of the Packer zip starts with abbfe0cf.
The Crossplane CLI is a single standalone binary Source 51সোর্স 51. Some of its commands, such as crossplane composition render, need a container runtime that works with Docker Source 51সোর্স 51. The tutorial downloaded the binary by hand, as the page describes Source 51সোর্স 51. The page says to move it to a folder in your PATH, for example /usr/local/bin Source 51সোর্স 51. The tutorial put it in ~/.local/bin, at 15:00. It compared the binary with the .sha256 file that sits next to it, and its SHA-256 starts with 065dd6b4. That file comes from the same host, and the tutorial found no signature for it. So the check shows only that the download is whole.
1. Write the configuration, and check it. Save this as main.tf in a folder named tf:
terraform {
required_version = ">= 1.6"
required_providers {
local = {
source = "hashicorp/local"
version = ">= 2.5"
}
}
}
variable "env_name" {
type = string
description = "Name of the test environment."
default = "qa"
validation {
condition = can(regex("^[a-z]+$", var.env_name))
error_message = "env_name must be lower-case letters only."
}
}
variable "base_url" {
type = string
description = "Address of the application under test."
default = "http://localhost:8080"
}
locals {
settings = "env=${var.env_name}\nbase_url=${var.base_url}\n"
}
resource "local_file" "settings" {
filename = "${path.module}/out/${var.env_name}.env"
content = local.settings
}
output "settings_path" {
value = local_file.settings.filename
}The file is the tutorial's own, and it has no comment. The terraform block names the provider in the required_providers block Source 5সোর্স 5. A variable block is like a function argument Source 7সোর্স 7. The validation block of env_name refuses capital letters. The locals block holds the text of the settings Source 9সোর্স 9. The local_file resource generates a local file with the given content Source 29সোর্স 29. The output block exposes the path of the file Source 8সোর্স 8.
Run:
cd tf
terraform version
terraform init -no-color
head -n 9 .terraform.lock.hcl
terraform fmt -check -diff
echo "fmt exit status: $?"
terraform validate -no-color
echo "validate exit status: $?"
printf 'variable "x" {\ntype = string\n}\n' > bad.tf
terraform fmt -check -diff
echo "fmt exit status: $?"
rm bad.tfOutput of the tutorial's run:
Terraform v1.17.2
on linux_amd64
Initializing the backend...
Initializing provider plugins...
- Finding hashicorp/local versions matching ">= 2.5.0"...
- Installing hashicorp/local v2.9.1...
- Installed hashicorp/local v2.9.1 (signed by HashiCorp)
Terraform has created a lock file .terraform.lock.hcl to record the provider
selections it made above. Include this file in your version control repository
so that Terraform can guarantee to make the same selections by default when
you run "terraform init" in the future.
Terraform has been successfully initialized!
You may now begin working with Terraform. Try running "terraform plan" to see
any changes that are required for your infrastructure. All Terraform commands
should now work.
If you ever set or change modules or backend configuration for Terraform,
rerun this command to reinitialize your working directory. If you forget, other
commands will detect it and remind you to do so if necessary.
# This file is maintained automatically by "terraform init".
# Manual edits may be lost in future updates.
provider "registry.terraform.io/hashicorp/local" {
version = "2.9.1"
constraints = ">= 2.5.0"
hashes = [
"h1:qGLHCuYSus+uHNnoEL4SuJqOs5yrNOcB7gnuHoVqizo=",
"zh:25606c7a5e308144fb627f6e31611bb52ff72bb9ae2d27af39673ab1a6b3c1bf",
fmt exit status: 0
Success! The configuration is valid.
validate exit status: 0
bad.tf
--- old/bad.tf
+++ new/bad.tf
@@ -1,3 +1,3 @@
variable "x" {
-type = string
+ type = string
}
fmt exit status: 3terraform initinstalled the provider and created.terraform.lock.hclSource 5সোর্স 5. The lock file is how Terraform remembers its choice of version Source 6সোর্স 6. The lines thatheadshows are the provider address, the version2.9.1, the constraint>= 2.5.0, and the start of the list of hashes. The tutorial wrote the constraint as>= 2.5, and Terraform wrote>= 2.5.0. The list holds checksums for your platform and for other platforms Source 6সোর্স 6. On a laterinit, Terraform returns an error if an installed package matches none of the recorded checksums Source 6সোর্স 6.- The first
terraform fmt -check -diffprinted nothing, and its exit status was 0. The exit status is 0 if the input is properly formatted, and non-zero otherwise, with a list of the file names Source 20সোর্স 20. Then the tutorial wrote a badly formatted file,bad.tf, on purpose. The secondfmtlistedbad.tf, showed the diff, and the exit status was 3. The tutorial removedbad.tfafter that. terraform validateprintedSuccess! The configuration is valid., and its exit status was 0. It checks that a configuration is syntactically valid and internally consistent Source 19সোর্স 19.
2. Plan, apply, and plan again. Run:
cd tf
terraform plan -no-color -out=tfplan -detailed-exitcode
echo "plan exit status: $?"
terraform show -json tfplan | python3 -c 'import json, sys; plan = json.load(sys.stdin); print([(c["address"], c["change"]["actions"]) for c in plan["resource_changes"]])'
terraform apply -no-color tfplan
echo "apply exit status: $?"
cat out/qa.env
terraform plan -no-color -detailed-exitcode
echo "plan exit status: $?"Output of the tutorial's run:
Terraform used the selected providers to generate the following execution
plan. Resource actions are indicated with the following symbols:
+ create
Terraform will perform the following actions:
# local_file.settings will be created
+ resource "local_file" "settings" {
+ content = <<-EOT
env=qa
base_url=http://localhost:8080
EOT
+ content_base64sha256 = (known after apply)
+ content_base64sha512 = (known after apply)
+ content_md5 = (known after apply)
+ content_sha1 = (known after apply)
+ content_sha256 = (known after apply)
+ content_sha512 = (known after apply)
+ directory_permission = "0777"
+ file_permission = "0777"
+ filename = "./out/qa.env"
+ id = (known after apply)
}
Plan: 1 to add, 0 to change, 0 to destroy.
Changes to Outputs:
+ settings_path = "./out/qa.env"
─────────────────────────────────────────────────────────────────────────────
Saved the plan to: tfplan
To perform exactly these actions, run the following command to apply:
terraform apply "tfplan"
plan exit status: 2
[('local_file.settings', ['create'])]
local_file.settings: Creating...
local_file.settings: Creation complete after 0s [id=ea8fed73fdf0af945662466adbb1135880656d6d]
Apply complete! Resources: 1 added, 0 changed, 0 destroyed.
Outputs:
settings_path = "./out/qa.env"
apply exit status: 0
env=qa
base_url=http://localhost:8080
local_file.settings: Refreshing state... [id=ea8fed73fdf0af945662466adbb1135880656d6d]
No changes. Your infrastructure matches the configuration.
Terraform has compared your real infrastructure against your configuration
and found no differences, so no changes are needed.
plan exit status: 0- The first plan saves the plan to the file
tfplanwith-out. It lists+ createfor one resource, and it ends withPlan: 1 to add, 0 to change, 0 to destroy.The values ofidand of the hashes areknown after apply. The plan showsfile_permission = "0777", which is the default of the provider Source 29সোর্স 29. -detailed-exitcodemade the exit status 2. That means that the command succeeded and that changes are present Source 21সোর্স 21.- The Python line of the tutorial reads the JSON of the saved plan. It prints the address and the
actionsof each item ofresource_changesSource 25সোর্স 25. The output shows one item, with the actioncreate. The valid values ofactionsareno-op,create,read,update,delete, and two replace pairs Source 25সোর্স 25. terraform apply tfplangot a saved plan, so it did not ask for approval Source 22সোর্স 22. It ended withApply complete! Resources: 1 added, 0 changed, 0 destroyed.The fileout/qa.envholds the two lines of the settings.- The second plan printed
No changes. Your infrastructure matches the configuration.Its exit status was 0, which means success with no changes Source 21সোর্স 21.
3. Change the file by hand, and let Terraform fix it. Run:
cd tf
printf 'env=changed-by-hand\n' > out/qa.env
terraform apply -no-color -auto-approve
cat out/qa.env
terraform plan -no-color -var env_name=QA
echo "plan exit status: $?"Output of the tutorial's run:
local_file.settings: Refreshing state... [id=ea8fed73fdf0af945662466adbb1135880656d6d]
Terraform used the selected providers to generate the following execution
plan. Resource actions are indicated with the following symbols:
+ create
Terraform will perform the following actions:
# local_file.settings will be created
+ resource "local_file" "settings" {
+ content = <<-EOT
env=qa
base_url=http://localhost:8080
EOT
+ content_base64sha256 = (known after apply)
+ content_base64sha512 = (known after apply)
+ content_md5 = (known after apply)
+ content_sha1 = (known after apply)
+ content_sha256 = (known after apply)
+ content_sha512 = (known after apply)
+ directory_permission = "0777"
+ file_permission = "0777"
+ filename = "./out/qa.env"
+ id = (known after apply)
}
Plan: 1 to add, 0 to change, 0 to destroy.
local_file.settings: Creating...
local_file.settings: Creation complete after 0s [id=ea8fed73fdf0af945662466adbb1135880656d6d]
Apply complete! Resources: 1 added, 0 changed, 0 destroyed.
Outputs:
settings_path = "./out/qa.env"
env=qa
base_url=http://localhost:8080
Planning failed. Terraform encountered an error while generating this plan.
Error: Invalid value for variable
on main.tf line 12:
12: variable "env_name" {
├────────────────
│ var.env_name is "QA"
env_name must be lower-case letters only.
This was checked by the validation rule at main.tf:17,3-13.
plan exit status: 1- The tutorial overwrote
out/qa.envby hand. The apply began withRefreshing state.... Before any operation, Terraform does a refresh to update the state with the real infrastructure Source 11সোর্স 11. - The plan then said
local_file.settings will be created, withPlan: 1 to add, 0 to change, 0 to destroy.It did not say that the file would be updated. No page that the tutorial read says why. After the apply,catshows the original two lines, so Terraform put the file back. -auto-approveskipped the question. The docs say to make sure that no one can change your infrastructure outside of your Terraform workflow when you use it Source 22সোর্স 22. The tutorial used it for a file that it can lose.- The last command passed
-var env_name=QA. Terraform refused, withError: Invalid value for variable, the message of thevalidationblock, and the exit status 1. Terraform checks the validations while it creates a plan, and it stops the operation when a condition is false Source 7সোর্স 7. The exit status 1 means an error Source 21সোর্স 21.
4. Look at the state. Run:
cd tf
terraform state list
ls terraform.tfstate*
grep -n '"content"' terraform.tfstateOutput of the tutorial's run:
local_file.settings
terraform.tfstate
terraform.tfstate.backup
22: "content": "env=qa\nbase_url=http://localhost:8080\n",terraform state listlists resources within a state Source 57সোর্স 57. It printed the one resource of the state,local_file.settings.- The folder holds
terraform.tfstateandterraform.tfstate.backup. By default, Terraform stores the state in a local file named terraform.tfstate, and a backup of the previous state in terraform.tfstate.backup Source 11সোর্স 11. - The
grepline shows the content of the file inside the state, in plain text. A local state is a plaintext file that includes any secret values you defined in your configuration Source 14সোর্স 14. The settings of this file are not secret. For sensitive content, the provider says to use thelocal_sensitive_fileresource Source 29সোর্স 29.
5. Test the configuration. Save this as tests/settings.tftest.hcl:
run "default_settings" {
command = plan
assert {
condition = local_file.settings.content == "env=qa\nbase_url=http://localhost:8080\n"
error_message = "The default settings are not what the tests expect."
}
}
run "name_with_capitals_is_refused" {
command = plan
variables {
env_name = "QA"
}
expect_failures = [var.env_name]
}
run "file_is_created_and_removed" {
command = apply
variables {
env_name = "scratch"
}
assert {
condition = output.settings_path == "./out/scratch.env"
error_message = "The file is not where the test expects it."
}
}Run it. Then the tutorial wrote a test with a wrong expectation on purpose, ran only that file, and removed it:
cd tf
terraform test -no-color
echo "test exit status: $?"
cat > tests/wrong.tftest.hcl <<'TEST'
run "wrong_expectation" {
command = plan
assert {
condition = local_file.settings.content == "env=prod\n"
error_message = "The settings are not the production settings."
}
}
TEST
terraform test -no-color -filter=tests/wrong.tftest.hcl
echo "test exit status: $?"
rm tests/wrong.tftest.hclOutput of the tutorial's run:
tests/settings.tftest.hcl... in progress
run "default_settings"... pass
run "name_with_capitals_is_refused"... pass
run "file_is_created_and_removed"... pass
tests/settings.tftest.hcl... tearing down
tests/settings.tftest.hcl... pass
Success! 3 passed, 0 failed.
test exit status: 0
tests/wrong.tftest.hcl... in progress
run "wrong_expectation"... fail
Error: Test assertion failed
on tests/wrong.tftest.hcl line 5, in run "wrong_expectation":
5: condition = local_file.settings.content == "env=prod\n"
├────────────────
│ Diff:
│ --- actual
│ +++ expected
│ - "env=qa\nbase_url=http://localhost:8080\n"
│ + "env=prod\n"
The settings are not the production settings.
tests/wrong.tftest.hcl... tearing down
tests/wrong.tftest.hcl... fail
Failure! 0 passed, 1 failed.
test exit status: 1- By default, the directory with the test files is named
testsSource 27সোর্স 27. A test file has one or morerunblocks Source 26সোর্স 26. - The first two
runblocks usecommand = plan, so they create no infrastructure Source 26সোর্স 26. The first one asserts the default content of the file. The second one setsenv_name = "QA". Itsexpect_failures = [var.env_name]lists a variable that should fail its custom condition Source 26সোর্স 26. It passes, becauseQAbreaks thevalidationrule. - The third
runblock uses the default, which applies the configuration. By default, tests create real infrastructure Source 26সোর্স 26. Here it created./out/scratch.env, and it checked the output. The output showstearing down. After a test file has run, Terraform tries to destroy what is left Source 27সোর্স 27. - The result was
Success! 3 passed, 0 failed., and the exit status was 0. - A test file keeps its own state, apart from the state of the configuration Source 27সোর্স 27. The file
out/qa.envof step 3 was still there, and step 6 destroys it. - The wrong test asserts
env=prod, and it failed. Terraform printedTest assertion failed, theDiffof the actual and the expected value, and theerror_message. The exit status was 1.-filterlimits the run to the given test file Source 27সোর্স 27.
6. Destroy it. Run:
cd tf
terraform destroy -no-color -auto-approve
ls out
terraform state list
echo "state list exit status: $?"Output of the tutorial's run:
local_file.settings: Refreshing state... [id=ea8fed73fdf0af945662466adbb1135880656d6d]
Terraform used the selected providers to generate the following execution
plan. Resource actions are indicated with the following symbols:
- destroy
Terraform will perform the following actions:
# local_file.settings will be destroyed
- resource "local_file" "settings" {
- content = <<-EOT
env=qa
base_url=http://localhost:8080
EOT -> null
- content_base64sha256 = "O3FCs3DMCHcVvw4jqt5VgiQLrnoBpfbzXYTgwrb2xdw=" -> null
- content_base64sha512 = "dr4Aa0ooINRuEdBv6qMIMiEdeMzD70f1k+vSzr/OA9tO4kTf/iNCLA4AjpaSAg8Au6vZ0ayK3IWB9XOgobl9uA==" -> null
- content_md5 = "71a00ff38b756e3d0971971589dfeffc" -> null
- content_sha1 = "ea8fed73fdf0af945662466adbb1135880656d6d" -> null
- content_sha256 = "3b7142b370cc087715bf0e23aade5582240bae7a01a5f6f35d84e0c2b6f6c5dc" -> null
- content_sha512 = "76be006b4a2820d46e11d06feaa30832211d78ccc3ef47f593ebd2cebfce03db4ee244dffe23422c0e008e9692020f00bbabd9d1ac8adc8581f573a0a1b97db8" -> null
- directory_permission = "0777" -> null
- file_permission = "0777" -> null
- filename = "./out/qa.env" -> null
- id = "ea8fed73fdf0af945662466adbb1135880656d6d" -> null
}
Plan: 0 to add, 0 to change, 1 to destroy.
Changes to Outputs:
- settings_path = "./out/qa.env" -> null
local_file.settings: Destroying... [id=ea8fed73fdf0af945662466adbb1135880656d6d]
local_file.settings: Destruction complete after 0s
Destroy complete! Resources: 1 destroyed.
state list exit status: 0terraform destroydeprovisions all objects that the configuration manages Source 23সোর্স 23. The plan lists- destroy, and it ends withPlan: 0 to add, 0 to change, 1 to destroy.The apply ended withDestroy complete! Resources: 1 destroyed.ls outprinted nothing, so the file is gone.terraform state listprinted nothing, and its exit status was 0. The state holds no resource.- The runner of the tutorial then removed the whole folder of the run.
7. Build a Docker image with Packer. Save this as image.pkr.hcl in a folder named pk:
packer {
required_plugins {
docker = {
version = ">= 1.1.0"
source = "github.com/hashicorp/docker"
}
}
}
source "docker" "alpine" {
image = "alpine:latest"
pull = false
commit = true
}
build {
name = "qa-base"
sources = ["source.docker.alpine"]
provisioner "shell" {
inline = [
"echo 'built by Packer' > /etc/qa-image.txt",
"apk add --no-cache curl",
]
}
post-processor "docker-tag" {
repository = "packer-practice-qa-base"
tags = ["1.0"]
}
}The file is the tutorial's own, and it has no comment. The packer block lists the Docker plugin in required_plugins Source 37সোর্স 37. The source block holds the builder Source 33সোর্স 33. commit = true makes Packer commit the container to an image Source 41সোর্স 41. pull = false makes Packer use the image that is already on the machine Source 41সোর্স 41. The build block names the build qa-base and picks the source. A provisioner block defines how to configure a provisioner Source 35সোর্স 35. The docker-tag post-processor takes an artifact from the docker builder that was committed, and tags it into a repository Source 42সোর্স 42. The name, the tag, and the two commands of the provisioner are the tutorial's own choice.
Run:
cd pk
packer version
packer init .
packer fmt -check .
echo "fmt exit status: $?"
packer validate .
echo "validate exit status: $?"
packer build -color=false .
docker run --rm packer-practice-qa-base:1.0 cat /etc/qa-image.txt
docker run --rm packer-practice-qa-base:1.0 curl --version
docker rmi packer-practice-qa-base:1.0Output of the tutorial's run:
Packer v1.16.2
[1;36mInstalled plugin github.com/hashicorp/docker v1.1.5 in "/work/home/.config/packer/plugins/github.com/hashicorp/docker/packer-plugin-docker_v1.1.5_x5.0_linux_amd64"[0m
fmt exit status: 0
The configuration is valid.
validate exit status: 0
==> qa-base.docker.alpine: Creating a temporary directory for sharing data...
==> qa-base.docker.alpine: Starting docker container...
==> qa-base.docker.alpine: Run command: docker run -v /work/home/.config/packer/tmp460997856:/packer-files -d -i -t --entrypoint=/bin/sh -- alpine:latest
==> qa-base.docker.alpine: Container ID: eef29ce691014a83fbc715656cc8c39c4de4496baefd9876a8b53aee648a7471
==> qa-base.docker.alpine: Provisioning with shell script: /work/tmp/packer-shell4200093466
==> qa-base.docker.alpine: (1/9) Installing brotli-libs (1.2.1-r0)
==> qa-base.docker.alpine: (2/9) Installing c-ares (1.34.9-r0)
==> qa-base.docker.alpine: (3/9) Installing libunistring (1.4.2-r0)
==> qa-base.docker.alpine: (4/9) Installing libidn2 (2.3.8-r0)
==> qa-base.docker.alpine: (5/9) Installing nghttp2-libs (1.70.0-r0)
==> qa-base.docker.alpine: (6/9) Installing libpsl (0.21.5-r3)
==> qa-base.docker.alpine: (7/9) Installing zstd-libs (1.5.7-r2)
==> qa-base.docker.alpine: (8/9) Installing libcurl (8.23.0-r0)
==> qa-base.docker.alpine: (9/9) Installing curl (8.23.0-r0)
==> qa-base.docker.alpine: Executing busybox-1.37.0-r31.trigger
==> qa-base.docker.alpine: OK: 13.1 MiB in 25 packages
==> qa-base.docker.alpine: Committing the container
==> qa-base.docker.alpine: Image ID: sha256:43b55b1018aeab608ed6ca143e9b73c28aa3b677a418ebef52f6e7f62c4ce9f4
==> qa-base.docker.alpine: Killing the container: eef29ce691014a83fbc715656cc8c39c4de4496baefd9876a8b53aee648a7471
==> qa-base.docker.alpine: Running post-processor: (type docker-tag)
==> qa-base.docker.alpine (docker-tag): Tagging image: sha256:43b55b1018aeab608ed6ca143e9b73c28aa3b677a418ebef52f6e7f62c4ce9f4
==> qa-base.docker.alpine (docker-tag): Repository: packer-practice-qa-base:1.0
Build 'qa-base.docker.alpine' finished after 2 seconds 828 milliseconds.
==> Wait completed after 2 seconds 829 milliseconds
==> Builds finished. The artifacts of successful builds are:
--> qa-base.docker.alpine: Imported Docker image: sha256:43b55b1018aeab608ed6ca143e9b73c28aa3b677a418ebef52f6e7f62c4ce9f4
--> qa-base.docker.alpine: Imported Docker image: packer-practice-qa-base:1.0 with tags packer-practice-qa-base:1.0
built by Packer
curl 8.23.0 (x86_64-alpine-linux-musl) libcurl/8.23.0 OpenSSL/3.5.9 zlib/1.3.2 brotli/1.2.1 zstd/1.5.7 c-ares/1.34.9 libidn2/2.3.8 libpsl/0.21.5 nghttp2/1.70.0
Release-Date: 2026-10-14
Protocols: dict file ftp ftps gopher gophers http https imap imaps ipfs ipns mqtt mqtts pop3 pop3s rtsp smtp smtps telnet tftp ws wss
Features: alt-svc AsynchDNS brotli HSTS HTTP2 HTTPS-proxy IDN IPv6 Largefile libz PSL SSL threadsafe UnixSockets zstd
Untagged: packer-practice-qa-base:1.0
Deleted: sha256:43b55b1018aeab608ed6ca143e9b73c28aa3b677a418ebef52f6e7f62c4ce9f4packer initinstalled the plugingithub.com/hashicorp/dockerSource 37সোর্স 37. The path in the output is in the empty home folder of the run, which the page shows as/work/home.packer fmt -check .andpacker validate .both ended with the exit status 0.packer fmtformats HCL2 files to a canonical format and style Source 53সোর্স 53. With-check, the exit status is 0 only if all input is properly formatted Source 53সোর্স 53.packer validateprintedThe configuration is valid.It returns a zero exit status on success Source 39সোর্স 39.packer buildstarted a container fromalpine:latest, ran the provisioner in it, and committed the container Source 41সোর্স 41. Thedocker-tagpost-processor then tagged the imagepacker-practice-qa-base:1.0Source 42সোর্স 42. It used no Dockerfile Source 41সোর্স 41.- The two
docker runcommands used the new image.cat /etc/qa-image.txtprintedbuilt by Packer, andcurl --versionprinted the version of thecurlthat the provisioner installed. This is the tutorial's own check of the image. docker rmiremoved the tag and the image.
8. Render a Crossplane composition. Save this as app.yaml in a folder named xp:
apiVersion: example.crossplane.io/v1
kind: App
metadata:
namespace: default
name: my-app
spec:
image: nginxThis is an App that asks for the image nginx. The other three files are xrd.yaml (step 9 shows it), fn-patch-and-transform.yaml (6 lines, the function), and composition-yaml.yaml (72 lines). Take them from the page "Get started with composition" Source 50সোর্স 50. The composition has one pipeline step. It uses the function crossplane-contrib-function-patch-and-transform. It builds a Deployment with replicas: 2 and a Service with the port 8080 for the port 80. A patch copies spec.image of the App into the image of the Deployment. A composition is a template for creating several Kubernetes resources as one composite resource Source 45সোর্স 45.
Run:
cd xp
crossplane version --client
crossplane composition render app.yaml composition-yaml.yaml fn-patch-and-transform.yaml
echo "render exit status: $?"Output of the tutorial's run:
Client Version: v2.5.0
---
apiVersion: example.crossplane.io/v1
kind: App
metadata:
name: my-app
namespace: default
spec:
crossplane:
resourceRefs:
- apiVersion: apps/v1
kind: Deployment
name: my-app-3ebefffb6666
- apiVersion: v1
kind: Service
name: my-app-bb6a52963bfb
status:
conditions:
- lastTransitionTime: "2024-01-01T00:00:00Z"
reason: WatchCircuitClosed
status: "True"
type: Responsive
- lastTransitionTime: "2024-01-01T00:00:00Z"
reason: ReconcileSuccess
status: "True"
type: Synced
- lastTransitionTime: "2024-01-01T00:00:00Z"
message: 'Unready resources: deployment, service'
reason: Creating
status: "False"
type: Ready
---
apiVersion: apps/v1
kind: Deployment
metadata:
annotations:
crossplane.io/composition-resource-name: deployment
generateName: my-app-
labels:
crossplane.io/composite: my-app
example.crossplane.io/app: my-app
name: my-app-3ebefffb6666
namespace: default
ownerReferences:
- apiVersion: example.crossplane.io/v1
blockOwnerDeletion: true
controller: true
kind: App
name: my-app
uid: 9de988c4-8410-5318-8780-2295cef818ff
spec:
replicas: 2
selector:
matchLabels:
example.crossplane.io/app: my-app
template:
metadata:
labels:
example.crossplane.io/app: my-app
spec:
containers:
- image: nginx
name: app
ports:
- containerPort: 80
---
apiVersion: v1
kind: Service
metadata:
annotations:
crossplane.io/composition-resource-name: service
generateName: my-app-
labels:
crossplane.io/composite: my-app
example.crossplane.io/app: my-app
name: my-app-bb6a52963bfb
namespace: default
ownerReferences:
- apiVersion: example.crossplane.io/v1
blockOwnerDeletion: true
controller: true
kind: App
name: my-app
uid: 9de988c4-8410-5318-8780-2295cef818ff
spec:
ports:
- port: 8080
protocol: TCP
targetPort: 80
selector:
example.crossplane.io/app: my-app
render exit status: 0crossplane version --clientprinted the client version, and it needs no server Source 52সোর্স 52.composition renderneeds a container runtime that works with Docker Source 51সোর্স 51. By default, it pulls and runs the composition functions with Docker Source 52সোর্স 52.composition renderprinted three documents: theAppwithresourceRefs, a Deployment, and a Service. It shows what resources the composition would create or change Source 52সোর্স 52. The Deployment hasreplicas: 2andimage: nginx, the value ofspec.imageof theApp. The Service maps the port 8080 to the port 80.- The status of the
AppsaysUnready resources: deployment, service, and eachlastTransitionTimeis2024-01-01T00:00:00Z. Nothing was created, becauserenderruns locally. No page that the tutorial read says why the time is fixed. The exit status was 0.
9. Validate the App against its schema. Save this as xrd.yaml:
apiVersion: apiextensions.crossplane.io/v2
kind: CompositeResourceDefinition
metadata:
name: apps.example.crossplane.io
spec:
scope: Namespaced
group: example.crossplane.io
names:
kind: App
plural: apps
versions:
- name: v1
served: true
referenceable: true
schema:
openAPIV3Schema:
type: object
properties:
spec:
type: object
properties:
image:
description: The app's OCI container image.
type: string
required:
- image
status:
type: object
properties:
replicas:
description: The number of available app replicas.
type: integer
address:
description: The app's IP address.
type: stringThe XRD defines the schema of the custom API Source 44সোর্স 44. In it, spec.image is a string, and it is required.
Run:
cd xp
crossplane resource validate xrd.yaml app.yaml
echo "validate exit status: $?"
sed 's/image: nginx/imagee: nginx/' app.yaml > bad-app.yaml
crossplane resource validate xrd.yaml bad-app.yaml
echo "validate exit status: $?"
crossplane composition render bad-app.yaml composition-yaml.yaml fn-patch-and-transform.yaml | grep -c "image:"
echo "render exit status: ${PIPESTATUS[0]}"Output of the tutorial's run:
schemas does not exist, downloading: xpkg.crossplane.io/crossplane/crossplane:stable
[✓] example.crossplane.io/v1, Kind=App, my-app validated successfully
Total 1 resources: 0 missing schemas, 1 success cases, 0 failure cases
validate exit status: 0
[x] schema validation error example.crossplane.io/v1, Kind=App, my-app : spec.image: Required value
[x] schema validation error example.crossplane.io/v1, Kind=App, my-app : spec.imagee: Invalid value: "imagee": unknown field: "imagee"
Total 1 resources: 0 missing schemas, 0 success cases, 1 failure cases
crossplane: error: could not validate all resources
validate exit status: 1
0
render exit status: 0- The first
crossplane resource validateprintedschemas does not exist, downloading: xpkg.crossplane.io/crossplane/crossplane:stable, and thenvalidated successfully. The summary says1 success cases, and the exit status was 0. The command checks resources against the schemas of XRDs, CRDs, providers, functions, and configurations Source 52সোর্স 52. No page that the tutorial read says what was downloaded. - Then the tutorial copied
app.yamltobad-app.yaml, with a typo:imageeforimage.validateprinted two errors,spec.image: Required valueandunknown field: "imagee", and the exit status was 1. The command detects unknown fields Source 52সোর্স 52. renderof the same file exited with 0, andgrep -c "image:"counted 0 lines in its output. Sorenderdid not refuse the typo, and the Deployment that it printed has no image. The docs markresource validateas beta Source 52সোর্স 52.
বাংলা ব্যাখ্যা
টিউটোরিয়াল ১ থেকে ৯ নম্বর ধাপ চালিয়েছে 2026-11-19 তারিখে 15:22-এ (+06), Linux 7.0.0-43-generic-এ, Terraform v1.17.2, Packer v1.16.2, Crossplane CLI v2.5.0, Docker 29.10.0 আর bash 5.3.9 দিয়ে। এই page-এর output টিউটোরিয়ালের run থেকে নেওয়া। প্রতিটা ধাপ চলেছে নিজের shell-এ, practice folder-এর একটা কপিতে, একটা নতুন, খালি HOME দিয়ে। page-এ run-এর folder দেখানো হয়েছে /work নামে। ধাপগুলোর আগে এমন কোনো variable সেট ছিল না, যার নাম TF_, PACKER_, CHECKPOINT_, XP_ বা CROSSPLANE_ দিয়ে শুরু। run-এর পর টিউটোরিয়াল আসল home folder-এর প্রথম স্তরের entry-গুলো আগের তালিকার সঙ্গে মিলিয়েছে, আর নতুন কোনোটা ছিল না। টিউটোরিয়াল network নজর করেনি।
১ থেকে ৬ নম্বর ধাপ Terraform ব্যবহার করে local provider দিয়ে। সেগুলো আপনার মেশিনে একটা text file লেখে, আর কোনো cloud account লাগে না। terraform init network দিয়ে hashicorp/local provider v2.9.1 download করেছে। ৭ নম্বর ধাপ Packer দিয়ে একটা Docker image বানায়। packer init Docker plugin v1.1.5 download করেছে। provisioner image-এ curl install করেছে Alpine-এর package repository থেকে, তাই এই ধাপও network ব্যবহার করে। base image alpine:latest (sha256:f59abe656b69) আগে থেকেই মেশিনে ছিল, আর Packer সেটা pull করেনি। Packer-এর বানানো image টিউটোরিয়াল সরিয়ে দিয়েছে।
৮ আর ৯ নম্বর ধাপ Crossplane CLI চালায়, আর কোনো cluster লাগে না। এই দুই ধাপে Docker দুটো image pull করেছে: xpkg.crossplane.io/crossplane/crossplane:stable (181MB, digest sha256:00ec53eefb39, তৈরি 2026-11-18) আর xpkg.crossplane.io/crossplane-contrib/function-patch-and-transform:v0.8.2 (87MB)। run-এর পর টিউটোরিয়াল দুটো image-ই সরিয়ে দিয়েছে। এই ধাপগুলোর চারটা manifest file এসেছে "Get started with composition" page থেকে Source 50সোর্স 50। টিউটোরিয়াল file-গুলোর লাইন page-এর সঙ্গে মিলিয়েছে, indentation বাদ দিয়ে, আর প্রতিটা লাইন সেখানে ছিল, একই ক্রমে।
যে সিদ্ধান্ত কোনো source দেয় না, সেগুলো টিউটোরিয়ালের নিজের: file-গুলোর নাম, file-এর ভেতরের নাম, >= 1.6 আর >= 2.5 version, base image, provisioner-এর command, ৫ নম্বর ধাপের ভুল test, আর ৯ নম্বর ধাপের typo।
tool-গুলো install করুন। 2026-11-19 তারিখে Terraform-এর install page সর্বশেষ version হিসেবে 1.17.2 দেখিয়েছিল Source 55সোর্স 55, আর Packer-এর install page দেখিয়েছিল 1.16.2 Source 56সোর্স 56। দুটো page-ই package-manager command আর একটা binary download তালিকাভুক্ত করে Source 55সোর্স 55 Source 56সোর্স 56। টিউটোরিয়াল binary download নিয়েছে, একজন user-এর জন্য, ~/.local/bin-এ, sudo ছাড়া। 2026-11-19 তারিখে সেটা Terraform install করেছে 14:52-এ আর Packer 14:52-এ।
একটা binary-তে ক্ষতিকর code লুকিয়ে থাকতে পারে। HashiCorp বলে, binary চালানোর আগে যাচাই করুন যে HashiCorp সেটা তৈরি ও sign করেছে Source 54সোর্স 54। HashiCorp তার product archive-এর checksum sign করতে একটা public PGP key ব্যবহার করে Source 54সোর্স 54। page-টা key-র fingerprint দেয় Source 54সোর্স 54। প্রতিটা tool-এর জন্য টিউটোরিয়াল কিছু install করার আগে তিনটা জিনিস যাচাই করেছে। hashicorp.com-এর key file-এ সেই fingerprint আছে। SHA256SUMS file-এর signature বৈধ, আর সেই key সেটা বানিয়েছে। zip file-এর SHA-256 হলো SHA256SUMS file-এ থাকা মানটাই। Terraform zip-এর SHA-256 শুরু হয় e6f16b2f দিয়ে, আর Packer zip-এরটা abbfe0cf দিয়ে।
Crossplane CLI একটা একক standalone binary Source 51সোর্স 51। এর কিছু command, যেমন crossplane composition render, Docker-এর সঙ্গে কাজ করে এমন একটা container runtime চায় Source 51সোর্স 51। page যেভাবে বলেছে, টিউটোরিয়াল binary-টা হাতে download করেছে Source 51সোর্স 51। page বলে সেটা PATH-এর একটা folder-এ সরাতে, যেমন /usr/local/bin Source 51সোর্স 51। টিউটোরিয়াল সেটা রেখেছে ~/.local/bin-এ, 15:00-এ। binary-টা পাশে থাকা .sha256 file-এর সঙ্গে মিলিয়েছে, আর এর SHA-256 শুরু হয় 065dd6b4 দিয়ে। সেই file আসে একই host থেকে, আর টিউটোরিয়াল তার কোনো signature পায়নি। তাই এই যাচাই শুধু দেখায় যে download-টা অক্ষত।
১. configuration লিখুন, আর যাচাই করুন। এটা tf নামের একটা folder-এ main.tf নামে save করুন:
terraform {
required_version = ">= 1.6"
required_providers {
local = {
source = "hashicorp/local"
version = ">= 2.5"
}
}
}
variable "env_name" {
type = string
description = "Name of the test environment."
default = "qa"
validation {
condition = can(regex("^[a-z]+$", var.env_name))
error_message = "env_name must be lower-case letters only."
}
}
variable "base_url" {
type = string
description = "Address of the application under test."
default = "http://localhost:8080"
}
locals {
settings = "env=${var.env_name}\nbase_url=${var.base_url}\n"
}
resource "local_file" "settings" {
filename = "${path.module}/out/${var.env_name}.env"
content = local.settings
}
output "settings_path" {
value = local_file.settings.filename
}file-টা টিউটোরিয়ালের নিজের, আর এতে কোনো comment নেই। terraform block required_providers block-এ provider-টার নাম দেয় Source 5সোর্স 5। একটা variable block একটা function argument-এর মতো Source 7সোর্স 7। env_name-এর validation block বড় হাতের অক্ষর প্রত্যাখ্যান করে। locals block settings-এর text ধরে রাখে Source 9সোর্স 9। local_file resource দেওয়া content দিয়ে একটা স্থানীয় file তৈরি করে Source 29সোর্স 29। output block file-টার path প্রকাশ করে Source 8সোর্স 8।
চালান:
cd tf
terraform version
terraform init -no-color
head -n 9 .terraform.lock.hcl
terraform fmt -check -diff
echo "fmt exit status: $?"
terraform validate -no-color
echo "validate exit status: $?"
printf 'variable "x" {\ntype = string\n}\n' > bad.tf
terraform fmt -check -diff
echo "fmt exit status: $?"
rm bad.tfটিউটোরিয়ালের run-এর output:
Terraform v1.17.2
on linux_amd64
Initializing the backend...
Initializing provider plugins...
- Finding hashicorp/local versions matching ">= 2.5.0"...
- Installing hashicorp/local v2.9.1...
- Installed hashicorp/local v2.9.1 (signed by HashiCorp)
Terraform has created a lock file .terraform.lock.hcl to record the provider
selections it made above. Include this file in your version control repository
so that Terraform can guarantee to make the same selections by default when
you run "terraform init" in the future.
Terraform has been successfully initialized!
You may now begin working with Terraform. Try running "terraform plan" to see
any changes that are required for your infrastructure. All Terraform commands
should now work.
If you ever set or change modules or backend configuration for Terraform,
rerun this command to reinitialize your working directory. If you forget, other
commands will detect it and remind you to do so if necessary.
# This file is maintained automatically by "terraform init".
# Manual edits may be lost in future updates.
provider "registry.terraform.io/hashicorp/local" {
version = "2.9.1"
constraints = ">= 2.5.0"
hashes = [
"h1:qGLHCuYSus+uHNnoEL4SuJqOs5yrNOcB7gnuHoVqizo=",
"zh:25606c7a5e308144fb627f6e31611bb52ff72bb9ae2d27af39673ab1a6b3c1bf",
fmt exit status: 0
Success! The configuration is valid.
validate exit status: 0
bad.tf
--- old/bad.tf
+++ new/bad.tf
@@ -1,3 +1,3 @@
variable "x" {
-type = string
+ type = string
}
fmt exit status: 3terraform initprovider install করেছে আর.terraform.lock.hclবানিয়েছে Source 5সোর্স 5। lock file-এর মাধ্যমেই Terraform তার বেছে নেওয়া version মনে রাখে Source 6সোর্স 6।headযে লাইনগুলো দেখায়, সেগুলো হলো provider-এর ঠিকানা, version2.9.1, constraint>= 2.5.0, আর hash-এর তালিকার শুরু। টিউটোরিয়াল constraint লিখেছিল>= 2.5, আর Terraform লিখেছে>= 2.5.0। তালিকায় আছে আপনার platform-এর আর অন্য platform-এর checksum Source 6সোর্স 6। পরের কোনোinit-এ install করা package রেকর্ড করা কোনো checksum-এর সঙ্গে না মিললে Terraform error দেয় Source 6সোর্স 6।- প্রথম
terraform fmt -check -diffকিছু ছাপেনি, আর এর exit status ছিল ০। input ঠিকমতো format করা থাকলে exit status ০, নইলে শূন্য নয়, আর সঙ্গে file-এর নামের তালিকা Source 20সোর্স 20। তারপর টিউটোরিয়াল ইচ্ছে করে একটা খারাপভাবে format করা filebad.tfলিখেছে। দ্বিতীয়fmtbad.tfতালিকাভুক্ত করেছে, diff দেখিয়েছে, আর exit status ছিল ৩। এরপর টিউটোরিয়ালbad.tfসরিয়ে দিয়েছে। terraform validateছেপেছেSuccess! The configuration is valid., আর এর exit status ছিল ০। এটা যাচাই করে, একটা configuration syntax-এর দিক থেকে বৈধ আর ভেতরে সামঞ্জস্যপূর্ণ কি না Source 19সোর্স 19।
২. plan করুন, apply করুন, আবার plan করুন। চালান:
cd tf
terraform plan -no-color -out=tfplan -detailed-exitcode
echo "plan exit status: $?"
terraform show -json tfplan | python3 -c 'import json, sys; plan = json.load(sys.stdin); print([(c["address"], c["change"]["actions"]) for c in plan["resource_changes"]])'
terraform apply -no-color tfplan
echo "apply exit status: $?"
cat out/qa.env
terraform plan -no-color -detailed-exitcode
echo "plan exit status: $?"টিউটোরিয়ালের run-এর output:
Terraform used the selected providers to generate the following execution
plan. Resource actions are indicated with the following symbols:
+ create
Terraform will perform the following actions:
# local_file.settings will be created
+ resource "local_file" "settings" {
+ content = <<-EOT
env=qa
base_url=http://localhost:8080
EOT
+ content_base64sha256 = (known after apply)
+ content_base64sha512 = (known after apply)
+ content_md5 = (known after apply)
+ content_sha1 = (known after apply)
+ content_sha256 = (known after apply)
+ content_sha512 = (known after apply)
+ directory_permission = "0777"
+ file_permission = "0777"
+ filename = "./out/qa.env"
+ id = (known after apply)
}
Plan: 1 to add, 0 to change, 0 to destroy.
Changes to Outputs:
+ settings_path = "./out/qa.env"
─────────────────────────────────────────────────────────────────────────────
Saved the plan to: tfplan
To perform exactly these actions, run the following command to apply:
terraform apply "tfplan"
plan exit status: 2
[('local_file.settings', ['create'])]
local_file.settings: Creating...
local_file.settings: Creation complete after 0s [id=ea8fed73fdf0af945662466adbb1135880656d6d]
Apply complete! Resources: 1 added, 0 changed, 0 destroyed.
Outputs:
settings_path = "./out/qa.env"
apply exit status: 0
env=qa
base_url=http://localhost:8080
local_file.settings: Refreshing state... [id=ea8fed73fdf0af945662466adbb1135880656d6d]
No changes. Your infrastructure matches the configuration.
Terraform has compared your real infrastructure against your configuration
and found no differences, so no changes are needed.
plan exit status: 0- প্রথম plan
-outদিয়ে plan-টাtfplanfile-এ save করে। এটা একটা resource-এর জন্য+ createতালিকাভুক্ত করে, আর শেষ হয়Plan: 1 to add, 0 to change, 0 to destroy.দিয়ে।idআর hash-গুলোর মানknown after apply। plan-এ দেখা যায়file_permission = "0777", যা provider-এর default Source 29সোর্স 29। -detailed-exitcodeexit status ২ করেছে। তার মানে command সফল হয়েছে আর পরিবর্তন আছে Source 21সোর্স 21।- টিউটোরিয়ালের Python লাইন saved plan-এর JSON পড়ে। এটা
resource_changes-এর প্রতিটা item-এর address আরactionsছাপে Source 25সোর্স 25। output-এ একটা item, actioncreate।actions-এর বৈধ মানno-op,create,read,update,delete, আর দুটো replace জোড়া Source 25সোর্স 25। terraform apply tfplanএকটা saved plan পেয়েছে, তাই অনুমোদন চায়নি Source 22সোর্স 22। শেষ হয়েছেApply complete! Resources: 1 added, 0 changed, 0 destroyed.দিয়ে।out/qa.envfile-এ settings-এর দুটো লাইন আছে।- দ্বিতীয় plan ছেপেছে
No changes. Your infrastructure matches the configuration.এর exit status ছিল ০, যার মানে সফল, কোনো পরিবর্তন নেই Source 21সোর্স 21।
৩. file-টা হাতে বদলান, আর Terraform-কে ঠিক করতে দিন। চালান:
cd tf
printf 'env=changed-by-hand\n' > out/qa.env
terraform apply -no-color -auto-approve
cat out/qa.env
terraform plan -no-color -var env_name=QA
echo "plan exit status: $?"টিউটোরিয়ালের run-এর output:
local_file.settings: Refreshing state... [id=ea8fed73fdf0af945662466adbb1135880656d6d]
Terraform used the selected providers to generate the following execution
plan. Resource actions are indicated with the following symbols:
+ create
Terraform will perform the following actions:
# local_file.settings will be created
+ resource "local_file" "settings" {
+ content = <<-EOT
env=qa
base_url=http://localhost:8080
EOT
+ content_base64sha256 = (known after apply)
+ content_base64sha512 = (known after apply)
+ content_md5 = (known after apply)
+ content_sha1 = (known after apply)
+ content_sha256 = (known after apply)
+ content_sha512 = (known after apply)
+ directory_permission = "0777"
+ file_permission = "0777"
+ filename = "./out/qa.env"
+ id = (known after apply)
}
Plan: 1 to add, 0 to change, 0 to destroy.
local_file.settings: Creating...
local_file.settings: Creation complete after 0s [id=ea8fed73fdf0af945662466adbb1135880656d6d]
Apply complete! Resources: 1 added, 0 changed, 0 destroyed.
Outputs:
settings_path = "./out/qa.env"
env=qa
base_url=http://localhost:8080
Planning failed. Terraform encountered an error while generating this plan.
Error: Invalid value for variable
on main.tf line 12:
12: variable "env_name" {
├────────────────
│ var.env_name is "QA"
env_name must be lower-case letters only.
This was checked by the validation rule at main.tf:17,3-13.
plan exit status: 1- টিউটোরিয়াল
out/qa.envহাতে overwrite করেছে। apply শুরু হয়েছেRefreshing state...দিয়ে। যেকোনো operation-এর আগে Terraform একটা refresh করে, যাতে state বাস্তব infrastructure-এর সঙ্গে হালনাগাদ হয় Source 11সোর্স 11। - তারপর plan বলেছে
local_file.settings will be created, সঙ্গেPlan: 1 to add, 0 to change, 0 to destroy.এটা বলেনি যে file-টা update হবে। টিউটোরিয়াল যে page-গুলো পড়েছে, তার কোনোটাই বলে না কেন। apply-এর পরcatমূল দুটো লাইন দেখায়, তাই Terraform file-টা ফিরিয়ে দিয়েছে। -auto-approveপ্রশ্নটা বাদ দিয়েছে। docs বলে, এটা ব্যবহার করলে নিশ্চিত করতে যে আপনার Terraform workflow-এর বাইরে কেউ আপনার infrastructure বদলাতে পারে না Source 22সোর্স 22। টিউটোরিয়াল এটা ব্যবহার করেছে এমন একটা file-এর জন্য, যা সে হারাতে পারে।- শেষ command
-var env_name=QAদিয়েছে। Terraform প্রত্যাখ্যান করেছেError: Invalid value for variableদিয়ে, সঙ্গেvalidationblock-এর বার্তা, আর exit status ১। Terraform plan বানানোর সময় validation যাচাই করে, আর condition মিথ্যা হলে operation থামিয়ে দেয় Source 7সোর্স 7। exit status ১ মানে error Source 21সোর্স 21।
৪. state দেখুন। চালান:
cd tf
terraform state list
ls terraform.tfstate*
grep -n '"content"' terraform.tfstateটিউটোরিয়ালের run-এর output:
local_file.settings
terraform.tfstate
terraform.tfstate.backup
22: "content": "env=qa\nbase_url=http://localhost:8080\n",terraform state listএকটা state-এর ভেতরের resource তালিকাভুক্ত করে Source 57সোর্স 57। এটা state-এর একমাত্র resource ছেপেছে,local_file.settings।- folder-এ আছে
terraform.tfstateআরterraform.tfstate.backup। by default Terraform state রাখে terraform.tfstate নামের একটা স্থানীয় file-এ, আর আগের state-এর backup রাখে terraform.tfstate.backup-এ Source 11সোর্স 11। grepলাইন state-এর ভেতরে file-এর content সাধারণ text-এ দেখায়। একটা স্থানীয় state হলো সাধারণ text file, যাতে আপনার configuration-এ ঠিক করা যেকোনো গোপন মান থাকে Source 14সোর্স 14। এই file-এর settings গোপন নয়। সংবেদনশীল content-এর জন্য provider বলেlocal_sensitive_fileresource ব্যবহার করতে Source 29সোর্স 29।
৫. configuration test করুন। এটা tests/settings.tftest.hcl নামে save করুন:
run "default_settings" {
command = plan
assert {
condition = local_file.settings.content == "env=qa\nbase_url=http://localhost:8080\n"
error_message = "The default settings are not what the tests expect."
}
}
run "name_with_capitals_is_refused" {
command = plan
variables {
env_name = "QA"
}
expect_failures = [var.env_name]
}
run "file_is_created_and_removed" {
command = apply
variables {
env_name = "scratch"
}
assert {
condition = output.settings_path == "./out/scratch.env"
error_message = "The file is not where the test expects it."
}
}এটা চালান। তারপর টিউটোরিয়াল ইচ্ছে করে ভুল প্রত্যাশার একটা test লিখেছে, শুধু সেই file চালিয়েছে, আর সরিয়ে দিয়েছে:
cd tf
terraform test -no-color
echo "test exit status: $?"
cat > tests/wrong.tftest.hcl <<'TEST'
run "wrong_expectation" {
command = plan
assert {
condition = local_file.settings.content == "env=prod\n"
error_message = "The settings are not the production settings."
}
}
TEST
terraform test -no-color -filter=tests/wrong.tftest.hcl
echo "test exit status: $?"
rm tests/wrong.tftest.hclটিউটোরিয়ালের run-এর output:
tests/settings.tftest.hcl... in progress
run "default_settings"... pass
run "name_with_capitals_is_refused"... pass
run "file_is_created_and_removed"... pass
tests/settings.tftest.hcl... tearing down
tests/settings.tftest.hcl... pass
Success! 3 passed, 0 failed.
test exit status: 0
tests/wrong.tftest.hcl... in progress
run "wrong_expectation"... fail
Error: Test assertion failed
on tests/wrong.tftest.hcl line 5, in run "wrong_expectation":
5: condition = local_file.settings.content == "env=prod\n"
├────────────────
│ Diff:
│ --- actual
│ +++ expected
│ - "env=qa\nbase_url=http://localhost:8080\n"
│ + "env=prod\n"
The settings are not the production settings.
tests/wrong.tftest.hcl... tearing down
tests/wrong.tftest.hcl... fail
Failure! 0 passed, 1 failed.
test exit status: 1- by default test file-এর directory-র নাম
testsSource 27সোর্স 27। একটা test file-এ এক বা একাধিকrunblock থাকে Source 26সোর্স 26। - প্রথম দুটো
runblockcommand = planব্যবহার করে, তাই কোনো infrastructure তৈরি করে না Source 26সোর্স 26। প্রথমটা file-এর default content assert করে। দ্বিতীয়টাenv_name = "QA"সেট করে। এরexpect_failures = [var.env_name]এমন একটা variable তালিকাভুক্ত করে, যার তার custom condition-এ ব্যর্থ হওয়া উচিত Source 26সোর্স 26। এটা পাস করে, কারণQAvalidationrule ভাঙে। - তৃতীয়
runblock default ব্যবহার করে, যা configuration apply করে। by default একটা test বাস্তব infrastructure তৈরি করে Source 26সোর্স 26। এখানে সেটা./out/scratch.envবানিয়েছে, আর output যাচাই করেছে। output-এtearing downদেখা যায়। একটা test file চলার পর Terraform বাকি থাকা জিনিস destroy করার চেষ্টা করে Source 27সোর্স 27। - ফল ছিল
Success! 3 passed, 0 failed., আর exit status ০। - একটা test file তার নিজের state রাখে, পরীক্ষাধীন configuration-এর state থেকে আলাদা Source 27সোর্স 27। ৩ নম্বর ধাপের
out/qa.envfile তখনও ছিল, আর ৬ নম্বর ধাপ সেটা destroy করে। - ভুল test
env=prodassert করে, আর সেটা ব্যর্থ হয়েছে। Terraform ছেপেছেTest assertion failed, প্রকৃত আর প্রত্যাশিত মানেরDiff, আরerror_message। exit status ছিল ১।-filterচালানোকে নির্দিষ্ট test file-এ সীমাবদ্ধ করে Source 27সোর্স 27।
৬. destroy করুন। চালান:
cd tf
terraform destroy -no-color -auto-approve
ls out
terraform state list
echo "state list exit status: $?"টিউটোরিয়ালের run-এর output:
local_file.settings: Refreshing state... [id=ea8fed73fdf0af945662466adbb1135880656d6d]
Terraform used the selected providers to generate the following execution
plan. Resource actions are indicated with the following symbols:
- destroy
Terraform will perform the following actions:
# local_file.settings will be destroyed
- resource "local_file" "settings" {
- content = <<-EOT
env=qa
base_url=http://localhost:8080
EOT -> null
- content_base64sha256 = "O3FCs3DMCHcVvw4jqt5VgiQLrnoBpfbzXYTgwrb2xdw=" -> null
- content_base64sha512 = "dr4Aa0ooINRuEdBv6qMIMiEdeMzD70f1k+vSzr/OA9tO4kTf/iNCLA4AjpaSAg8Au6vZ0ayK3IWB9XOgobl9uA==" -> null
- content_md5 = "71a00ff38b756e3d0971971589dfeffc" -> null
- content_sha1 = "ea8fed73fdf0af945662466adbb1135880656d6d" -> null
- content_sha256 = "3b7142b370cc087715bf0e23aade5582240bae7a01a5f6f35d84e0c2b6f6c5dc" -> null
- content_sha512 = "76be006b4a2820d46e11d06feaa30832211d78ccc3ef47f593ebd2cebfce03db4ee244dffe23422c0e008e9692020f00bbabd9d1ac8adc8581f573a0a1b97db8" -> null
- directory_permission = "0777" -> null
- file_permission = "0777" -> null
- filename = "./out/qa.env" -> null
- id = "ea8fed73fdf0af945662466adbb1135880656d6d" -> null
}
Plan: 0 to add, 0 to change, 1 to destroy.
Changes to Outputs:
- settings_path = "./out/qa.env" -> null
local_file.settings: Destroying... [id=ea8fed73fdf0af945662466adbb1135880656d6d]
local_file.settings: Destruction complete after 0s
Destroy complete! Resources: 1 destroyed.
state list exit status: 0terraform destroyconfiguration যে সব object পরিচালনা করে, সেগুলো সরিয়ে দেয় Source 23সোর্স 23। plan-এ- destroyতালিকাভুক্ত, আর শেষ হয়Plan: 0 to add, 0 to change, 1 to destroy.দিয়ে। apply শেষ হয়েছেDestroy complete! Resources: 1 destroyed.দিয়ে।ls outকিছু ছাপেনি, তাই file-টা নেই।terraform state listকিছু ছাপেনি, আর এর exit status ছিল ০। state-এ কোনো resource নেই।- তারপর টিউটোরিয়ালের runner run-এর পুরো folder সরিয়ে দিয়েছে।
৭. Packer দিয়ে একটা Docker image বানান। এটা pk নামের একটা folder-এ image.pkr.hcl নামে save করুন:
packer {
required_plugins {
docker = {
version = ">= 1.1.0"
source = "github.com/hashicorp/docker"
}
}
}
source "docker" "alpine" {
image = "alpine:latest"
pull = false
commit = true
}
build {
name = "qa-base"
sources = ["source.docker.alpine"]
provisioner "shell" {
inline = [
"echo 'built by Packer' > /etc/qa-image.txt",
"apk add --no-cache curl",
]
}
post-processor "docker-tag" {
repository = "packer-practice-qa-base"
tags = ["1.0"]
}
}file-টা টিউটোরিয়ালের নিজের, আর এতে কোনো comment নেই। packer block required_plugins-এ Docker plugin তালিকাভুক্ত করে Source 37সোর্স 37। source block builder ধরে রাখে Source 33সোর্স 33। commit = true Packer-কে container-টা একটা image-এ commit করতে বলে Source 41সোর্স 41। pull = false Packer-কে বলে মেশিনে আগে থেকে থাকা image ব্যবহার করতে Source 41সোর্স 41। build block build-টার নাম দেয় qa-base আর source বেছে নেয়। একটা provisioner block একটা provisioner কীভাবে configure হবে তা সংজ্ঞায়িত করে Source 35সোর্স 35। docker-tag post-processor docker builder-এর একটা committed artifact নিয়ে সেটাকে একটা repository-তে tag করে Source 42সোর্স 42। নাম, tag আর provisioner-এর দুটো command টিউটোরিয়ালের নিজের সিদ্ধান্ত।
চালান:
cd pk
packer version
packer init .
packer fmt -check .
echo "fmt exit status: $?"
packer validate .
echo "validate exit status: $?"
packer build -color=false .
docker run --rm packer-practice-qa-base:1.0 cat /etc/qa-image.txt
docker run --rm packer-practice-qa-base:1.0 curl --version
docker rmi packer-practice-qa-base:1.0টিউটোরিয়ালের run-এর output:
Packer v1.16.2
[1;36mInstalled plugin github.com/hashicorp/docker v1.1.5 in "/work/home/.config/packer/plugins/github.com/hashicorp/docker/packer-plugin-docker_v1.1.5_x5.0_linux_amd64"[0m
fmt exit status: 0
The configuration is valid.
validate exit status: 0
==> qa-base.docker.alpine: Creating a temporary directory for sharing data...
==> qa-base.docker.alpine: Starting docker container...
==> qa-base.docker.alpine: Run command: docker run -v /work/home/.config/packer/tmp460997856:/packer-files -d -i -t --entrypoint=/bin/sh -- alpine:latest
==> qa-base.docker.alpine: Container ID: eef29ce691014a83fbc715656cc8c39c4de4496baefd9876a8b53aee648a7471
==> qa-base.docker.alpine: Provisioning with shell script: /work/tmp/packer-shell4200093466
==> qa-base.docker.alpine: (1/9) Installing brotli-libs (1.2.1-r0)
==> qa-base.docker.alpine: (2/9) Installing c-ares (1.34.9-r0)
==> qa-base.docker.alpine: (3/9) Installing libunistring (1.4.2-r0)
==> qa-base.docker.alpine: (4/9) Installing libidn2 (2.3.8-r0)
==> qa-base.docker.alpine: (5/9) Installing nghttp2-libs (1.70.0-r0)
==> qa-base.docker.alpine: (6/9) Installing libpsl (0.21.5-r3)
==> qa-base.docker.alpine: (7/9) Installing zstd-libs (1.5.7-r2)
==> qa-base.docker.alpine: (8/9) Installing libcurl (8.23.0-r0)
==> qa-base.docker.alpine: (9/9) Installing curl (8.23.0-r0)
==> qa-base.docker.alpine: Executing busybox-1.37.0-r31.trigger
==> qa-base.docker.alpine: OK: 13.1 MiB in 25 packages
==> qa-base.docker.alpine: Committing the container
==> qa-base.docker.alpine: Image ID: sha256:43b55b1018aeab608ed6ca143e9b73c28aa3b677a418ebef52f6e7f62c4ce9f4
==> qa-base.docker.alpine: Killing the container: eef29ce691014a83fbc715656cc8c39c4de4496baefd9876a8b53aee648a7471
==> qa-base.docker.alpine: Running post-processor: (type docker-tag)
==> qa-base.docker.alpine (docker-tag): Tagging image: sha256:43b55b1018aeab608ed6ca143e9b73c28aa3b677a418ebef52f6e7f62c4ce9f4
==> qa-base.docker.alpine (docker-tag): Repository: packer-practice-qa-base:1.0
Build 'qa-base.docker.alpine' finished after 2 seconds 828 milliseconds.
==> Wait completed after 2 seconds 829 milliseconds
==> Builds finished. The artifacts of successful builds are:
--> qa-base.docker.alpine: Imported Docker image: sha256:43b55b1018aeab608ed6ca143e9b73c28aa3b677a418ebef52f6e7f62c4ce9f4
--> qa-base.docker.alpine: Imported Docker image: packer-practice-qa-base:1.0 with tags packer-practice-qa-base:1.0
built by Packer
curl 8.23.0 (x86_64-alpine-linux-musl) libcurl/8.23.0 OpenSSL/3.5.9 zlib/1.3.2 brotli/1.2.1 zstd/1.5.7 c-ares/1.34.9 libidn2/2.3.8 libpsl/0.21.5 nghttp2/1.70.0
Release-Date: 2026-10-14
Protocols: dict file ftp ftps gopher gophers http https imap imaps ipfs ipns mqtt mqtts pop3 pop3s rtsp smtp smtps telnet tftp ws wss
Features: alt-svc AsynchDNS brotli HSTS HTTP2 HTTPS-proxy IDN IPv6 Largefile libz PSL SSL threadsafe UnixSockets zstd
Untagged: packer-practice-qa-base:1.0
Deleted: sha256:43b55b1018aeab608ed6ca143e9b73c28aa3b677a418ebef52f6e7f62c4ce9f4packer initgithub.com/hashicorp/dockerplugin install করেছে Source 37সোর্স 37। output-এর path run-এর খালি home folder-এ, যা page দেখায়/work/homeনামে।packer fmt -check .আরpacker validate .দুটোর exit status ছিল ০।packer fmtHCL2 file-কে canonical format ও style-এ সাজায় Source 53সোর্স 53।-checkদিলে সব input ঠিকমতো format করা থাকলেই শুধু exit status ০ Source 53সোর্স 53।packer validateছেপেছেThe configuration is valid.সফল হলে এটা শূন্য exit status দেয় Source 39সোর্স 39।packer buildalpine:latestথেকে একটা container চালু করেছে, তাতে provisioner চালিয়েছে, আর container commit করেছে Source 41সোর্স 41। এরপরdocker-tagpost-processor image-টাকে tag করেছেpacker-practice-qa-base:1.0Source 42সোর্স 42। এটা কোনো Dockerfile ব্যবহার করেনি Source 41সোর্স 41।- দুটো
docker runcommand নতুন image ব্যবহার করেছে।cat /etc/qa-image.txtছেপেছেbuilt by Packer, আরcurl --versionছেপেছে provisioner-এর install করাcurl-এর version। এটা image-এর ওপর টিউটোরিয়ালের নিজের পরীক্ষা। docker rmitag আর image সরিয়ে দিয়েছে।
৮. একটা Crossplane composition render করুন। এটা xp নামের একটা folder-এ app.yaml নামে save করুন:
apiVersion: example.crossplane.io/v1
kind: App
metadata:
namespace: default
name: my-app
spec:
image: nginxএটা একটা App, যা nginx image চায়। বাকি তিনটা file হলো xrd.yaml (৯ নম্বর ধাপ সেটা দেখায়), fn-patch-and-transform.yaml (৬ লাইন, function) আর composition-yaml.yaml (৭২ লাইন)। সেগুলো নিন "Get started with composition" page থেকে Source 50সোর্স 50। composition-এ একটা pipeline step আছে। সেটা crossplane-contrib-function-patch-and-transform function ব্যবহার করে। সেটা replicas: 2 সহ একটা Deployment আর ৮০ নম্বর port-এর জন্য ৮০৮০ নম্বর port সহ একটা Service বানায়। একটা patch App-এর spec.image Deployment-এর image-এ কপি করে। composition হলো একটা template, যা একাধিক Kubernetes resource-কে একটা composite resource হিসেবে তৈরি করে Source 45সোর্স 45।
চালান:
cd xp
crossplane version --client
crossplane composition render app.yaml composition-yaml.yaml fn-patch-and-transform.yaml
echo "render exit status: $?"টিউটোরিয়ালের run-এর output:
Client Version: v2.5.0
---
apiVersion: example.crossplane.io/v1
kind: App
metadata:
name: my-app
namespace: default
spec:
crossplane:
resourceRefs:
- apiVersion: apps/v1
kind: Deployment
name: my-app-3ebefffb6666
- apiVersion: v1
kind: Service
name: my-app-bb6a52963bfb
status:
conditions:
- lastTransitionTime: "2024-01-01T00:00:00Z"
reason: WatchCircuitClosed
status: "True"
type: Responsive
- lastTransitionTime: "2024-01-01T00:00:00Z"
reason: ReconcileSuccess
status: "True"
type: Synced
- lastTransitionTime: "2024-01-01T00:00:00Z"
message: 'Unready resources: deployment, service'
reason: Creating
status: "False"
type: Ready
---
apiVersion: apps/v1
kind: Deployment
metadata:
annotations:
crossplane.io/composition-resource-name: deployment
generateName: my-app-
labels:
crossplane.io/composite: my-app
example.crossplane.io/app: my-app
name: my-app-3ebefffb6666
namespace: default
ownerReferences:
- apiVersion: example.crossplane.io/v1
blockOwnerDeletion: true
controller: true
kind: App
name: my-app
uid: 9de988c4-8410-5318-8780-2295cef818ff
spec:
replicas: 2
selector:
matchLabels:
example.crossplane.io/app: my-app
template:
metadata:
labels:
example.crossplane.io/app: my-app
spec:
containers:
- image: nginx
name: app
ports:
- containerPort: 80
---
apiVersion: v1
kind: Service
metadata:
annotations:
crossplane.io/composition-resource-name: service
generateName: my-app-
labels:
crossplane.io/composite: my-app
example.crossplane.io/app: my-app
name: my-app-bb6a52963bfb
namespace: default
ownerReferences:
- apiVersion: example.crossplane.io/v1
blockOwnerDeletion: true
controller: true
kind: App
name: my-app
uid: 9de988c4-8410-5318-8780-2295cef818ff
spec:
ports:
- port: 8080
protocol: TCP
targetPort: 80
selector:
example.crossplane.io/app: my-app
render exit status: 0crossplane version --clientclient-এর version ছেপেছে, আর এর জন্য কোনো server লাগে না Source 52সোর্স 52।composition render-এর জন্য Docker-এর সঙ্গে কাজ করে এমন একটা container runtime লাগে Source 51সোর্স 51। by default এটা Docker দিয়ে composition function pull ও চালায় Source 52সোর্স 52।composition renderতিনটা document ছেপেছে:resourceRefsসহApp, একটা Deployment আর একটা Service। এটা দেখায় composition কোন resource তৈরি বা বদলাবে Source 52সোর্স 52। Deployment-এ আছেreplicas: 2আরimage: nginx, যাApp-এরspec.image-এর মান। Service ৮০৮০ নম্বর port-কে ৮০ নম্বর port-এ মেলায়।App-এর status বলেUnready resources: deployment, service, আর প্রতিটাlastTransitionTimeহলো2024-01-01T00:00:00Z। কিছুই তৈরি হয়নি, কারণrenderস্থানীয়ভাবে চলে। টিউটোরিয়াল যে page-গুলো পড়েছে, তার কোনোটাই বলে না সময়টা কেন স্থির। exit status ছিল ০।
৯. App-কে তার schema-র বিপরীতে যাচাই করুন। এটা xrd.yaml নামে save করুন:
apiVersion: apiextensions.crossplane.io/v2
kind: CompositeResourceDefinition
metadata:
name: apps.example.crossplane.io
spec:
scope: Namespaced
group: example.crossplane.io
names:
kind: App
plural: apps
versions:
- name: v1
served: true
referenceable: true
schema:
openAPIV3Schema:
type: object
properties:
spec:
type: object
properties:
image:
description: The app's OCI container image.
type: string
required:
- image
status:
type: object
properties:
replicas:
description: The number of available app replicas.
type: integer
address:
description: The app's IP address.
type: stringXRD custom API-র schema সংজ্ঞায়িত করে Source 44সোর্স 44। এতে spec.image একটা string, আর সেটা বাধ্যতামূলক।
চালান:
cd xp
crossplane resource validate xrd.yaml app.yaml
echo "validate exit status: $?"
sed 's/image: nginx/imagee: nginx/' app.yaml > bad-app.yaml
crossplane resource validate xrd.yaml bad-app.yaml
echo "validate exit status: $?"
crossplane composition render bad-app.yaml composition-yaml.yaml fn-patch-and-transform.yaml | grep -c "image:"
echo "render exit status: ${PIPESTATUS[0]}"টিউটোরিয়ালের run-এর output:
schemas does not exist, downloading: xpkg.crossplane.io/crossplane/crossplane:stable
[✓] example.crossplane.io/v1, Kind=App, my-app validated successfully
Total 1 resources: 0 missing schemas, 1 success cases, 0 failure cases
validate exit status: 0
[x] schema validation error example.crossplane.io/v1, Kind=App, my-app : spec.image: Required value
[x] schema validation error example.crossplane.io/v1, Kind=App, my-app : spec.imagee: Invalid value: "imagee": unknown field: "imagee"
Total 1 resources: 0 missing schemas, 0 success cases, 1 failure cases
crossplane: error: could not validate all resources
validate exit status: 1
0
render exit status: 0- প্রথম
crossplane resource validateছেপেছেschemas does not exist, downloading: xpkg.crossplane.io/crossplane/crossplane:stable, তারপরvalidated successfully। সারাংশে1 success cases, আর exit status ছিল ০। command resource-গুলোকে XRD, CRD, provider, function আর configuration-এর schema-র বিপরীতে যাচাই করে Source 52সোর্স 52। টিউটোরিয়াল যে page-গুলো পড়েছে, তার কোনোটাই বলে না কী download হয়েছে। - তারপর টিউটোরিয়াল
app.yamlকপি করেbad-app.yamlবানিয়েছে একটা typo দিয়ে:image-এর জায়গায়imagee।validateদুটো error ছেপেছে,spec.image: Required valueআরunknown field: "imagee", আর exit status ছিল ১। command অজানা field ধরে Source 52সোর্স 52। - একই file-এর
renderexit করেছে ০ দিয়ে, আরgrep -c "image:"তার output-এ ০ লাইন গুনেছে। তাইrendertypo প্রত্যাখ্যান করেনি, আর সেটা যে Deployment ছেপেছে তাতে কোনো image নেই। docsresource validate-কে beta বলে চিহ্নিত করে Source 52সোর্স 52।
How a tester uses it
- Gate a change on exit codes.
terraform fmt -checkhas the exit status 0 if the input is properly formatted, and a non-zero exit status otherwise Source 20সোর্স 20.packer fmt -checkdoes the same Source 53সোর্স 53.packer validatereturns a non-zero exit status on failure Source 39সোর্স 39.terraform plan -detailed-exitcodereturns 0 for no changes, 1 for an error, and 2 for changes Source 21সোর্স 21. HashiCorp's style guide says to runterraform fmtandterraform validatebefore you commit code Source 28সোর্স 28. - Read the plan as data.
terraform show -jsonshows a JSON representation of a plan file Source 24সোর্স 24. Each item ofresource_changeshas a list ofactionsSource 25সোর্স 25. A replacement shows as two actions, so you can scan the list fordeleteto find every case that deletes an object Source 25সোর্স 25. - Test the code with
terraform test. A run block withcommand = plancreates no infrastructure Source 26সোর্স 26. A run block that applies creates real infrastructure, which can cost money Source 27সোর্স 27. A test file keeps a state that is separate from the state of the configuration Source 27সোর্স 27. Since Terraform v1.7.0, a test can mock the data that providers return Source 26সোর্স 26. The-junit-xmloption saves a report in JUnit XML format Source 27সোর্স 27. - Test the image, and not only the template.
packer validatechecks the syntax and the configuration of a template Source 39সোর্স 39. The result of a build is an artifact Source 31সোর্স 31. In step 7 of Try it, the tutorial ran the built image and read a file and a version from it. - Check custom resources before a cluster sees them.
crossplane resource validatechecks resources against schemas, and it detects unknown fields Source 52সোর্স 52.crossplane composition rendershows what resources a composition would create or change, by running the composition locally Source 52সোর্স 52. In step 9 of Try it,renderaccepted a typo thatvalidaterefused. - Keep secrets out of reports. State and plan files can hold sensitive values, such as initial database passwords or API tokens Source 14সোর্স 14.
terraform show -jsonshows sensitive values of the state in plain text Source 24সোর্স 24. So a plan, a state file, or its JSON can contain a secret. - Use short-lived resources, and clean up. Terraform tests run against test-specific, short-lived resources Source 26সোর্স 26.
terraform destroydeprovisions all objects that a configuration manages Source 23সোর্স 23. Aprevent_destroyrule also prevents theterraform destroycommand from operating once the objects are created Source 16সোর্স 16. - Verify what you download. A binary can contain malicious code, and HashiCorp says to verify that it created and signed the binary before you run it Source 54সোর্স 54.
সহজ English
- Gate a change on exit codes.
terraform fmt -checkhas the exit status 0 if the input is properly formatted, and a non-zero exit status otherwise Source 20সোর্স 20.packer fmt -checkdoes the same Source 53সোর্স 53.packer validatereturns a non-zero exit status on failure Source 39সোর্স 39.terraform plan -detailed-exitcodereturns 0 for no changes, 1 for an error, and 2 for changes Source 21সোর্স 21. HashiCorp's style guide says to runterraform fmtandterraform validatebefore you commit code Source 28সোর্স 28. - Read the plan as data.
terraform show -jsonshows a JSON representation of a plan file Source 24সোর্স 24. Each item ofresource_changeshas a list ofactionsSource 25সোর্স 25. A replacement shows as two actions, so you can scan the list fordeleteto find every case that deletes an object Source 25সোর্স 25. - Test the code with
terraform test. A run block withcommand = plancreates no infrastructure Source 26সোর্স 26. A run block that applies creates real infrastructure, which can cost money Source 27সোর্স 27. A test file keeps a state that is separate from the state of the configuration Source 27সোর্স 27. Since Terraform v1.7.0, a test can mock the data that providers return Source 26সোর্স 26. The-junit-xmloption saves a report in JUnit XML format Source 27সোর্স 27. - Test the image, and not only the template.
packer validatechecks the syntax and the configuration of a template Source 39সোর্স 39. The result of a build is an artifact Source 31সোর্স 31. In step 7 of Try it, the tutorial ran the built image and read a file and a version from it. - Check custom resources before a cluster sees them.
crossplane resource validatechecks resources against schemas, and it detects unknown fields Source 52সোর্স 52.crossplane composition rendershows what resources a composition would create or change, by running the composition locally Source 52সোর্স 52. In step 9 of Try it,renderaccepted a typo thatvalidaterefused. - Keep secrets out of reports. State and plan files can hold sensitive values, such as initial database passwords or API tokens Source 14সোর্স 14.
terraform show -jsonshows sensitive values of the state in plain text Source 24সোর্স 24. So a plan, a state file, or its JSON can contain a secret. - Use short-lived resources, and clean up. Terraform tests run against test-specific, short-lived resources Source 26সোর্স 26.
terraform destroydeprovisions all objects that a configuration manages Source 23সোর্স 23. Aprevent_destroyrule also prevents theterraform destroycommand from operating once the objects are created Source 16সোর্স 16. - Verify what you download. A binary can contain malicious code, and HashiCorp says to verify that it created and signed the binary before you run it Source 54সোর্স 54.
বাংলা ব্যাখ্যা
- exit code-এর ওপর একটা পরিবর্তন আটকান। input ঠিকমতো format করা থাকলে
terraform fmt -check-এর exit status ০, নইলে শূন্য নয় Source 20সোর্স 20।packer fmt -checkএকই কাজ করে Source 53সোর্স 53। ব্যর্থ হলেpacker validateশূন্য নয় এমন exit status দেয় Source 39সোর্স 39।terraform plan -detailed-exitcodeকোনো পরিবর্তন না থাকলে ০, error হলে ১, আর পরিবর্তন থাকলে ২ দেয় Source 21সোর্স 21। HashiCorp-এর style guide বলে, code commit করার আগেterraform fmtআরterraform validateচালাতে Source 28সোর্স 28। - plan-কে data হিসেবে পড়ুন।
terraform show -jsonএকটা plan file-এর JSON রূপ দেখায় Source 24সোর্স 24।resource_changes-এর প্রতিটা item-এactions-এর একটা তালিকা থাকে Source 25সোর্স 25। একটা replacement দুটো action হিসেবে দেখা যায়, তাই কোন কোন ক্ষেত্রে একটা object মুছে যায়, তা খুঁজতে আপনি তালিকায়deleteখুঁজতে পারেন Source 25সোর্স 25। terraform testদিয়ে code test করুন।command = planসহ একটা run block কোনো infrastructure তৈরি করে না Source 26সোর্স 26। যে run block apply করে, সেটা বাস্তব infrastructure তৈরি করে, যাতে টাকা খরচ হতে পারে Source 27সোর্স 27। একটা test file এমন একটা state রাখে, যা configuration-এর state থেকে আলাদা Source 27সোর্স 27। Terraform v1.7.0 থেকে একটা test provider-এর ফেরত দেওয়া data mock করতে পারে Source 26সোর্স 26।-junit-xmloption JUnit XML format-এ একটা report save করে Source 27সোর্স 27।- শুধু template নয়, image-ও test করুন।
packer validateএকটা template-এর syntax আর configuration যাচাই করে Source 39সোর্স 39। একটা build-এর ফল হলো একটা artifact Source 31সোর্স 31। Try it-এর ৭ নম্বর ধাপে টিউটোরিয়াল বানানো image চালিয়েছে, আর তার ভেতর থেকে একটা file আর একটা version পড়েছে। - cluster দেখার আগে custom resource যাচাই করুন।
crossplane resource validateresource-গুলোকে schema-র বিপরীতে যাচাই করে, আর অজানা field ধরে Source 52সোর্স 52।crossplane composition rendercomposition স্থানীয়ভাবে চালিয়ে দেখায় এটা কোন resource তৈরি বা বদলাবে Source 52সোর্স 52। Try it-এর ৯ নম্বর ধাপেrenderএমন একটা typo মেনে নিয়েছে, যাvalidateপ্রত্যাখ্যান করেছে। - report-এ secret রাখবেন না। state আর plan file-এ সংবেদনশীল মান থাকতে পারে, যেমন database-এর প্রাথমিক password বা API token Source 14সোর্স 14।
terraform show -jsonstate-এর সংবেদনশীল মান সাধারণ text-এ দেখায় Source 24সোর্স 24। তাই একটা plan, একটা state file বা তার JSON-এ secret থাকতে পারে। - অল্পস্থায়ী resource ব্যবহার করুন, আর পরিষ্কার করুন। Terraform test চলে test-এর নিজস্ব, অল্পস্থায়ী resource-এর বিরুদ্ধে Source 26সোর্স 26।
terraform destroyএকটা configuration যে সব object পরিচালনা করে, সেগুলো সরিয়ে দেয় Source 23সোর্স 23।prevent_destroyrule object তৈরি হওয়ার পরterraform destroycommand-কেও কাজ করতে দেয় না Source 16সোর্স 16। - যা download করেন তা যাচাই করুন। একটা binary-তে ক্ষতিকর code থাকতে পারে, আর HashiCorp বলে, চালানোর আগে যাচাই করতে যে সে-ই binary-টা তৈরি ও sign করেছে Source 54সোর্স 54।
Common mistakes
- Keeping the state in version control. HashiCorp says to avoid storing the state in a version control system or other storage that does not support state locking and secure access control Source 11সোর্স 11.
- Editing the state file by hand. The state is a JSON text file, and you should not edit it directly Source 11সোর্স 11.
- Using a backend that cannot lock. If the backend supports it, Terraform locks the state for all operations that could write state Source 13সোর্স 13. If state locking fails, Terraform does not continue Source 13সোর্স 13.
- Leaving the lock file out of version control. You should include
.terraform.lock.hclin your version control repository, so that a code review can discuss changes to your external dependencies Source 6সোর্স 6. - Leaving provider versions open in production. HashiCorp recommends constraining the acceptable provider versions in production Source 4সোর্স 4.
- Applying a plan that nobody re-checked. You should always re-check the final non-speculative plan before applying it, to make sure that it still matches your intent Source 21সোর্স 21.
- Using
-auto-approveon shared infrastructure. HashiCorp recommends making sure that no one can change your infrastructure outside of your Terraform workflow, because this minimizes the risk of unpredictable changes and configuration drift Source 22সোর্স 22. - Trusting
prevent_destroytoo much. The rule does not stop Terraform from destroying a resource when you remove its configuration Source 16সোর্স 16. HashiCorp says to use it sparingly Source 16সোর্স 16. - Expecting
terraform validateto look at remote services. It does not validate remote services, such as remote state or provider APIs Source 19সোর্স 19. It needs an initialized working directory Source 19সোর্স 19. - Writing a secret into
local_file. If the file content is sensitive, the provider says to use thelocal_sensitive_fileresource instead Source 29সোর্স 29. - Being surprised by the noise of
local_filein CI. Terraform detects the resource as deleted each time a configuration is applied on a new machine where the file is not present, and it generates a diff to re-create it Source 29সোর্স 29. - Running
terraform testwithout knowing what it creates. The command can create real infrastructure that can cost money Source 27সোর্স 27. - Expecting Packer to replace configuration management. Packer does not replace configuration management like Chef or Puppet Source 30সোর্স 30.
- Forgetting that Packer pulls the base image. The
pulloption defaults to true Source 41সোর্স 41. The tutorial's template sets it to false, so it uses the image that is already on the machine. - Treating
crossplane composition renderas a check of the schema. In step 9 of Try it,renderexited with 0 for a typo in a field name, andresource validaterefused it. The docs say thatvalidatedetects unknown fields Source 52সোর্স 52. - Running a binary that nobody verified. HashiCorp says that you can avoid running an executable with malicious code by verifying that HashiCorp created and signed the binary Source 54সোর্স 54.
সহজ English
- Keeping the state in version control. HashiCorp says to avoid storing the state in a version control system or other storage that does not support state locking and secure access control Source 11সোর্স 11.
- Editing the state file by hand. The state is a JSON text file, and you should not edit it directly Source 11সোর্স 11.
- Using a backend that cannot lock. If the backend supports it, Terraform locks the state for all operations that could write state Source 13সোর্স 13. If state locking fails, Terraform does not continue Source 13সোর্স 13.
- Leaving the lock file out of version control. You should include
.terraform.lock.hclin your version control repository, so that a code review can discuss changes to your external dependencies Source 6সোর্স 6. - Leaving provider versions open in production. HashiCorp recommends constraining the acceptable provider versions in production Source 4সোর্স 4.
- Applying a plan that nobody re-checked. You should always re-check the final non-speculative plan before applying it, to make sure that it still matches your intent Source 21সোর্স 21.
- Using
-auto-approveon shared infrastructure. HashiCorp recommends making sure that no one can change your infrastructure outside of your Terraform workflow, because this minimizes the risk of unpredictable changes and configuration drift Source 22সোর্স 22. - Trusting
prevent_destroytoo much. The rule does not stop Terraform from destroying a resource when you remove its configuration Source 16সোর্স 16. HashiCorp says to use it sparingly Source 16সোর্স 16. - Expecting
terraform validateto look at remote services. It does not validate remote services, such as remote state or provider APIs Source 19সোর্স 19. It needs an initialized working directory Source 19সোর্স 19. - Writing a secret into
local_file. If the file content is sensitive, the provider says to use thelocal_sensitive_fileresource instead Source 29সোর্স 29. - Being surprised by the noise of
local_filein CI. Terraform detects the resource as deleted each time a configuration is applied on a new machine where the file is not present, and it generates a diff to re-create it Source 29সোর্স 29. - Running
terraform testwithout knowing what it creates. The command can create real infrastructure that can cost money Source 27সোর্স 27. - Expecting Packer to replace configuration management. Packer does not replace configuration management like Chef or Puppet Source 30সোর্স 30.
- Forgetting that Packer pulls the base image. The
pulloption defaults to true Source 41সোর্স 41. The tutorial's template sets it to false, so it uses the image that is already on the machine. - Treating
crossplane composition renderas a check of the schema. In step 9 of Try it,renderexited with 0 for a typo in a field name, andresource validaterefused it. The docs say thatvalidatedetects unknown fields Source 52সোর্স 52. - Running a binary that nobody verified. HashiCorp says that you can avoid running an executable with malicious code by verifying that HashiCorp created and signed the binary Source 54সোর্স 54.
বাংলা ব্যাখ্যা
- state-কে version control-এ রাখা। HashiCorp বলে, state এমন version control system বা অন্য storage-এ রাখা এড়াতে, যা state locking আর নিরাপদ access control সমর্থন করে না Source 11সোর্স 11।
- state file হাতে edit করা। state একটা JSON text file, আর সেটা সরাসরি edit করা উচিত নয় Source 11সোর্স 11।
- lock করতে পারে না এমন backend ব্যবহার করা। backend সমর্থন করলে Terraform state লিখতে পারে এমন সব operation-এর জন্য state lock করে Source 13সোর্স 13। state locking ব্যর্থ হলে Terraform এগোয় না Source 13সোর্স 13।
- lock file version control-এর বাইরে রাখা। আপনার উচিত
.terraform.lock.hclআপনার version control repository-তে রাখা, যাতে একটা code review আপনার বাইরের dependency-র পরিবর্তন নিয়ে আলোচনা করতে পারে Source 6সোর্স 6। - production-এ provider version খোলা রাখা। HashiCorp production-এ গ্রহণযোগ্য provider version সীমাবদ্ধ করার পরামর্শ দেয় Source 4সোর্স 4।
- এমন plan apply করা, যা কেউ আবার দেখেনি। apply করার আগে চূড়ান্ত non-speculative plan সবসময় আবার দেখে নেওয়া উচিত, যাতে নিশ্চিত হওয়া যায় যে সেটা এখনও আপনার উদ্দেশ্যের সঙ্গে মেলে Source 21সোর্স 21।
- shared infrastructure-এ
-auto-approveব্যবহার করা। HashiCorp পরামর্শ দেয় নিশ্চিত করতে যে আপনার Terraform workflow-এর বাইরে কেউ আপনার infrastructure বদলাতে পারে না, কারণ এতে অপ্রত্যাশিত পরিবর্তন আর configuration drift-এর ঝুঁকি কমে Source 22সোর্স 22। prevent_destroy-কে বেশি বিশ্বাস করা। আপনি কোনো resource-এর configuration সরিয়ে দিলে এই rule Terraform-কে সেটা destroy করা থেকে আটকায় না Source 16সোর্স 16। HashiCorp বলে এটা কম ব্যবহার করতে Source 16সোর্স 16।terraform validateremote service দেখবে বলে আশা করা। এটা remote state বা provider API-র মতো remote service যাচাই করে না Source 19সোর্স 19। এর জন্য একটা প্রস্তুত করা (initialized) working directory লাগে Source 19সোর্স 19।local_file-এ secret লেখা। file-এর content সংবেদনশীল হলে provider বলে এর বদলেlocal_sensitive_fileresource ব্যবহার করতে Source 29সোর্স 29।- CI-তে
local_file-এর noise দেখে অবাক হওয়া। যে নতুন মেশিনে file নেই, সেখানে configuration apply করলেই Terraform resource-টাকে মুছে যাওয়া হিসেবে ধরে, আর সেটা আবার বানানোর একটা diff তৈরি করে Source 29সোর্স 29। terraform testকী তৈরি করে তা না জেনে চালানো। command বাস্তব infrastructure তৈরি করতে পারে, যাতে টাকা খরচ হতে পারে Source 27সোর্স 27।- Packer configuration management-এর জায়গা নেবে বলে আশা করা। Packer Chef বা Puppet-এর মতো configuration management-এর জায়গা নেয় না Source 30সোর্স 30।
- ভুলে যাওয়া যে Packer base image pull করে।
pulloption-এর default true Source 41সোর্স 41। টিউটোরিয়ালের template সেটা false করেছে, তাই সে মেশিনে আগে থেকে থাকা image ব্যবহার করে। crossplane composition render-কে schema-র যাচাই ভাবা। Try it-এর ৯ নম্বর ধাপেrenderএকটা field-এর নামের typo-র জন্য ০ দিয়ে exit করেছে, আরresource validateসেটা প্রত্যাখ্যান করেছে। docs বলেvalidateঅজানা field ধরে Source 52সোর্স 52।- যাচাই না করা binary চালানো। HashiCorp বলে, HashiCorp-ই binary তৈরি ও sign করেছে তা যাচাই করে আপনি ক্ষতিকর code-সহ executable চালানো এড়াতে পারেন Source 54সোর্স 54।
What a tester can check
Tutorial advice
This list is the tutorial's own advice for a tester who works with Terraform, Packer, and Crossplane.
- Run
terraform fmt -check,terraform validate, andterraform teston every pull request, and fail the build on a non-zero exit status. - After an apply, run
terraform plan -detailed-exitcodeagain, and expect the exit status 0. - Save the plan with
-out, read it, and apply that file, so that the apply does what you read. - Read the plan as JSON, and write a test that fails when an action that you did not expect, such as
delete, appears. - Write one
expect_failurestest for everyvalidationrule, so that bad input is refused. - Test in a throwaway folder or account, and put the clean-up in the same script that creates the resources.
- Keep state files, plan files, and their JSON out of Git, bug reports, and chat messages.
- Commit
.terraform.lock.hcl, and read its diff in a review. - Run the image of a Packer build, and check what you expect in it, and what you expect not to be in it.
- Validate a custom resource against its schema before you apply it, and write one test with a typo in a field name.
- Use made-up values for every name and setting, and start each name with a prefix that says that it is a test.
- Keep the date, the tool versions, and the exact commands with every test result.
সহজ English
Tutorial advice
This list is the tutorial's own advice for a tester who works with Terraform, Packer, and Crossplane.
- Run
terraform fmt -check,terraform validate, andterraform teston every pull request, and fail the build on a non-zero exit status. - After an apply, run
terraform plan -detailed-exitcodeagain, and expect the exit status 0. - Save the plan with
-out, read it, and apply that file, so that the apply does what you read. - Read the plan as JSON, and write a test that fails when an action that you did not expect, such as
delete, appears. - Write one
expect_failurestest for everyvalidationrule, so that bad input is refused. - Test in a throwaway folder or account, and put the clean-up in the same script that creates the resources.
- Keep state files, plan files, and their JSON out of Git, bug reports, and chat messages.
- Commit
.terraform.lock.hcl, and read its diff in a review. - Run the image of a Packer build, and check what you expect in it, and what you expect not to be in it.
- Validate a custom resource against its schema before you apply it, and write one test with a typo in a field name.
- Use made-up values for every name and setting, and start each name with a prefix that says that it is a test.
- Keep the date, the tool versions, and the exact commands with every test result.
বাংলা ব্যাখ্যা
Tutorial advice
এই তালিকা টিউটোরিয়ালের নিজের পরামর্শ, এমন একজন tester-এর জন্য যিনি Terraform, Packer আর Crossplane নিয়ে কাজ করেন।
- প্রতিটা pull request-এ
terraform fmt -check,terraform validateআরterraform testচালান, আর শূন্য নয় এমন exit status হলে build ব্যর্থ করুন। - apply-এর পর আবার
terraform plan -detailed-exitcodeচালান, আর exit status ০ আশা করুন। -outদিয়ে plan save করুন, সেটা পড়ুন, আর সেই file-টাই apply করুন, যাতে apply তা-ই করে যা আপনি পড়েছেন।- plan JSON হিসেবে পড়ুন, আর এমন একটা test লিখুন, যা আপনার ভাবনার বাইরের কোনো action, যেমন
delete, দেখা দিলে ব্যর্থ হয়। - প্রতিটা
validationrule-এর জন্য একটা করেexpect_failurestest লিখুন, যাতে খারাপ input প্রত্যাখ্যাত হয়। - একটা ফেলে দেওয়ার মতো folder বা account-এ test করুন, আর পরিষ্কারের কাজ রাখুন সেই একই script-এ, যা resource বানায়।
- state file, plan file আর তাদের JSON Git, bug report আর chat message-এর বাইরে রাখুন।
.terraform.lock.hclcommit করুন, আর review-তে তার diff পড়ুন।- একটা Packer build-এর image চালান, আর যা তাতে থাকার কথা আর যা থাকার কথা নয়, দুটোই যাচাই করুন।
- একটা custom resource apply করার আগে তার schema-র বিপরীতে যাচাই করুন, আর একটা field-এর নামে typo দিয়ে একটা test লিখুন।
- প্রতিটা নাম আর setting-এর জন্য বানানো মান ব্যবহার করুন, আর প্রতিটা নাম শুরু করুন এমন একটা prefix দিয়ে, যা বলে এটা test।
- প্রতিটা test-এর ফলের সঙ্গে তারিখ, tool-এর version আর হুবহু command রাখুন।
Key words
| Term | Meaning |
|---|---|
| Infrastructure as code | Terraform is an infrastructure as code tool that lets you build, change, and version cloud and on-prem resources safely and efficiently |
| Provider | Terraform relies on plugins called providers to interact with cloud providers, SaaS providers, and other APIs |
| Resource | The resource block defines a piece of infrastructure |
| Variable | The variable block is similar to a function argument in other programming languages |
| Output | The output block lets you expose information about your infrastructure |
| Plan | The terraform plan command creates an execution plan, which lets you preview the changes that Terraform plans to make |
| Speculative plan | Without the -out option, it creates a speculative plan |
| Apply | The terraform apply command executes the operations of a plan |
| State | Terraform must store state about your workspace's managed infrastructure and configuration |
| Remote state | With remote state, Terraform writes the state data to a remote data store that a whole team can share |
| Dependency lock file | The lock file is always named .terraform.lock.hcl |
| Module | A module is a collection of resources that Terraform manages together |
| Terraform test | Terraform tests let authors validate that module configuration updates do not introduce breaking changes |
| Machine image | A machine image is a single static unit that contains a pre-configured operating system and installed software |
| Template | A template defines one or more builds |
| Builder | A builder creates a machine image for a single platform |
| Provisioner | Provisioners install and configure software in a running machine before it becomes a static artifact |
| Post-processor | A post-processor takes the result of a builder or another post-processor and creates a new artifact |
| Artifact | An artifact is the result of a single build |
| Control plane | A control plane is software that controls other software |
| Drift | If the software drifts from the desired state, the control plane corrects the drift |
| Composite resource definition (XRD) | A composite resource definition (XRD) defines the schema for a custom API |
| Composition | A composition is a template for creating several Kubernetes resources as a single composite resource |
| Composite resource (XR) | A composite resource represents a set of Kubernetes resources as a single Kubernetes object |
| Managed resource | A managed resource represents an external service in a provider |
| Function | Functions extend Crossplane with new ways to configure composition |
| Render | The composition render command shows what resources a composition would create or change |