diff --git a/.gitignore b/.gitignore index 84e63fd..1ce636e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,4 @@ .vscode/* -!.vscode/settings.json -!.vscode/tasks.json -!.vscode/launch.json !.vscode/extensions.json !.vscode/*.code-snippets @@ -37,3 +34,5 @@ node_modules # File generated by the inventory-collector should not be committed inventory.csv + +.venv diff --git a/elastio-deployment/cloudformation/README.md b/elastio-deployment/cloudformation/README.md index 3c917f7..6ef2d27 100644 --- a/elastio-deployment/cloudformation/README.md +++ b/elastio-deployment/cloudformation/README.md @@ -56,10 +56,10 @@ Here are some links to the released versions of both Cloudformation templates. ### `connector.yaml` template -- [Single-click deployment link](https://us-east-1.console.aws.amazon.com/cloudformation/home?region=us-east-1#/stacks/create/review?templateURL=https://elastio-prod-artifacts-us-east-1.s3.us-east-1.amazonaws.com/contrib/elastio-deployment/cloudformation/v1/connector.yaml&stackName=elastio-connector) -- [Template download link](https://elastio-prod-artifacts-us-east-1.s3.us-east-1.amazonaws.com/contrib/elastio-deployment/cloudformation/v1/connector.yaml) +- [Single-click deployment link](https://us-east-1.console.aws.amazon.com/cloudformation/home?region=us-east-1#/stacks/create/review?templateURL=https://elastio-prod-artifacts-us-east-1.s3.us-east-1.amazonaws.com/contrib/elastio-deployment/cloudformation/v2/connector.yaml&stackName=elastio-connector) +- [Template download link](https://elastio-prod-artifacts-us-east-1.s3.us-east-1.amazonaws.com/contrib/elastio-deployment/cloudformation/v2/connector.yaml) ### `connector-region.yaml` template -- [Single-click deployment link](https://us-east-1.console.aws.amazon.com/cloudformation/home?region=us-east-1#/stacks/create/review?templateURL=https://elastio-prod-artifacts-us-east-1.s3.us-east-1.amazonaws.com/contrib/elastio-deployment/cloudformation/v1/connector-region.yaml&stackName=elastio-connector-region) -- [Template download link](https://elastio-prod-artifacts-us-east-1.s3.us-east-1.amazonaws.com/contrib/elastio-deployment/cloudformation/v1/connector-region.yaml) +- [Single-click deployment link](https://us-east-1.console.aws.amazon.com/cloudformation/home?region=us-east-1#/stacks/create/review?templateURL=https://elastio-prod-artifacts-us-east-1.s3.us-east-1.amazonaws.com/contrib/elastio-deployment/cloudformation/v2/connector-region.yaml&stackName=elastio-connector-region) +- [Template download link](https://elastio-prod-artifacts-us-east-1.s3.us-east-1.amazonaws.com/contrib/elastio-deployment/cloudformation/v2/connector-region.yaml) diff --git a/elastio-deployment/cloudformation/connector-region.yaml b/elastio-deployment/cloudformation/connector-region.yaml index 8dce2a9..10a0e65 100644 --- a/elastio-deployment/cloudformation/connector-region.yaml +++ b/elastio-deployment/cloudformation/connector-region.yaml @@ -29,6 +29,14 @@ Parameters: If not set or empty,then Elastio will create an Elastio-managed VPC for the connector. Make sure to enable 'Auto-Create VPC' option for the Connector Account stack. + ElastioConnectorAccountStackVersion: + Type: String + Default: '' + Description: > + The version of the deployed Elastio Connector Account stack. This + parameter is used only to ensure that the connector region stack + deployment is re-triggred when the Connector Account stack is updated. + Metadata: AWS::CloudFormation::Interface: ParameterGroups: @@ -97,14 +105,6 @@ Resources: MemorySize: 512 Timeout: 600 Role: !GetAtt LambdaRole.Arn - - Environment: - Variables: - ELASTIO_PAT: !Ref ElastioPat - ELASTIO_TENANT: !Ref ElastioTenant - ELASTIO_AWS_ACCOUNT_ID: !Ref AWS::AccountId - ELASTIO_VPC_ID: !Ref ElastioVpcId - ELASTIO_SUBNET_IDS: !Join [',', !Ref ElastioSubnetIds] Code: S3Bucket: !Sub '{{S3_BUCKET_PREFIX}}-${AWS::Region}' S3Key: {{S3_KEY_PREFIX}}/{{VERSION}}/lambda.zip @@ -116,6 +116,16 @@ Resources: DeletionPolicy: Delete Properties: ServiceToken: !GetAtt LambdaFunction.Arn + ServiceTimeout: 60 + ElastioPat: !Ref ElastioPat + ElastioTenant: !Ref ElastioTenant + ElastioAwsAccountId: !Ref AWS::AccountId + ElastioVpcId: !Ref ElastioVpcId + ElastioSubnetIds: !Join [',', !Ref ElastioSubnetIds] + + # Make sure an update is triggered when versions change + ElastioConnectorAccountStackVersion: !Ref ElastioConnectorAccountStackVersion + ElastioConnectorRegionDelegatorStackVersion: '{{VERSION}}' Outputs: templateVersion: diff --git a/elastio-deployment/cloudformation/connector.yaml b/elastio-deployment/cloudformation/connector.yaml index 4d1d43c..f30d505 100644 --- a/elastio-deployment/cloudformation/connector.yaml +++ b/elastio-deployment/cloudformation/connector.yaml @@ -71,8 +71,11 @@ Resources: Tags: - Key: elastio:resource Value: 'true' + - Key: elastio:connector:account:stack-version + Value: !GetAtt account.Outputs.accountStackVersion Parameters: ElastioTenant: !Ref ElastioTenant ElastioPat: !Ref ElastioPat ElastioVpcId: !Ref ElastioVpcId ElastioSubnetIds: !Join [',', !Ref ElastioSubnetIds] + ElastioConnectorAccountStackVersion: !GetAtt account.Outputs.accountStackVersion diff --git a/elastio-deployment/cloudformation/lambda.py b/elastio-deployment/cloudformation/lambda.py index 728cefd..d39a39d 100644 --- a/elastio-deployment/cloudformation/lambda.py +++ b/elastio-deployment/cloudformation/lambda.py @@ -28,8 +28,10 @@ def send_cfn_response(status, reason=None): print(response.read().decode()) try: + print(f"Received event: {json.dumps(event)}") + if event["RequestType"] == "Create" or event["RequestType"] == "Update": - run() + run(event["ResourceProperties"]) send_cfn_response("SUCCESS") except HTTPError as e: send_cfn_response("FAILED", f"{e}: {e.read().decode()}") @@ -38,19 +40,19 @@ def send_cfn_response(status, reason=None): raise -def run(): - elastio_pat = os.environ["ELASTIO_PAT"] - elastio_tenant = os.environ["ELASTIO_TENANT"] +def run(props): + elastio_pat = props["ElastioPat"] + elastio_tenant = props["ElastioTenant"] elastio_endpoint = f"https://{elastio_tenant}/public-api/v1" - subnet_ids = os.environ.get("ELASTIO_SUBNET_IDS") + subnet_ids = props.get("ElastioSubnetIds") request_body = { "region": os.environ["AWS_REGION"], - "account_id": os.environ["ELASTIO_AWS_ACCOUNT_ID"], + "account_id": props["ElastioAwsAccountId"], # # None `vpc_id/subnet_ids` means we'll create a new Elastio-managed VPC - "vpc_id": os.environ.get("ELASTIO_VPC_ID") or None, + "vpc_id": props.get("ElastioVpcId") or None, "subnet_ids": subnet_ids.split(",") if subnet_ids else None, } diff --git a/elastio-deployment/cloudformation/version b/elastio-deployment/cloudformation/version index 626799f..8c1384d 100644 --- a/elastio-deployment/cloudformation/version +++ b/elastio-deployment/cloudformation/version @@ -1 +1 @@ -v1 +v2