|
|
@ -1,8 +1,3 @@
|
|
|
|
---
|
|
|
|
|
|
|
|
sidebar_position: 3
|
|
|
|
|
|
|
|
slug: /programming/cloudformation
|
|
|
|
|
|
|
|
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Infra provisioning
|
|
|
|
# Infra provisioning
|
|
|
|
|
|
|
|
|
|
|
|
## Integrating with AWS Cloudformation
|
|
|
|
## Integrating with AWS Cloudformation
|
|
|
@ -59,8 +54,8 @@ The idea here is to follow best practices in [<u>S3 buckets</u>](https://docs.aw
|
|
|
|
|
|
|
|
|
|
|
|
The [<u>template</u>](https://docs.aws.amazon.com/fr_fr/AWSCloudFormation/latest/UserGuide/quickref-s3.html#scenario-s3-bucket-website) has far more outputs than necessary, as we just want to retrieve the bucket name:
|
|
|
|
The [<u>template</u>](https://docs.aws.amazon.com/fr_fr/AWSCloudFormation/latest/UserGuide/quickref-s3.html#scenario-s3-bucket-website) has far more outputs than necessary, as we just want to retrieve the bucket name:
|
|
|
|
|
|
|
|
|
|
|
|
import Tabs from '@theme/Tabs';
|
|
|
|
import Tabs from "@theme/Tabs";
|
|
|
|
import TabItem from '@theme/TabItem';
|
|
|
|
import TabItem from "@theme/TabItem";
|
|
|
|
|
|
|
|
|
|
|
|
<Tabs
|
|
|
|
<Tabs
|
|
|
|
defaultValue="nv"
|
|
|
|
defaultValue="nv"
|
|
|
@ -174,10 +169,7 @@ import TabItem from '@theme/TabItem';
|
|
|
|
"Outputs": {
|
|
|
|
"Outputs": {
|
|
|
|
"Name": {
|
|
|
|
"Name": {
|
|
|
|
"Value": {
|
|
|
|
"Value": {
|
|
|
|
"Fn::GetAtt": [
|
|
|
|
"Fn::GetAtt": ["S3Bucket", "Arn"]
|
|
|
|
"S3Bucket",
|
|
|
|
|
|
|
|
"Arn"
|
|
|
|
|
|
|
|
]
|
|
|
|
|
|
|
|
},
|
|
|
|
},
|
|
|
|
"Description": "Name S3 Bucket"
|
|
|
|
"Description": "Name S3 Bucket"
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -188,15 +180,15 @@ import TabItem from '@theme/TabItem';
|
|
|
|
</TabItem>
|
|
|
|
</TabItem>
|
|
|
|
</Tabs>
|
|
|
|
</Tabs>
|
|
|
|
|
|
|
|
|
|
|
|
2. Some *"Pro tips"*
|
|
|
|
2. Some _"Pro tips"_
|
|
|
|
|
|
|
|
|
|
|
|
Double-checks at the template level can be done with manual uploads on Cloudformation's web interface or by executing the below command locally:
|
|
|
|
Double-checks at the template level can be done with manual uploads on Cloudformation's web interface or by executing the below command locally:
|
|
|
|
|
|
|
|
|
|
|
|
```bash
|
|
|
|
```bash
|
|
|
|
aws cloudformation validate-template --template-body file://template.json
|
|
|
|
aws cloudformation validate-template --template-body file://template.json
|
|
|
|
```
|
|
|
|
```
|
|
|
|
> PS: The *"Full Base Template"* tab contains the base template used for the following parts of the guide
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
> PS: The _"Full Base Template"_ tab contains the base template used for the following parts of the guide
|
|
|
|
|
|
|
|
|
|
|
|
### JSON / YAML to Cue conversion
|
|
|
|
### JSON / YAML to Cue conversion
|
|
|
|
|
|
|
|
|
|
|
@ -320,7 +312,9 @@ data: """
|
|
|
|
</Tabs>
|
|
|
|
</Tabs>
|
|
|
|
|
|
|
|
|
|
|
|
###### 2. Retrieve the Unmarshalled JSON
|
|
|
|
###### 2. Retrieve the Unmarshalled JSON
|
|
|
|
|
|
|
|
|
|
|
|
Then, still in the same folder, query the `point` value to retrieve the Unmarshalled result of `data`:
|
|
|
|
Then, still in the same folder, query the `point` value to retrieve the Unmarshalled result of `data`:
|
|
|
|
|
|
|
|
|
|
|
|
<Tabs
|
|
|
|
<Tabs
|
|
|
|
defaultValue="sc"
|
|
|
|
defaultValue="sc"
|
|
|
|
values={[
|
|
|
|
values={[
|
|
|
@ -418,28 +412,27 @@ This Cue version of the JSON template is going to be integrated inside our provi
|
|
|
|
|
|
|
|
|
|
|
|
With the Cloudformation template now finished, tested and converted in Cue. We can now enter the last part of our guide: piping everything together inside our personal plan.
|
|
|
|
With the Cloudformation template now finished, tested and converted in Cue. We can now enter the last part of our guide: piping everything together inside our personal plan.
|
|
|
|
|
|
|
|
|
|
|
|
Before continuing, don't forget to reset your `main.cue` plan to it's *Setup* form:
|
|
|
|
Before continuing, don't forget to reset your `main.cue` plan to it's _Setup_ form:
|
|
|
|
|
|
|
|
|
|
|
|
```cue
|
|
|
|
```cue
|
|
|
|
-- ~/infra-provisioning/.dagger/env/s3-provisioning/plan/main.cue --
|
|
|
|
-- ~/infra-provisioning/.dagger/env/s3-provisioning/plan/main.cue --
|
|
|
|
package main
|
|
|
|
package main
|
|
|
|
```
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
### Cloudformation relay
|
|
|
|
### Cloudformation relay
|
|
|
|
|
|
|
|
|
|
|
|
As our plan relies on [<u>Cloudformation's relay</u>](https://dagger.io/aws/cloudformation), let's dissect the expected inputs by gradually incorporating them in our plan.
|
|
|
|
As our plan relies on [<u>Cloudformation's relay</u>](https://dagger.io/aws/cloudformation), let's dissect the expected inputs by gradually incorporating them in our plan.
|
|
|
|
|
|
|
|
|
|
|
|
| Name | Type | Description |
|
|
|
|
| Name | Type | Description |
|
|
|
|
| ------------- |:-------------: |:-------------: |
|
|
|
|
| ------------------ | :---------------------------------------: | :------------------------------------------------------------------: |
|
|
|
|
|*config.region* | `string` |AWS region |
|
|
|
|
| _config.region_ | `string` | AWS region |
|
|
|
|
|*config.accessKey* | `dagger.#Secret` |AWS access key |
|
|
|
|
| _config.accessKey_ | `dagger.#Secret` | AWS access key |
|
|
|
|
|*config.secretKey* | `dagger.#Secret` |AWS secret key |
|
|
|
|
| _config.secretKey_ | `dagger.#Secret` | AWS secret key |
|
|
|
|
|*source* | `string` |Source is the Cloudformation template (JSON/YAML string) |
|
|
|
|
| _source_ | `string` | Source is the Cloudformation template (JSON/YAML string) |
|
|
|
|
|*stackName* | `string` |Stackname is the cloudformation stack |
|
|
|
|
| _stackName_ | `string` | Stackname is the cloudformation stack |
|
|
|
|
|*onFailure* | `*"DO_NOTHING" \| "ROLLBACK" \| "DELETE"` |Behavior when failure to create/update the Stack |
|
|
|
|
| _onFailure_ | `*"DO_NOTHING" \| "ROLLBACK" \| "DELETE"` | Behavior when failure to create/update the Stack |
|
|
|
|
|*timeout* | `*10 \| \>=0 & int` |Timeout for waiting for the stack to be created/updated (in minutes) |
|
|
|
|
| _timeout_ | `*10 \| \>=0 & int` | Timeout for waiting for the stack to be created/updated (in minutes) |
|
|
|
|
|*neverUpdate* | `*false \| bool` |Never update the stack if already exists |
|
|
|
|
| _neverUpdate_ | `*false \| bool` | Never update the stack if already exists |
|
|
|
|
|
|
|
|
|
|
|
|
1. General insights
|
|
|
|
1. General insights
|
|
|
|
|
|
|
|
|
|
|
@ -447,11 +440,11 @@ As seen before in the documentation, values starting with `*` are default values
|
|
|
|
|
|
|
|
|
|
|
|
> WARNING: All inputs without a default option have to be filled for a proper execution of the relay. In our case:
|
|
|
|
> WARNING: All inputs without a default option have to be filled for a proper execution of the relay. In our case:
|
|
|
|
>
|
|
|
|
>
|
|
|
|
>* *config.region*
|
|
|
|
> - _config.region_
|
|
|
|
>* *config.accessKey*
|
|
|
|
> - _config.accessKey_
|
|
|
|
>* *config.secretKey*
|
|
|
|
> - _config.secretKey_
|
|
|
|
>* *source*
|
|
|
|
> - _source_
|
|
|
|
>* *stackName*
|
|
|
|
> - _stackName_
|
|
|
|
|
|
|
|
|
|
|
|
2. The config value
|
|
|
|
2. The config value
|
|
|
|
|
|
|
|
|
|
|
@ -515,7 +508,7 @@ awsConfig: aws.#Config & { // Assign an aws.#Config definition to a field named
|
|
|
|
</TabItem>
|
|
|
|
</TabItem>
|
|
|
|
</Tabs>
|
|
|
|
</Tabs>
|
|
|
|
|
|
|
|
|
|
|
|
*Pro tips: In order to check wether it worked or not, these two commands might help*
|
|
|
|
_Pro tips: In order to check wether it worked or not, these two commands might help_
|
|
|
|
|
|
|
|
|
|
|
|
<Tabs
|
|
|
|
<Tabs
|
|
|
|
defaultValue="fc"
|
|
|
|
defaultValue="fc"
|
|
|
@ -897,4 +890,3 @@ The name of the provisioned S3 instance lies in the `cfnStack.outputs.Name` outp
|
|
|
|
PS: This plan could be further extended with the AWS S3 example : it could not only provision an infrastructure but also easily deploy on it.
|
|
|
|
PS: This plan could be further extended with the AWS S3 example : it could not only provision an infrastructure but also easily deploy on it.
|
|
|
|
|
|
|
|
|
|
|
|
PS1: As it could make a nice first exercise for you, this won't be detailed here. However, we're interested in your imagination : let us know your implementations :-)
|
|
|
|
PS1: As it could make a nice first exercise for you, this won't be detailed here. However, we're interested in your imagination : let us know your implementations :-)
|
|
|
|
|
|
|
|
|
|
|
|