Makefile 变量操作
Makefile variable manipulation
我正在这样做:
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 显示正在设置的两个变量(我正在使用 := 但这对我不起作用,因为我在执行 apply
时需要设置它们)但它仍然回显空白:
...
Outputs:
S3_Bucket = "bucket1"
dynamo_db_lock = "dyna1"
BUCKET="bucket"
DYNAMODB="dyna1"
<-- echo should print it out here
之后我想将该变量用于 sed...
谢谢大家!
每个 makefile 配方行都是 运行 在它自己的 shell 中。因此,在一个配方行中设置的 shell 变量不会影响其他配方行。您可以通过这样连接所有行来解决此问题:
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}
我正在这样做:
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 显示正在设置的两个变量(我正在使用 := 但这对我不起作用,因为我在执行 apply
时需要设置它们)但它仍然回显空白:
...
Outputs:
S3_Bucket = "bucket1"
dynamo_db_lock = "dyna1"
BUCKET="bucket"
DYNAMODB="dyna1"
<-- echo should print it out here
之后我想将该变量用于 sed...
谢谢大家!
每个 makefile 配方行都是 运行 在它自己的 shell 中。因此,在一个配方行中设置的 shell 变量不会影响其他配方行。您可以通过这样连接所有行来解决此问题:
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}