Breaking News: Grepper is joining You.com. Read the official announcement!
Check it out

Project code in detail#

Sumit Rawal answered on May 19, 2023 Popularity 1/10 Helpfulness 1/10

Contents


More Related Answers

  • Project example#
  • Project output#

  • Project code in detail#

    0

    In the code above:

    We define a local block by using the keyword locals and then an opening {.

    We define each local on a new line by giving it a name. The first local we define is called first_part.

    We then follow it with an = and give it a value. For the first_part local, we give it the value of the string literal hello.

    For the second local second_part, we are use the value "${local.first_part}-there".

    As the whole expression is inside quotes, we need to use the ${ and } around our expression so Terraform evaluates it.

    To reference a local, we use the expression syntax local.local_identifier.

    The second_part local will be set to “hello-there”. In the bucket_name local, we are using the second_part local in the expression "${local.second_part}-how-are-you-today" which will evaluate to hello-there-how-are-you-today.

    At the bottom of the project, we define an S3 bucket and set the name to local.bucket_name. This will create an S3 bucket with the name hello-there-how-are-you-today.

    đź“ťNote: We do not need the ${ and } as we are not inside quotes here.

    We could also have set the bucket to "${local.bucket_name}", which would be evaluated to the same thing.

    In Terraform version 1.0.0, though, we can now omit the ${ and } for a single line expression where we are using the whole value. This makes the code cleaner and easier to read. Easily read code becomes vital when we define our infrastructure as code.

    Popularity 1/10 Helpfulness 1/10 Language whatever
    Source: Grepper
    Link to this answer
    Share Copy Link
    Contributed on May 19 2023
    Sumit Rawal
    0 Answers  Avg Quality 2/10


    X

    Continue with Google

    By continuing, I agree that I have read and agree to Greppers's Terms of Service and Privacy Policy.
    X
    Grepper Account Login Required

    Oops, You will need to install Grepper and log-in to perform this action.