Home > Software engineering >  Makefile variable manipulation
Makefile variable manipulation

Time:09-17

I'm doing this:

apply: init
    @terraform apply -auto-approve
    BUCKET=$(shell terraform output -json | jq '.S3_Bucket.value')
    DYNAMODB=$(shell terraform output -json | jq '.dynamo_db_lock.value')
    @echo $${BUCKET}

make shows both variables being set (I was using := but that doesn't work for me, since i need them set when i execute apply) but it's still echoing blank:

...
Outputs:

S3_Bucket = "bucket1"
dynamo_db_lock = "dyna1"
BUCKET="bucket"
DYNAMODB="dyna1"
    <-- echo should print it out here

I want to use that variable for a sed afterwards...

Thanks all!

CodePudding user response:

Each makefile recipe line is run in its own shell. Thus, shell variables set in one recipe line will not effect other recipe lines. You can get around this by catenating all the lines as so:

 apply: init
    @terraform apply -auto-approve
    @BUCKET=$(shell terraform output -json | jq '.S3_Bucket.value'); \
     DYNAMODB=$(shell terraform output -json | jq '.dynamo_db_lock.value'); \
     echo $${BUCKET}
  • Related