Sixth Flashcards Preview

P211A000N02F > Sixth > Flashcards

Flashcards in Sixth Deck (7)
Loading flashcards...
1

You need to deploy your AWS infrastructure in a multi-region environment. How you will configure your provider to do this?

A. provider "aws" {
region = "eu-west-1"
}
provider "aws" {
alias = "frankfurt"
region = "eu-central-1"
}

B. provider "aws" {
region = "eu-west-1"
}
provider "aws2" {
region = "eu-central-1"
}

C. provider "aws" {
region = "eu-west-1"
}
provider "aws" {
region = "eu-central-1"
}

D. provider "aws" {
region = "eu-west-1"
}
provider "aws" {
name = aws
region = "eu-central-1"
}

A. provider "aws" {
region = "eu-west-1"
}
provider "aws" {
alias = "frankfurt"
region = "eu-central-1"
}

To use Terraform with a non-default provider configuration, you need to use the alias meta-argument

Option B is incorrect because the provider aws2 doesn’t exist

Option C is incorrect because you are defining two default providers with the same name and you need to reference your providers differently

Option D is incorrect because the meta-argument name is not valid in the Terraform provider configuration

https://www.terraform.io/docs/language/providers/configuration.html
https://github.com/hashicorp/terraform-provider-aws
https://registry.terraform.io/providers/hashicorp/aws/latest/docs

2

Can you force Terraform to use a particular version in your code?

A. Yes. Using the meta-argument required_version in the terraform block
B. Yes. Using the meta-argument required_version in the provider block
C. Yes. Using the meta-argument version in the terraform block
D. Yes. Using the meta-argument version in the provider block

A. Yes. Using the meta-argument required_version in the terraform block

You can force to use a particular version of Terraform using the meta-argument required_version in the terraform block

Answer B is incorrect because the meta-argument must be on the terraform block configuration and not on the provider’s block

Answer C is incorrect because the meta-argument version is incorrect

Answer D is incorrect because the meta-argument version is incorrect

https://www.terraform.io/docs/language/settings/index.html

3

How you can install all the providers associated with your terraform directory?

A. terraform install providers.tf
B. terraform plan
C. Using the default installer of your Operating System to install the plugins
D. terraform init

D. terraform init

The configuration and installation of providers occur during the initialization of your Terraform directory.This step is happening when a terraform init is executed

A is incorrect as terraform install doesn’t exist on the terraform client
# terraform install
Usage: terraform [-version] [-help] [args]
The available commands for execution are listed below.
The most common, useful commands are shown first, followed by less common or more advanced commands. If you're just getting started with Terraform, stick with the common commands. For the other commands, please read the help and docs before usage.
Common commands:
- apply Builds or changes infrastructure
- console Interactive console for Terraform interpolations
- destroy Destroy Terraform-managed infrastructure
- env Workspace management
- fmt Rewrites config files to canonical format
- get Download and install modules for the configuration
- graph Create a visual graph of Terraform resources
- import Import existing infrastructure into Terraform
- init Initialize a Terraform working directory
- output Read an output from a state file
- plan Generate and show an execution plan
- providers Prints a tree of the providers used in the configuration
- push Upload this Terraform module to Atlas to run
- refresh Update local state file against real resources
- show Inspect Terraform state or plan
- taint Manually mark a resource for recreation
- untaint Manually unmark a resource as tainted
- validate Validates the Terraform files
- version Prints the Terraform version
- workspace Workspace management

B is incorrect because before planning your infrastructure, Terraform needs to have installed plugins and providers to operate with your infrastructure before a plan and apply operations.

C is incorrect as you can’t install providers and plugins using installers like apt, yum, etc

https://learn.hashicorp.com/tutorials/terraform/aws-build#initialize-the-directory

4

You have the following provider configuration:
provider "aws" {
region = "eu-west-1"
}
provider "aws" {
alias = "frankfurt"
region = "eu-central-1"
}

You have modules and resources on your IaC. You want to create the resources associated with yourmodule on eu-west-1 and the resources to eu-central-1.

What of the following code blocks is correct?

A. module "aws_vpc" {
source = "./aws_vpc"
providers = {
aws = aws
}
}
resource "aws_instance""whizlabs" {
provider = aws.frankfurt
}

