Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Support named export #42

Merged
merged 2 commits into from
Oct 6, 2024

Conversation

derek10cloud
Copy link
Collaborator

@derek10cloud derek10cloud commented Oct 1, 2024

Description

This PR enhances the export functionality in StackQL to allow for named exports when reusing an .iql file for multiple resources within a stack. #41

The changes enable exports to be defined as either a simple list of strings or as objects that map exported variables to renamed assigned variables.

I also add the logic of checking type consistency in expected_exports (all items({items}) must be either dicts or non-dicts)

Fixes

  • Fix the base.py file in cmd dir and the utils.py file in lib dir.
  • Suppose that expected_exports's type can be a list or an object(dict)(But don't the elements of expected_exports should be same type, not allowing different type.)
  • If expected_exports is an object(dict), the value of expected_exports is a name of export.

Checklist

Please make sure that the following criteria are met:

  • The PR title is descriptive.
  • For example stacks, I have included a descriptive README.md in the example project directory, which describes the stack and includes instructions to deploy or test.
  • For example stacks, add your stack to the website template library at website/docs/template-library/.. which gets published to stackql-deploy.io (optional)
  • I have ⭐'ed the stackql and stackql-deploy repos.

Additional Notes

I tested it like below

1) make stackql manifest

# will make an example of stackql resources(vpc) for aws
$ stackql-deploy init {STACK_DIR} --provider aws 
$ cd {STACK_DIR}

2) set all exports as named export (unnamed export is already supported, so I am not showing that case.)

...
    exports:
      - vpc_id: renamed_vpc_id
      - vpc_cidr_block: renamed_vpc_cidr_block
...

fyi) not allowing below manifest

...
    exports:
      - vpc_id: renamed_vpc_id
      - vpc_cidr_block 
...

becuase exports' types are different each other.

3) build resources

$ stackql-deploy build . dev -e AWS_REGION=ap-northeast-2

image

image

4) I also tested test command

$ stackql-deploy test . dev -e AWS_REGION=ap-northeast-2

image

5) also tested teardown command

  • before test teardown, if you used named export like above, not a unnamed export, you should set props like below.
# stackql_manifest.yml
...
props:
     - name: vpc_id # populate `renamed_vpc_id` key in the context when tearing down
         value: "{{ renamed_vpc_id }}"
     - name: vpc_cidr_block # populate `renamed_vpc_cidr_block` key in the context when tearing down
        value: "{{ renamed_vpc_cidr_block }}"
    exports:
      - vpc_id: renamed_vpc_id
      - vpc_cidr_block: renamed_vpc_cidr_block
  • And then execute below command
$ stackql-deploy teardown . dev -e AWS_REGION=ap-northeast-2

image

image

@derek10cloud derek10cloud force-pushed the generic-to-named-export branch from 34bf8e1 to e56b61f Compare October 2, 2024 13:27
@derek10cloud derek10cloud changed the title feat: Support both generic export and named export feat: Support named export Oct 2, 2024
@derek10cloud derek10cloud force-pushed the generic-to-named-export branch from e56b61f to e76b6fb Compare October 2, 2024 13:51
@jeffreyaven jeffreyaven merged commit eb9abd0 into stackql:main Oct 6, 2024
2 checks passed
@derek10cloud
Copy link
Collaborator Author

fyi) my example manifest file

#
# aws starter project manifest file, add and update values as needed
#
version: 1
name: "derek-aws-vpc"
description: description for "derek-aws-vpc"
providers:
  - aws
globals:
  - name: region
    description: aws region
    value: "{{ AWS_REGION }}"
  - name: global_tags
    value:
      - Key: Provisioner
        Value: stackql
      - Key: StackName
        Value: "{{ stack_name }}"
      - Key: StackEnv
        Value: "{{ stack_env }}"
resources:
  - name: example_vpc
    description: example vpc resource
    props:
      - name: vpc_cidr_block
        values:
          prd:
            value: "10.0.0.0/16"
          sit:
            value: "10.1.0.0/16"
          dev:
            value: "10.2.0.0/16"
      - name: vpc_tags
        value:
          - Key: Name
            Value: "{{ stack_name }}-{{ stack_env }}-vpc"
        merge: ['global_tags']
      - name: vpc_id # blank when building, populate when tearing down
        value: "{{ renamed_vpc_id }}"
    exports:
      - vpc_id: renamed_vpc_id
      - vpc_cidr_block: renamed_vpc_cidr_block

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants