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

Go templates in config values for edge and resource templates #732

Merged
merged 4 commits into from
Sep 19, 2023

Conversation

gordon-klotho
Copy link
Contributor

@gordon-klotho gordon-klotho commented Sep 12, 2023

Support go templates in configuration values.

Test input

constraints:
  - target: aws:api_integration:api_integration_api_01_pets
    scope: resource
    operator: equals
    property: Route
    value: /pets/:petId
resources:
  - aws:api_deployment:api_deployment-0
  - aws:api_integration:api_integration_api_01_pets
  - aws:api_method:api_method-api_integration_api_01_pets-0
  - aws:api_resource:-/-proxy-
  - aws:api_stage:api_stage-api_01-0
  - aws:ecr_image:ecr_image-pets-0
  - aws:ecr_repo:ecr_repo-0
  - aws:iam_role:iam_role-pets-0
  - aws:lambda_function:pets
  - aws:log_group:log_group-pets-0
  - aws:rest_api:api_01
resourceMetadata:
  - id: aws:api_deployment:api_deployment-0
    metadata:
      name: api_deployment-0
      restapi:
        name: api_01
        binarymediatypes: []
      triggers: {}
  - id: aws:api_integration:api_integration_api_01_pets
    metadata:
      name: api_integration_api_01_pets
      restapi:
        name: api_01
        binarymediatypes: []
      resource:
        name: -/-proxy-
        restapi:
          name: api_01
          binarymediatypes: []
        pathpart: /
        parentresource: null
      method:
        name: api_method-api_integration_api_01_pets-0
        restapi:
          name: api_01
          binarymediatypes: []
        resource: null
        httpmethod: ''
        requestparameters: {}
        authorization: ''
      requestparameters: {}
      integrationhttpmethod: ''
      type: ''
      connectiontype: ''
      vpclink: null
      uri:
        resourceid: ''
        property: ''
      route: /
  - id: aws:api_method:api_method-api_integration_api_01_pets-0
    metadata:
      name: api_method-api_integration_api_01_pets-0
      restapi:
        name: api_01
        binarymediatypes: []
      resource: null
      httpmethod: ''
      requestparameters: {}
      authorization: ''
  - id: aws:api_resource:-/-proxy-
    metadata:
      name: -/-proxy-
      restapi:
        name: api_01
        binarymediatypes: []
      pathpart: /
      parentresource: null
  - id: aws:api_stage:api_stage-api_01-0
    metadata:
      name: api_stage-api_01-0
      stagename: ''
      restapi:
        name: api_01
        binarymediatypes: []
      deployment:
        name: api_deployment-0
        restapi:
          name: api_01
          binarymediatypes: []
        triggers: {}
  - id: aws:ecr_image:ecr_image-pets-0
    metadata:
      name: ecr_image-pets-0
      imagename: ''
      repo:
        name: ecr_repo-0
        forcedelete: true
      context: ''
      dockerfile: ''
      extraoptions: []
      baseimage: ''
  - id: aws:ecr_repo:ecr_repo-0
    metadata:
      name: ecr_repo-0
      forcedelete: true
  - id: aws:iam_role:iam_role-pets-0
    metadata:
      name: iam_role-pets-0
      assumerolepolicydoc:
        version: '2012-10-17'
        statement:
          - effect: Allow
            action:
              - sts:AssumeRole
            resource: []
            principal:
              service: lambda.amazonaws.com
              federated:
                resourceid: ''
                property: ''
              aws:
                resourceid: ''
                property: ''
            condition: null
      managedpolicies: []
      awsmanagedpolicies:
        - arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole
      inlinepolicies: []
  - id: aws:lambda_function:pets
    metadata:
      name: pets
      role:
        name: iam_role-pets-0
        assumerolepolicydoc:
          version: '2012-10-17'
          statement:
            - effect: Allow
              action:
                - sts:AssumeRole
              resource: []
              principal:
                service: lambda.amazonaws.com
                federated:
                  resourceid: ''
                  property: ''
                aws:
                  resourceid: ''
                  property: ''
              condition: null
        managedpolicies: []
        awsmanagedpolicies:
          - arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole
        inlinepolicies: []
      image:
        name: ecr_image-pets-0
        imagename: ''
        repo:
          name: ecr_repo-0
          forcedelete: true
        context: ''
        dockerfile: ''
        extraoptions: []
        baseimage: ''
      securitygroups: []
      subnets: []
      timeout: 0
      memorysize: 0
      efsaccesspoint: null
  - id: aws:log_group:log_group-pets-0
    metadata:
      name: log_group-pets-0
      loggroupname: /aws/lambda/pets
      retentionindays: 0
  - id: aws:rest_api:api_01
    metadata:
      name: api_01
      binarymediatypes: []
