Skip to content

Commit

Permalink
Introducing a dedicated bootstrap lab
Browse files Browse the repository at this point in the history
  • Loading branch information
tillkahlbrock committed Aug 23, 2022
1 parent c726c12 commit 3ca3145
Show file tree
Hide file tree
Showing 2 changed files with 97 additions and 17 deletions.
93 changes: 93 additions & 0 deletions 0-bootstrap/README.md
Original file line number Diff line number Diff line change
@@ -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.
21 changes: 4 additions & 17 deletions 1-getting-started/README.md
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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.

Expand Down

0 comments on commit 3ca3145

Please sign in to comment.