B. module "aws_vpc" {
source = "./aws_vpc"
providers = {
aws = aws.east
}
}
resource "aws_instance""whizlabs" {
provider = aws.frankfurt
}

C. module "aws_vpc" {
source = "./aws_vpc"
provider = aws.frankfurt
}
}
resource "aws_instance""whizlabs" {
provider = aws.frankfurt
}

D. module "aws_vpc" {
source = "./aws_vpc"
provider = aws.eu-west-1
}
resource "aws_instance""whizlabs" {
provider = aws.frankfurt
}

A. module "aws_vpc" {
source = "./aws_vpc"
providers = {
aws = aws
}
}
resource "aws_instance""whizlabs" {
provider = aws.frankfurt
}

On Terraform we have to make use of an alias to distinguish different providers from the default provider.In the module, configuration is ok to use the default provider as we have to create those resources on eu-west-1

module "aws_vpc" {
source = "./aws_vpc"
providers = {
aws = aws
}
}

The single resource must be created on eu-central-1, so we have to specify the provider configured with the alias frankfurt
resource "aws_instance" "whizlabs" {
provider = aws.frankfurt
}

Option B is incorrect as we don’t have a provider configured with alias aws.east

Option C is incorrect because we want to create the VPC on eu-west-1 and the single resource on eu-central-1. With this configuration, both resources are being created on eu-central-1

Option D is incorrect because you have to specify or default provider, or an alias.

https://www.terraform.io/docs/language/providers/configuration.html

5

With Terraform, you can only download providers from the Terraform registry.

A. True
B. False
C. All providers must be hosted on Github.
D. A and C

B. False

With Terraform, you can specify a local mirror to download other providers or your custom Terraform providers.

A is incorrect because you can use different alternatives to download custom providers that are not part of the Terraform Registry

C is incorrect because you can have your providers hosted in different repositories than GitHub.

D is incorrect as A and C are incorrect

https://www.terraform.io/docs/cli/config/config-file.html#explicit-installation-method-configuration
https://www.terraform.io/docs/cli/config/config-file.html#explicit-installation-method-configuration

6

Which provisioner you should use to execute a script in a remote resource?

A. Use a local-exec provisioner with ssh command inside.
B. Use an ssh-provisioner and add the command to be executed
C. Use a remote-exec provisioner to execute the script required
D. All the above

C. Use a remote-exec provisioner to execute the script required

remote-exec is the provider defined to execute a script or other operations remotely after the resource is created.

resource "aws_instance" "whizlabs" {
provisioner "remote-exec" {
inline = [
"apt-get install terraform" ]
}
}

Option A is incorrect as local-exec is executed locally and not remotely.

Option B is incorrect as the ssh-provisioner doesn’t exist. You have to use the connection provisioner

Option D is incorrect as A and B are incorrect

https://www.terraform.io/docs/language/resources/provisioners/remote-exec.html
https://www.terraform.io/docs/language/resources/provisioners/connection.html

7

You need to install pymysql libraries in the local instance where you are executing Terraform to be used in your IaC. How you will install these libraries and use them in your IaC.

A. resource "null_resource" "pymysql" {
provisioner "local-exec" {
command = "pip install --target./python pymysql && zip -r pymysql.zip python"
}
}
And use the null resource attributes inside of your IaC

B. provisioner "local-exec" {
command = "pip install --target ./python pymysql && zip -r pymysql.zippython"
}
Then reference this provisioner inside of your IaC

C. You have to install the libraries manually first and the packaged them as zip and reference this zipfile on your IaC

D. A and B are correct

A. resource "null_resource" "pymysql" {
provisioner "local-exec" {
command = "pip install --target./python pymysql && zip -r pymysql.zip python"
}
}
And use the null resource attributes inside of your IaC

Using a provisioner local-exec you can execute commands locally.

In this question, is required to create pymysql libraries. Once you have the libraries, you must reference these libraries in your IaC.

The best approach is using a null resource that is executing this local provisioner to use as a reference in the IaC

Option B is incorrect because you always have to add a provisioner block inside of a resource block

Option C is incorrect because if you created manually those libraries you don’t have a resource block to identify those libraries to be used in your IaC

Option D is incorrect because B is incorrect

https://www.terraform.io/docs/language/resources/provisioners/syntax.html#provisioners-are-a-last-resort