edges:
  - source: aws:api_deployment:api_deployment-0
    destination: aws:api_integration:api_integration_api_01_pets
  - source: aws:api_deployment:api_deployment-0
    destination: aws:rest_api:api_01
  - source: aws:api_deployment:api_deployment-0
    destination: aws:api_method:api_method-api_integration_api_01_pets-0
  - source: aws:api_stage:api_stage-api_01-0
    destination: aws:rest_api:api_01
  - source: aws:api_stage:api_stage-api_01-0
    destination: aws:api_deployment:api_deployment-0
  - source: aws:ecr_image:ecr_image-pets-0
    destination: aws:ecr_repo:ecr_repo-0
  - source: aws:api_method:api_method-api_integration_api_01_pets-0
    destination: aws:api_integration:api_integration_api_01_pets
  - source: aws:api_integration:api_integration_api_01_pets
    destination: aws:lambda_function:pets
  - source: aws:api_resource:-/-proxy-
    destination: aws:api_integration:api_integration_api_01_pets
  - source: aws:lambda_function:pets
    destination: aws:iam_role:iam_role-pets-0
  - source: aws:lambda_function:pets
    destination: aws:ecr_image:ecr_image-pets-0
  - source: aws:lambda_function:pets
    destination: aws:log_group:log_group-pets-0
  - source: aws:rest_api:api_01
    destination: aws:api_resource:-/-proxy-
  - source: aws:rest_api:api_01
    destination: aws:api_method:api_method-api_integration_api_01_pets-0
  - source: aws:rest_api:api_01
    destination: aws:api_integration:api_integration_api_01_pets

Test Output Decisions (excerpt)

[
    {
        "Cause": {
            "constraint": "ResourceConstraint: aws:api_integration:api_integration_api_01_pets Route equals /pets/:petId"
        },
        "Resources": null,
        "Edges": null,
        "Config": [
            {
                "Resource": "aws:api_integration:api_integration_api_01_pets",
                "Config": {
                    "field": "Route",
                    "value": "/pets/:petId",
                    "value_template": "",
                    "zero_value_allowed": false
                }
            }
        ],
        "CauseMessage": "",
        "DisplayMessage": ""
    },
    {
        "Cause": {
            "resource_configuration": "aws:api_integration:api_integration_api_01_pets"
        },
        "Resources": null,
        "Edges": null,
        "Config": [
            {
                "Resource": "aws:api_integration:api_integration_api_01_pets",
                "Config": {
                    "field": "RequestParameters",
                    "value": {
                        "integration.request.path.petId": "method.request.path.petId"
                    },
                    "value_template": "",
                    "zero_value_allowed": false
                }
            }
        ],
        "CauseMessage": "",
        "DisplayMessage": ""
    },
    {
        "Cause": {
            "edge_expansion": "aws:api_method:api_method-api_integration_api_01_pets-0,aws:api_integration:api_integration_api_01_pets"
        },
        "Resources": null,
        "Edges": [
            {
                "Source": "aws:api_resource:-/-proxy-",
                "Destination": "aws:api_method:api_method-api_integration_api_01_pets-0"
            }
        ],
        "Config": [
            {
                "Resource": "aws:api_method:api_method-api_integration_api_01_pets-0",
                "Config": {
                    "field": "RequestParameters",
                    "value": {
                        "method.request.path.petId": true
                    },
                    "value_template": "",
                    "zero_value_allowed": false
                }
            }
        ],
        "CauseMessage": "",
        "DisplayMessage": "Connected api_method-api_integration_api_01_pets-0 to api_integration_api_01_pets, through the following resources: \n\taws:api_resource:-/-proxy-,\taws:api_method:api_method-api_integration_api_01_pets-0"
    },
]

Standard checks

  • Unit tests: Any special considerations?
  • Docs: Do we need to update any docs, internal or public?
  • Backwards compatibility: Will this break existing apps? If so, what would be the extra work required to keep them working?

@gordon-klotho gordon-klotho marked this pull request as ready for review September 12, 2023 22:07
@@ -630,29 +628,6 @@ func (e *Engine) handleEdgeConstainConstraint(constraint *constraints.EdgeConstr
return nil
}

func (e *Engine) ApplyResourceConstraint(graph *construct.ResourceGraph, constraint *constraints.ResourceConstraint) EngineError {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dont we either need this or line 368 to process resource constraints? Or am i missing that its moved somewhere else

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function itself was no longer being used. The line 368 change just moved it into the function configureResource which processes the constraints. It also now occurs on resource adding via decisions to make sure that any new resources are configured properly according to both user input constraints (if they happen to add a constraint for something that doesn't yet exist but would during resource expansion perhaps in the future we'd support {{ downstream x }} for example) as well as the templates' configuration.

pkg/knowledge_base/operational_funcs.go Outdated Show resolved Hide resolved
Base automatically changed from decisions to main September 13, 2023 17:48
@gordon-klotho gordon-klotho merged commit 33de449 into main Sep 19, 2023
82 of 84 checks passed
@gordon-klotho gordon-klotho deleted the feature/engine_config3 branch September 19, 2023 16:34
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