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(container): add resource containers as service #1103

Merged
Merged
Show file tree
Hide file tree
Changes from 24 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
11f98b9
feat(containers): add container creation
Monitob Feb 17, 2022
77e189b
feat(container): add container helpers and resources
Monitob Feb 22, 2022
9fa8a4f
feat(containers): remove handler container and add read/update and ne…
Monitob Feb 23, 2022
1102e6a
feat(containers): add check for environment variables
Monitob Feb 23, 2022
f4d0d15
Update scaleway/provider.go
Monitob Feb 23, 2022
76a1877
feat(container): add container helpers and resources
Monitob Feb 22, 2022
cea6d3f
feat(containers): remove handler container and add read/update and ne…
Monitob Feb 23, 2022
3f9f44f
feat(containers): add container test
Monitob Mar 1, 2022
3591841
feat(containers): add helpers
Monitob Mar 4, 2022
ababec6
feat(containers): add containers default values and descriptions
Monitob Mar 4, 2022
d1b9456
feat(containers): bump cassettes
Monitob Mar 4, 2022
bcca45b
feat(container): add container test with registry image
Monitob Mar 7, 2022
467c5f6
feat(container): add docker test
Monitob Mar 9, 2022
d9e3de0
chore: add cassette test containers with image
Monitob Mar 9, 2022
ebfafa5
fix(containers): helpers
Monitob Mar 11, 2022
75d498a
fix(containers): read corrections
Monitob Mar 11, 2022
97c4581
fix(test): add cassettes
Monitob Mar 11, 2022
30bb74d
bump depencencies
Monitob Mar 11, 2022
c540fa3
feat(container): add cassettes
Monitob Mar 14, 2022
676e2e3
feat(container): add datasource container
Monitob Mar 14, 2022
fdf3d40
feat(container): add documentation for resource and datasource
Monitob Mar 14, 2022
051e273
feat(container) add push image on registry and enhancements
Monitob Mar 14, 2022
84ab3b9
fix(docs): resource/data_source
Monitob Mar 22, 2022
d6bcbff
Merge branch 'master' into feat-add-resource-containers-as-service
remyleone Mar 28, 2022
38b7e6c
Merge branch 'master' into feat-add-resource-containers-as-service
remyleone Mar 31, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/acceptance-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ jobs:
TF_ACC: 1
TF_UPDATE_CASSETTES: false
TF_TEST_DOMAIN: scaleway-terraform.com
TF_TEST_DOCKER_IMG: docker.io/library/alpine
SCW_DEBUG: 0
SCW_ACCESS_KEY: "SCWXXXXXXXXXXXXXFAKE"
SCW_SECRET_KEY: "11111111-1111-1111-1111-111111111111"
2 changes: 2 additions & 0 deletions .github/workflows/nightly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ jobs:
# Enable recording with the cassette system. By doing so, we ensure that real HTTPS requests are made.
TF_UPDATE_CASSETTES: true
TF_TEST_DOMAIN: scaleway-terraform.com
TF_TEST_DOCKER_IMG: docker.io/library/alpine
SCW_DEBUG: 1
SCW_ACCESS_KEY: ${{ secrets.SCW_ACCESS_KEY }}
SCW_SECRET_KEY: ${{ secrets.SCW_SECRET_KEY }}
Expand All @@ -66,6 +67,7 @@ jobs:
run: make sweep
env:
TF_TEST_DOMAIN: scaleway-terraform.com
TF_TEST_DOCKER_IMG: docker.io/library/alpine
SCW_ACCESS_KEY: ${{ secrets.SCW_ACCESS_KEY }}
SCW_SECRET_KEY: ${{ secrets.SCW_SECRET_KEY }}
SCW_DEFAULT_ORGANIZATION_ID: ${{ secrets.SCW_DEFAULT_ORGANIZATION_ID }}
Expand Down
6 changes: 6 additions & 0 deletions TESTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@ You can force the test domain with an environment var:
export TF_TEST_DOMAIN=your-domain.tld
```

For testing the container API with your own image you can force the environment var:

```shell
export TF_TEST_DOCKER_IMG=your_image
```

To ease debugging you can also set:
```sh
export TF_LOG=DEBUG
Expand Down
90 changes: 90 additions & 0 deletions docs/data-sources/container.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
---
page_title: "Scaleway: scaleway_container"
description: |-
Gets information about a container.
---
# scaleway_container

Gets information about the Scaleway Container.

