From 3ca3145a12aa6f8b7681210a541a6d7017339a91 Mon Sep 17 00:00:00 2001 From: Till Kahlbrock Date: Tue, 23 Aug 2022 13:49:45 +0200 Subject: [PATCH 1/2] Introducing a dedicated bootstrap lab --- 0-bootstrap/README.md | 93 +++++++++++++++++++++++++++++++++++++ 1-getting-started/README.md | 21 ++------- 2 files changed, 97 insertions(+), 17 deletions(-) create mode 100644 0-bootstrap/README.md diff --git a/0-bootstrap/README.md b/0-bootstrap/README.md new file mode 100644 index 0000000..5168c87 --- /dev/null +++ b/0-bootstrap/README.md @@ -0,0 +1,93 @@ +# Getting started + +Let’s get started by bootstrapping Terraform and out AWS environment. + +## AWS credentials setup + +Before you start you will need + +- an AWS account that you can safely use during this workshop +- administrator credentials to this account +- install the aws cli according to the [documentation](https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html) + +If you already have a mechanism in place for allowing access to AWS accounts (like SAML or AWS SSO), please use this. +Otherwise, you can create an IAM users as described [here](https://docs.aws.amazon.com/cli/latest/userguide/getting-started-prereqs.html#getting-started-prereqs-iam). + +Lastly you have to publish your credentials to your shell environment. If you created an IAM user earlier, +you can follow [this guide](https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-files.html#cli-configure-files-methods) +to configure your credentials with the `aws configure` command. + +### Test your credentials setup + +To make sure that your environment is set up correctly, you can use the following command: + +```shell +$ aws sts get-caller-identity +{ + "UserId": "AIDASAMPLEUSERID", + "Account": "123456789012", + "Arn": "arn:aws:iam::123456789012:user/DevAdmin" +} +``` + +You should make sure, that the field `Account` has the same account id that you wanted to use. + +## Bootstrap Terraform + +### Install Terraform + +During this workshop we will be using the terraform cli. To install we recommend that you use the +[terraform version manager tfenv](https://github.com/tfutils/tfenv). + +You can now install terraform using tfenv + +```shell +$ tfenv install 1.1.9 +``` + +Test if you are using the correct version afterwards + +```shell +$ terraform --version +Terraform v1.1.9 +... +``` + +### Bootstrap the Terraform project + +1. Create a new folder and cd into it. +1. Create a new file `main.tf` +2. Add these lines to the `main.tf`: + ```tf + terraform { + required_version = "~> 1.1.7" + } + + provider "aws" { + region = "eu-central-1" + } + ``` +3. Run `terraform init` + +You should see some output similar to this: +```shell +$ terraform init + +Initializing the backend... + +Initializing provider plugins... +- Finding latest version of hashicorp/aws... +- Installing hashicorp/aws v4.27.0... +- Installed hashicorp/aws v4.27.0 (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! +... +``` +## Next + +Our AWS environment and the terraform project is now properly set up. In the [next lab](../1-getting-started/), we can start deploying a first resource to our AWS account. diff --git a/1-getting-started/README.md b/1-getting-started/README.md index cef08e9..9346803 100644 --- a/1-getting-started/README.md +++ b/1-getting-started/README.md @@ -1,23 +1,10 @@ # Getting started -Let’s get started by bootstrapping Terraform and deploying some resources to AWS. Instead of just deploying some random resources, we want to create an S3 bucket and enable static website hosting. Ultimately, we serve a static HTML file. +Let’s get started by deploying some resources to AWS. Instead of just deploying some random resources, we want to create an S3 bucket and enable static website hosting. Ultimately, we serve a static HTML file. -## Bootstrap Terraform +## Creating a first bucket -1. Create a new folder and cd into it. -1. Create a new file `main.tf` -2. Add these lines to the `main.tf`: - ```tf - terraform { - required_version = "~> 1.1.7" - } - - provider "aws" { - region = "eu-central-1" - } - ``` -3. Run `terraform init` -4. Replace the `main.tf` file by adding the first resource: +1. Replace the `main.tf` file by adding the first resource: ```tf terraform { required_version = "~> 1.1.7" @@ -34,7 +21,7 @@ Let’s get started by bootstrapping Terraform and deploying some resources to A force_destroy = true } ``` -5. Run `terraform apply` and confirm the deployment with `yes`. +2. Run `terraform apply` and confirm the deployment with `yes`. We just created an empty S3 bucket. Go to the [S3 console](https://s3.console.aws.amazon.com/s3/buckets) and verify the existence. From 10f1223461166de82b23859e7a962bb22f74a7c3 Mon Sep 17 00:00:00 2001 From: Till Kahlbrock Date: Tue, 30 Aug 2022 11:19:47 +0200 Subject: [PATCH 2/2] Clarify bootstrap steps --- 0-bootstrap/README.md | 2 +- 0-bootstrap/main.tf | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) create mode 100644 0-bootstrap/main.tf diff --git a/0-bootstrap/README.md b/0-bootstrap/README.md index 5168c87..ad5afae 100644 --- a/0-bootstrap/README.md +++ b/0-bootstrap/README.md @@ -55,7 +55,7 @@ Terraform v1.1.9 ### Bootstrap the Terraform project -1. Create a new folder and cd into it. +1. Create a new folder `my-project` and cd into it. 1. Create a new file `main.tf` 2. Add these lines to the `main.tf`: ```tf diff --git a/0-bootstrap/main.tf b/0-bootstrap/main.tf new file mode 100644 index 0000000..2560387 --- /dev/null +++ b/0-bootstrap/main.tf @@ -0,0 +1,7 @@ +terraform { + required_version = "~> 1.1.7" +} + +provider "aws" { + region = "eu-central-1" +}