Magical Butter at Niagara Falls 420 Expo

The Magical Butter machine is the world’s first counter-top Botanical Extractor™, designed for creating fantastic recipes, infusing the essence of healthy herbs into butter, oil, grain alcohol…

Smartphone

独家优惠奖金 100% 高达 1 BTC + 180 免费旋转




Terraform Part I

Terraform is a tool for building, changing, and versioning infrastructure safely and efficiently. Terraform can manage existing and popular service providers as well as custom in-house solutions. Managing existing resources on aws will require the importation of the resources to Terraform and be managed by Terraform, which will allow other resources to be built around it.

Infrastructure is described using a high-level configuration syntax. This allows a blueprint of your datacenter to be versioned and treated as you would any other code. Additionally, infrastructure can be shared and re-used.

Terraform has a “planning” step where it generates an execution plan. The execution plan shows what Terraform will do when you call apply. This lets you avoid any surprises when Terraform manipulates infrastructure.

The above shows what will be added before the changes will be made on the infrastructure.

Terraform builds a graph of all your resources, and parallelizes the creation and modification of any non-dependent resources. Because of this, Terraform builds infrastructure as efficiently as possible, and operators get insight into dependencies in their infrastructure.

The graph can also be used to troubleshoot issues,

Complex change sets can be applied to your infrastructure with minimal human interaction. With the previously mentioned execution plan and resource graph, you know exactly what Terraform will change and in what order, avoiding many possible human errors.

Steps:

Login to your aws account, go to your IAM console, go to “Users”, click “Add user” to generate an access key and a secret key. Under **access type**, check `Programmatic access`, Click the “Create user” button on the last step and you will be able to see the security credentials for that user, which consist of Access Key ID and a Secret Access Key. You should save these keys immediately, as the Secret Access Key will never be shown again.
In order for terraform to be able to make changes to our aws infrastructure, we need to set AWS credential for the user. On your terminal:

After downloading Terraform, unzip the package. Terraform runs as a single binary named terraform. Any other files in the package can be safely removed and Terraform will still function.

Download terraform for Linux

set path

Using brew install is the quickest way brew install terraform. If you dont have homebre, install it.

install ruby

Note: Terraform is packaged as a zip archive, so after downloading Terraform, unzip the package. Terraform runs as a single binary named terraform. Any other files in the package can be safely removed and Terraform will still function

Copy files from the zip to “c:\terraform” for example. That’s our terraform PATH.

The final step is to make sure that the terraform binary is available on the PATH.

Set the path in your system utility in control panel.

After installing Terraform, verify the installation worked by opening a new terminal session and checking that terraform is available. By executing terraform you should see help output similar to this:

If you get an error that terraform could not be found, your PATH environment variable was not set up properly. Please go back and ensure that your PATH variable contains the directory where Terraform was installed.

This instructs Terraform the cloud prover you would be using, in this case, it is awsand that you wish to deploy your infrastructure in the us-east-1 region. If you’ve already configured your credentials as environment variables, you only need to specify the region. However, if you didn’t configure your creds as an environment variable, the below works. i.e it specifies the location of your aws credentials/config

Once updated run the below to initialize the project:

To build the resource, its advisable to view the resource(s) that would be created before it gets created…use the below code to see what will happen to your infrastructure before applying/deploying it. This is a way to run a sanity test on your changes before deploying/applying it.

Note: resources with a plus sign “+” will be created, resources with a minus sign “-” will be deleted, and resources with a tilde sign “~” will be modified.

To create an instance, run terraform apply. To bypass the “yes” prompt use terraform apply -auto-approve.

Note: It took 36s for Terraform to provision an ec2 instance in aws, manually it could take at least 2min. Another file terraform.tfstate was generated which contains the state and all the info attributed to the ec2 instance. Currently, its save locally, in the coming chapter, we will be storing the file automatically into a secured s3 bucket for security reasons

Notice, the ec2-instance id output i-0bf984bef5ff354d6 matches the instance id on the aws console. Now let's modify our ec2-instance by giving a name for our ec2 instance, we know the Name is configured from the tag, therefore, we will add a tag section to our terraform code for the ec2 resource.

Update existing ec2-instance

Since terraform keeps track of all the resources it created, therefore, it knows the ec2 instance already exist. The id for the deployed ec2 instance is i-0bf984bef5ff354d6, then it shows the difference between the current and new intended change, denoted with the sign ~. Apply the change and verify on the console.

It took 3s for terraform to apply this change to the ec2 instance.

Add a comment

Related posts:

Empowering Employees in the Fight for Cyber Security.

More than half of firms in the UK have reportedly been attacked by hackers, according to a study conducted by insurer Hiscox. The survey, which spanned across 7 countries and 5,400 companies, found…

What is UNO CBD Gummies?

UNO CBD Gummies can help you lose weight in just a few weeks. It is known for its outstanding results and its ability to provide a rapid and permanent solution to your weight loss problem. It is a…