For more information consult the [documentation](https://www.scaleway.com/en/docs/faq/serverless-containers/).

For more details about the limitation check [containers-limitations](https://www.scaleway.com/en/docs/compute/containers/reference-content/containers-limitations/).

You can check also our [containers guide](https://www.scaleway.com/en/docs/compute/containers/concepts/).

## Example Usage

```hcl
resource scaleway_container_namespace main {
}

resource scaleway_container main {
name = "test-container-data"
namespace_id = scaleway_container_namespace.main.id
}

// Get info by container name
data "scaleway_container" "by_name" {
namespace_id = scaleway_container_namespace.main.id
name = scaleway_container.main.name
}

// Get info by container ID
data "scaleway_container" "by_id" {
namespace_id = scaleway_container_namespace.main.id
container_id = scaleway_container.main.id
}
```

## Arguments Reference

The following arguments are required:

- `name` - (Required) The unique name of the container name.

- `namespace_id` - (Required) The container namespace ID of the container.

~> **Important** Updates to `name` will recreate the container.

## Attributes Reference

In addition to all arguments above, the following attributes are exported:

- `id` - The ID of the container

- `description` The description of the container.

- `environment_variables` - The [environment](https://www.scaleway.com/en/docs/compute/containers/concepts/#environment-variables) variables of the container.

- `min_scale` - The minimum of running container instances continuously. Defaults to 0.

- `max_scale` - The maximum of number of instances this container can scale to. Default to 20.

- `memory_limit` - The memory computing resources in MB to allocate to each container. Defaults to 128.

- `cpu_limit` - The amount of vCPU computing resources to allocate to each container. Defaults to 70.

- `timeout` - The maximum amount of time in seconds during which your container can process a request before we stop it. Defaults to 300s.

- `privacy` - The privacy type define the way to authenticate to your container. Please check our dedicated [section](https://developers.scaleway.com/en/products/containers/api/#protocol-9dd4c8).

- `registry_image` - The registry image address. e.g: **"rg.fr-par.scw.cloud/$NAMESPACE/$IMAGE"**.

- `max_concurrency` - The maximum number of simultaneous requests your container can handle at the same time. Defaults to 50.

- `domain_name` - The container domain name.

- `protocol` - The communication [protocol](https://developers.scaleway.com/en/products/containers/api/#protocol-9dd4c8) http1 or h2c. Defaults to http1.

- `port` - The port to expose the container. Defaults to 8080.

- `deploy` - Boolean indicating whether the container is on a production environment.

- `status` - The container status.

- `cron_status` - The cron status of the container.

- `error_message` - The error message of the container.

- `region` - (Defaults to [provider](../index.md#region) `region`) The [region](../guides/regions_and_zones.md#regions) in which the container was created.
140 changes: 140 additions & 0 deletions docs/resources/container.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
---
page_title: "Scaleway: scaleway_container"
description: |-
Manages Scaleway Containers.
---

# scaleway_container

Creates and manages Scaleway Container.

For more information consult the [documentation](https://www.scaleway.com/en/docs/faq/serverless-containers/).

For more details about the limitation check [containers-limitations](https://www.scaleway.com/en/docs/compute/containers/reference-content/containers-limitations/).

You can check also our [containers guide](https://www.scaleway.com/en/docs/compute/containers/concepts/).

## Example Usage

```hcl
resource scaleway_container_namespace main {
name = "my-ns-test"
description = "test container"
}

resource scaleway_container main {
name = "my-container-02"
description = "environment variables test"
namespace_id = scaleway_container_namespace.main.id
registry_image = "${scaleway_container_namespace.main.endpoint}/alpine:test"
port = 9997
cpu_limit = 140
memory_limit = 256
min_scale = 3
max_scale = 5
timeout = 600
max_concurrency = 80
privacy = "private"
protocol = "h2c"
deploy = true

environment_variables = {
"foo" = "var"
}
}
```

## Arguments Reference

The following arguments are required:

- `name` - (Required) The unique name of the container name.

- `namespace_id` - (Required) The container namespace ID of the container.

~> **Important** Updates to `name` will recreate the container.

The following arguments are optional:

- `description` (Optional) The description of the container.

- `environment_variables` - (Optional) The [environment](https://www.scaleway.com/en/docs/compute/containers/concepts/#environment-variables) variables of the container.

- `min_scale` - (Optional) The minimum of running container instances continuously. Defaults to 0.

- `max_scale` - (Optional) The maximum of number of instances this container can scale to. Default to 20.

- `memory_limit` - (Optional) The memory computing resources in MB to allocate to each container. Defaults to 128.

- `cpu_limit` - (Optional) The amount of vCPU computing resources to allocate to each container. Defaults to 70.

- `timeout` - (Optional) The maximum amount of time in seconds during which your container can process a request before we stop it. Defaults to 300s.

- `privacy` - (Optional) The privacy type define the way to authenticate to your container. Please check our dedicated [section](https://developers.scaleway.com/en/products/containers/api/#protocol-9dd4c8).

- `registry_image` - (Optional) The registry image address. e.g: **"rg.fr-par.scw.cloud/$NAMESPACE/$IMAGE"**.

- `max_concurrency` - (Optional) The maximum number of simultaneous requests your container can handle at the same time. Defaults to 50.

- `domain_name` - (Optional) The container domain name.

- `protocol` - (Optional) The communication [protocol](https://developers.scaleway.com/en/products/containers/api/#protocol-9dd4c8) http1 or h2c. Defaults to http1.

- `port` - (Optional) The port to expose the container. Defaults to 8080.

- `deploy` - (Optional) Boolean controlling whether the container is on a production environment.

Note that if you want to use your own configuration, you must consult our configuration [restrictions](https://www.scaleway.com/en/docs/compute/containers/reference-content/containers-limitations/#configuration-restrictions) section.

## Attributes Reference

In addition to all above arguments, the following attributes are exported:

- `region` - (Defaults to [provider](../index.md#region) `region`) The [region](../guides/regions_and_zones.md#regions) in which the container was created.
- `status` - The container status.
- `cron_status` - The cron status of the container.
- `error_message` - The error message of the container.

## Import

Container can be imported using the container_name, e.g.,

```bash
$ terraform import scaleway_container.main fr-par/11111111-1111-1111-1111-111111111111
```

## Protocols

The supported protocols are:

* `h2c`: HTTP/2 over TCP.
* `http1`: Hypertext Transfer Protocol.

**Important:** For details about the protocols check [this](https://httpd.apache.org/docs/2.4/howto/http2.html)

## Privacy

By default, creating a container will make it `public`, meaning that anybody knowing the endpoint could execute it.
A container can be made `private` with the privacy parameter.

Please check our [authentication](https://developers.scaleway.com/en/products/containers/api/#protocol-9dd4c8) section

## Memory and vCPUs configuration

The vCPU represents a portion or share of the underlying, physical CPU that is assigned to a particular virtual machine (VM).
Copy link
Member

Choose a reason for hiding this comment

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

How is this portion measured? What is the maximum vCPU possible in theory? Is it a gauge?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The hypervisor uses a portion of the physical CPU computing resources and allocates it to a vCPU which is assigned to a specific Container. The maximum allowed is 1.12 vCPU.


You may decide how much computing resources to allocate to each container.
The `memory_limit` (in MB) must correspond with the right amount of vCPU.

**Important:** The right choice for your container's resources is very important, as you will be billed based on compute usage over time and the number of Containers executions.

Please check our [price](https://www.scaleway.com/en/docs/faq/serverless-containers/#prices) section for more details.

| Memory (in MB) | vCPU |
|----------------|------|
| 128 | 70m |
| 256 | 140m |
| 512 | 280m |
| 1024 | 560m |

**Note:** 560mCPU accounts roughly for half of one CPU power of a Scaleway General Purpose instance
Copy link
Member

Choose a reason for hiding this comment

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

Which? We got several. @ofranc could you check to have a consistent naming across all our documentation?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Phrase from here. It refers to the last configuration case.

21 changes: 17 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module github.com/scaleway/terraform-provider-scaleway/v2
require (
github.com/aws/aws-sdk-go v1.43.18
github.com/dnaeon/go-vcr v1.2.0
github.com/docker/docker v20.10.12+incompatible
github.com/dustin/go-humanize v1.0.0
github.com/google/go-cmp v0.5.7
github.com/hashicorp/aws-sdk-go-base v1.1.0
Expand All @@ -16,13 +17,20 @@ require (
)

require (
github.com/Microsoft/go-winio v0.5.2 // indirect
github.com/agext/levenshtein v1.2.2 // indirect
github.com/apparentlymart/go-cidr v1.1.0 // indirect
github.com/apparentlymart/go-textseg/v13 v13.0.0 // indirect
github.com/containerd/containerd v1.6.1 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/docker/distribution v2.8.1+incompatible // indirect
github.com/docker/go-connections v0.4.0 // indirect
github.com/docker/go-units v0.4.0 // indirect
github.com/fatih/color v1.7.0 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/hashicorp/errwrap v1.0.0 // indirect
github.com/gorilla/mux v1.8.0 // indirect
github.com/hashicorp/errwrap v1.1.0 // indirect
github.com/hashicorp/go-checkpoint v0.5.0 // indirect
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
github.com/hashicorp/go-hclog v1.2.0 // indirect
Expand All @@ -48,18 +56,23 @@ require (
github.com/mitchellh/go-wordwrap v1.0.0 // indirect
github.com/mitchellh/mapstructure v1.4.3 // indirect
github.com/mitchellh/reflectwalk v1.0.2 // indirect
github.com/moby/term v0.0.0-20210619224110-3f7ff695adc6 // indirect
github.com/oklog/run v1.0.0 // indirect
github.com/opencontainers/go-digest v1.0.0 // indirect
github.com/opencontainers/image-spec v1.0.2 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/sirupsen/logrus v1.8.1 // indirect
github.com/vmihailenco/msgpack v4.0.4+incompatible // indirect
github.com/vmihailenco/msgpack/v4 v4.3.12 // indirect
github.com/vmihailenco/tagparser v0.1.1 // indirect
github.com/zclconf/go-cty v1.10.0 // indirect
golang.org/x/crypto v0.0.0-20210616213533-5ff15b29337e // indirect
golang.org/x/crypto v0.0.0-20210817164053-32db794688a5 // indirect
golang.org/x/net v0.0.0-20220127200216-cd36cc0744dd // indirect
golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e // indirect
golang.org/x/text v0.3.7 // indirect
google.golang.org/appengine v1.6.6 // indirect
google.golang.org/genproto v0.0.0-20200904004341-0bd0a958aa1d // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/genproto v0.0.0-20211208223120-3a66f561d7aa // indirect
google.golang.org/grpc v1.45.0 // indirect
google.golang.org/protobuf v1.27.1 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
Expand Down
Loading