You don't have access to this class

Keep learning! Join and start boosting your career

Aprovecha el precio especial y haz tu profesi贸n a prueba de IA

Antes: $249

Currency
$209
Suscr铆bete

Termina en:

2 D铆as
17 Hrs
38 Min
38 Seg

Creando roles y policies

14/30
Resources

How to initialize Terraform in a new project?

When you work with Terraform to manage infrastructure as code, the first essential step is to initialize the environment where Terraform will run. Let's follow these steps to understand how to do it correctly.

  1. Navigating to the infrastructure folder: First, make sure you are in the correct directory. For example, infra, where your Terraform configuration will be hosted.
  2. Initialize Terraform: Run the terraform init command, which will prepare the environment by downloading the necessary modules and setting the initial state to terraform.tfstate.
cd infraterraform init -backend=false
  1. Formatting correction: There may be formatting problems in your configuration files. Use the terraform fmt command to correct it:
terraform fmt -recursive

What is the terraform plan and how is it used?

The terraform plan command is essential to understand what changes are being proposed before applying any changes.

  • View changes: When run, Terraform will show you a list of the actions it plans to perform, such as resource creations, updates and deletions.
terraform plan
  • Module linking: If no changes are shown, make sure your modules are properly linked. Generally, a main.tf file is needed to reference and configure these modules.

How to apply changes with Terraform?

Once you are sure of your modifications, the next step is to apply them.

  1. Pre-validation: Before executing irreversible changes, confirm that the plan is correct with terraform plan.
  2. Execute changes: Use the terraform apply command, and when asked for confirmation, answer with yes to proceed.
terraform apply

How to verify the resources created in AWS?

A crucial step after applying the changes is to verify that they have been applied correctly in AWS:

  1. Navigate to the AWS console: Go to the IAM interface.
  2. Review policies and roles created: Look for resources such as roles and policies that are mentioned in your plan. For example, a repo collector platzi role should be present.
  • When you open a policy, you can see its definition in JSON format, which makes it easy to verify its completeness and consistency with the file generated by policy generate.

With these steps, you can not only manage infrastructure as code with Terraform, but also automate the creation of roles and policies, facilitating the use of services such as AWS Lambda. We invite you to continue learning and exploring new configurations in future classes!

Contributions 1

Questions 0

Sort by:

Want to see more contributions, questions and answers from the community?

Tutoriales de Terraform: <https://developer.hashicorp.com/terraform/tutorials>