Dependencies
It is possible to define dependencies between modules in Stacks by passing outputs from one deployment as input to another deployment.
Passing Outputs
If you want to pass the output of one deployment to another deployment you can do so by using the following quoted syntax:
"{{ <ModuleKind>::<Name of the resource>::<outputName> }}"
Let’s say the VPC module has a defined output subnet_id
in the terraform code:
output "subnet_id" { value = aws_subnet.vpc.id}
To stay consistent with casing for the rest of the claim as an output subnetIds
will be generated.
This can then be passed to the EC2 instance:
apiVersion: infraweave.io/v1kind: VPCmetadata: name: myvpc namespace: defaultspec: moduleVersion: 0.1.5 region: us-west-2 variables: cidr: 10.0.0.0/24 ...---apiVersion: infraweave.io/v1kind: EC2metadata: name: myec2spec: moduleVersion: 1.0.4 region: us-west-2 variables: instance_type: c5.large subnet_ids: "{{ VPC::myvpc::subnetIds }}" ...
This will read the output from the created VPC and use it as input for EC2 (managed by Terraform).
Multiple Dependencies
You can define multiple dependencies for a deployment.
Below is an example of a IAMRole
resource that depends on the S3Bucket
, Lambda
and DynamoDB
resources.
The dependency resolver will find a valid order to deploy the resources based on the dependencies.
apiVersion: infraweave.io/v1kind: IAMRolemetadata: name: myiamrolespec: moduleVersion: 0.7.2 region: eu-central-1 policy: | { "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": "s3:ListBucket", "Resource": "{{ S3Bucket::s3bucket::bucketArn }}" }, { "Effect": "Allow", "Action": "lambda:InvokeFunction", "Resource": "{{ Lambda::mylambda::functionArn }}" }, { "Effect": "Allow", "Action": "dynamodb:Query", "Resource": "{{ DynamoDB::mydynamodb::tableArn }}" } ] } ...