Skip to content

Commit 416da3c

Browse files
authored
doc: improve migration guide to v2 with a migration example (#715)
1 parent 07a3ce3 commit 416da3c

File tree

3 files changed

+153
-75
lines changed

3 files changed

+153
-75
lines changed

README.md

+8-15
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,18 @@
1-
Scaleway Terraform Provider
2-
==================
1+
# Scaleway Terraform Provider
32

43
- [Provider Documentation Website](https://www.terraform.io/docs/providers/scaleway/index.html)
54
- [![Gitter chat](https://badges.gitter.im/hashicorp-terraform/Lobby.png)](https://gitter.im/hashicorp-terraform/Lobby)
65
- Mailing list: [Google Groups](http://groups.google.com/group/terraform-tool)
6+
- Slack: [Scaleway-community Slack (#terraform)](https://app.slack.com/client/T7YEXCR7X/C015RD31DNK)
77

88
<img src="https://cdn.rawgit.com/hashicorp/terraform-website/master/content/source/assets/images/logo-hashicorp.svg" width="600px">
99

10-
### Version 2 In Progress
11-
12-
We are actively working on the version 2. You can follow the progess [here](https://github.com/scaleway/terraform-provider-scaleway/issues/125).
13-
14-
Requirements
15-
------------
10+
## Requirements
1611

1712
- [Terraform](https://www.terraform.io/downloads.html) 0.10.x
1813
- [Go](https://golang.org/doc/install) 1.11 (to build the provider plugin)
1914

20-
Building The Provider
21-
---------------------
15+
## Building The Provider
2216

2317
Clone repository to: `$GOPATH/src/github.com/scaleway/terraform-provider-scaleway`
2418

@@ -34,12 +28,11 @@ $ cd $GOPATH/src/github.com/scaleway/terraform-provider-scaleway
3428
$ make build
3529
```
3630

37-
Using the provider
38-
----------------------
39-
## Fill in for each provider
31+
## Using the provider
32+
33+
See the [Scaleway Provider Documentation](https://registry.terraform.io/providers/scaleway/scaleway/latest/docs) to get started using the Scaleway provider.
4034

41-
Developing the Provider
42-
---------------------------
35+
## Developing the Provider
4336

4437
If you wish to work on the provider, you'll first need [Go](http://www.golang.org) installed on your machine (version 1.13+ is *required*). You'll also need to correctly setup a [GOPATH](http://golang.org/doc/code.html#GOPATH), as well as adding `$GOPATH/bin` to your `$PATH`.
4538

docs/guides/migration_guide_v2.md

+105-13
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@ description: |-
44
Migrating your Scaleway provider from v1 to v2.
55
---
66

7-
# Migrating from v1 to v2
8-
9-
-> **Note:** The version 2 is not released yet but versions `v1.11+` allow you to do a smooth migration to the `v2`. In other words, there will be no breaking change between `v1.11+` and `v2`. The `v2` roadmap is available [here](https://github.com/scaleway/terraform-provider-scaleway/issues/125).
7+
# Migrating from Scaleway provider v1 to v2
108

119
This page guides you through the process of migrating your version 1 resources to their version 2 equivalent.
1210
To prepare the launch of all new Scaleway products, we completely changed the naming of all resources (as well as their attributes) in version 2 of the Terraform provider.
@@ -15,9 +13,10 @@ To prepare the launch of all new Scaleway products, we completely changed the na
1513

1614
### Version configuration
1715

18-
-> **Note:** Before upgrading to `v2+`, it is recommended to upgrade to the most recent `1.X` version of the provider (`v1.11.0`) and ensure that your environment successfully runs [`terraform plan`](https://www.terraform.io/docs/commands/plan.html) without unexpected change or deprecation notice.
16+
-> **Note:** Before upgrading to `v2+`, it is recommended to upgrade to the most recent `1.X` version of the provider (`v1.17.2`) and ensure that your environment successfully runs [`terraform plan`](https://www.terraform.io/docs/commands/plan.html) without unexpected change or deprecation notice.
1917

20-
It is recommended to use [version constraints when configuring Terraform providers](https://www.terraform.io/docs/configuration/providers.html#version-provider-versions). If you are following these recommendation, update the version constraints in your Terraform configuration and run [`terraform init`](https://www.terraform.io/docs/commands/init.html) to download the new version.
18+
It is recommended to use [version constraints when configuring Terraform providers](https://www.terraform.io/docs/configuration/providers.html#version-provider-versions).
19+
If you are following these recommendations, update the version constraints in your Terraform configuration and run [`terraform init`](https://www.terraform.io/docs/commands/init.html) to download the new version.
2120

2221
Update to latest `1.X` version:
2322

@@ -51,7 +50,8 @@ Below you find an overview of changes in the provider config:
5150
| `token` | `secret_key` |
5251
| `organization` | `organization_id` |
5352

54-
~> **Important:** `access_key` should now only be used for your access key (e.g. `SCWZFD9BPQ4TZ14SM1YS`). Your secret key (previously known as _token_) must be set in `secret_key` (`xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx`).
53+
~> **Important:** `access_key` should now only be used for your access key (e.g. `SCWZFD9BPQ4TZ14SM1YS`).
54+
Your secret key (previously known as _token_) must be set in `secret_key` (`xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx`).
5555

5656
Below you find an overview of the changes in environment variables:
5757

@@ -66,11 +66,98 @@ Below you find an overview of the changes in environment variables:
6666
| `SCW_REGION` | `SCW_DEFAULT_REGION` |
6767
| `SCW_TOKEN` | `SCW_SECRET_KEY` |
6868

69-
~> **Important:** `SCALEWAY_ACCESS_KEY` was changed to `SCW_ACCESS_KEY`. This should be your access key (e.g. `SCWZFD9BPQ4TZ14SM1YS`). Your secret key (previously known as _token_) must be set in `SCW_SECRET_KEY` (`xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx`).
69+
~> **Important:** `SCALEWAY_ACCESS_KEY` was changed to `SCW_ACCESS_KEY`.
70+
This should be your access key (e.g. `SCWZFD9BPQ4TZ14SM1YS`).
71+
Your secret key (previously known as _token_) must be set in `SCW_SECRET_KEY` (`xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx`).
72+
73+
Terraform can also read standard [Scaleway configuration files](https://github.com/scaleway/scaleway-sdk-go/blob/master/scw/README.md).
74+
By doing so, you can use the same configuration between different tools such as the [CLI](https://github.com/scaleway/scaleway-cli) or [Packer](https://www.packer.io/docs/builders/scaleway).
75+
76+
#### Resolution order
77+
78+
Here is the priority list for credentials sources from top to bottom:
79+
80+
1. Environment variables
81+
1. Provider settings
82+
1. [Scaleway configuration files](https://github.com/scaleway/scaleway-sdk-go/blob/master/scw/README.md)
7083

7184
## Resources
7285

73-
All resources are from now on prefixed by `scaleway`, their product category and their product name (`scaleway_{product-category-name}_{product-name}_{resource-name}`). For instances an S3 bucket belongs to the `Storage` product category and is a resource of the `Object` product. Hence it is named: `scaleway_object_bucket`.
86+
All resources are from now on prefixed by `scaleway` and their product name (`scaleway_{product-name}_{resource-name}`).
87+
For instances an S3 bucket belongs to the `object` product and is a resource of type `bucket`.
88+
Hence it is named: `scaleway_object_bucket`.
89+
90+
### Migration guide for renamed resources
91+
92+
Because the resources changed their name, we cannot use automatic state migration.
93+
We will first get the identifier of the resource, then remove the resource from the terraform state and then use [`terraform import`](https://www.terraform.io/docs/import/usage.html) to import existing resources to a renamed resource.
94+
95+
For instance, let's suppose that you have resource in `fr-par-1` such as:
96+
97+
```hcl-terraform
98+
provider "scaleway" {
99+
zone= "fr-par-1"
100+
}
101+
102+
resource scaleway_server main {
103+
name = "foobar"
104+
type = "DEV1-S"
105+
image = "cf44b8f5-77e2-42ed-8f1e-09ed5bb028fc"
106+
}
107+
```
108+
109+
First, let's get the identifier of this resource and put it in a variable.
110+
You can do it using the [`terraform state`](https://www.terraform.io/docs/commands/state/index.html) command.
111+
112+
```text
113+
$ terraform state show scaleway_server.main
114+
# scaleway_server.main:
115+
resource "scaleway_server" "main" {
116+
boot_type = "local"
117+
enable_ipv6 = false
118+
id = "11111111-1111-1111-1111-111111111111"
119+
image = "cf44b8f5-77e2-42ed-8f1e-09ed5bb028fc"
120+
name = "foobar"
121+
private_ip = "10.68.74.121"
122+
state = "running"
123+
state_detail = "booting kernel"
124+
type = "DEV1-S"
125+
}
126+
```
127+
128+
So in that case, the id is "11111111-1111-1111-1111-111111111111".
129+
Now that we got the id, let's delete the resource from your terraform state.
130+
You can do it using: `terraform state rm scaleway_server.main`.
131+
132+
Once this is done, refactor your terraform code to:
133+
134+
```hcl-terraform
135+
provider "scaleway" {
136+
zone= "fr-par-1"
137+
}
138+
139+
resource scaleway_instance_server main {
140+
name = "foobar"
141+
type = "DEV1-S"
142+
image = "cf44b8f5-77e2-42ed-8f1e-09ed5bb028fc"
143+
}
144+
```
145+
146+
We are now ready to import the new resource!
147+
Run `terraform import scaleway_instance_server.main fr-par-1/11111111-1111-1111-1111-111111111111` where `11111111-1111-1111-1111-111111111111` is the id of your resource.
148+
After importing, you can verify using `terraform apply` that you are in a desired state and that no changes need to be done.
149+
150+
You can automate this using scripting:
151+
152+
```shell
153+
#!/usr/bin/env bash
154+
155+
OLD_RESOURCE_NAME="scaleway_server.main"
156+
NEW_RESOURCE_NAME="scaleway_instance_server.main"
157+
ID=$(terraform state show $OLD_RESOURCE_NAME | grep "id" | cut -d\= -f 2 | sed 's/"//g' | awk '{$1=$1};1')
158+
terraform state rm $OLD_RESOURCE_NAME
159+
terraform import $NEW_RESOURCE_NAME $ID
160+
```
74161

75162
### Instance
76163

@@ -81,7 +168,8 @@ This means that all old instance resources are now prefixed with `scaleway_insta
81168

82169
`scaleway_server` was renamed to `scaleway_instance_server`.
83170

84-
In version 1, attachments of volumes where done on the volume resource. But from now on, this is done on the `scaleway_instance_server` resource.
171+
In version 1, attachments of volumes where done on the volume resource.
172+
From now on, this is done on the `scaleway_instance_server` resource.
85173

86174
Thus, to create a server with a volume attached:
87175

@@ -118,12 +206,14 @@ resource "scaleway_instance_ip" "test_ip" {
118206
`scaleway_volume` was renamed to `scaleway_instance_volume`.
119207
The former attributes can still be used on the new volume resource.
120208

121-
Additionally, from now on, you can also create new volumes based on other volumes or snapshots. For more information check the [new volume `scaleway_instance_volume` resource](../resources/instance_volume.md).
209+
Additionally, from now on, you can also create new volumes based on other volumes or snapshots.
210+
For more information check the [new volume `scaleway_instance_volume` resource](../resources/instance_volume.md).
122211

123212
#### Renamed: `scaleway_ssh_key` -> `scaleway_account_ssk_key`
124213

125214
`scaleway_ssh_key` was renamed to `scaleway_account_ssk_key`
126-
The `key` attribute has been renamed to `public_key`. A `name` required attribute and an `organization_id` optional attribute have been added.
215+
The `key` attribute has been renamed to `public_key`.
216+
A `name` required attribute and an `organization_id` optional attribute have been added.
127217

128218
#### Removed: `scaleway_user_data`
129219

@@ -143,12 +233,14 @@ Tokens should be created in the console.
143233

144234
The `scaleway_volume_attachment` was removed in version 2.
145235

146-
Volumes can in version 2 only be attached on the server resource. The [above example](#scaleway_server-gt-scaleway_instance_server) shows how this works.
236+
Volumes can in version 2 only be attached on the server resource.
237+
The [above example](#scaleway_server-gt-scaleway_instance_server) shows how this works.
147238

148239
### Storage
149240

150241
#### Renamed: `scaleway_bucket` -> `scaleway_object_bucket`
151242

152243
The `scaleway_bucket` was moved to the `object` product in the `storage` product category.
153244

154-
It's behaviour remained the same, but we also added an [`acl` attribute](../resources/object_bucket.md#acl). This attribute takes canned ACLs.
245+
It's behaviour remained the same, but we also added an [`acl` attribute](../resources/object_bucket.md#acl).
246+
This attribute takes canned ACLs.

docs/index.md

+40-47
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ terraform {
3030

3131
## Example
3232

33-
Here is an example that will setup a web server with an additional volume, a public IP and a security group.
33+
Here is an example that will set up a web server with an additional volume, a public IP and a security group.
3434

3535
You can test this config by creating a `test.tf` and run terraform commands from this directory:
3636

@@ -40,11 +40,16 @@ You can test this config by creating a `test.tf` and run terraform commands from
4040
- Build the infrastructure: `terraform apply`
4141

4242
```hcl
43+
terraform {
44+
required_providers {
45+
scaleway = {
46+
source = "scaleway/scaleway"
47+
}
48+
}
49+
required_version = ">= 0.13"
50+
}
51+
4352
provider "scaleway" {
44-
access_key = "<SCALEWAY-ACCESS-KEY>"
45-
secret_key = "<SCALEWAY-SECRET-KEY>"
46-
organization_id = "<SCALEWAY-ORGANIZATION-ID>"
47-
project_id = "<SCALEWAY-PROJECT-ID>"
4853
zone = "fr-par-1"
4954
region = "fr-par"
5055
}
@@ -104,26 +109,12 @@ need to create a new one in the section "API Tokens" of the
104109
[Scaleway console](https://console.scaleway.com/account/credentials).
105110
Click on the "Generate new token" button to create them. Giving it a friendly-name is recommended.
106111

107-
The Scaleway provider offers three ways of providing these credentials. The following methods are supported, in this priority order:
112+
The Scaleway provider offers three ways of providing these credentials.
113+
The following methods are supported, in this priority order:
108114

115+
1. [Environment variables](#environment-variables)
109116
1. [Static credentials](#static-credentials)
110-
2. [Environment variables](#environment-variables)
111-
3. [Shared configuration file](#shared-configuration-file)
112-
113-
### Static credentials
114-
115-
!> **Warning**: Hard-coding credentials into any Terraform configuration is not recommended, and risks secret leakage should this file ever be committed to a public version control system.
116-
117-
Static credentials can be provided by adding `access_key` and `secret_key` attributes in-line in the Scaleway provider block:
118-
119-
Example:
120-
121-
```hcl
122-
provider "scaleway" {
123-
access_key = "my-access-key"
124-
secret_key = "my-secret-key"
125-
}
126-
```
117+
1. [Shared configuration file](#shared-configuration-file)
127118

128119
### Environment variables
129120

@@ -143,6 +134,21 @@ $ export SCW_SECRET_KEY="my-secret-key"
143134
$ terraform plan
144135
```
145136

137+
### Static credentials
138+
139+
!> **Warning**: Hard-coding credentials into any Terraform configuration is not recommended, and risks secret leakage should this file ever be committed to a public version control system.
140+
141+
Static credentials can be provided by adding `access_key` and `secret_key` attributes in-line in the Scaleway provider block:
142+
143+
Example:
144+
145+
```hcl
146+
provider "scaleway" {
147+
access_key = "my-access-key"
148+
secret_key = "my-secret-key"
149+
}
150+
```
151+
146152
### Shared configuration file
147153

148154
It is a YAML configuration file shared between the majority of the
@@ -157,30 +163,16 @@ You can find more information about this configuration [in the documentation](ht
157163

158164
In addition to [generic provider arguments](https://www.terraform.io/docs/configuration/providers.html) (e.g. `alias` and `version`), the following arguments are supported in the Scaleway provider block:
159165

160-
- `access_key` - (Optional) The Scaleway access key. It must be provided, but it can also be sourced from
161-
the `SCW_ACCESS_KEY` [environment variable](#environment-variables), or via a [shared configuration file](#shared-configuration-file),
162-
in this priority order.
163-
164-
- `secret_key` - (Optional) The Scaleway secert key. It must be provided, but it can also be sourced from
165-
the `SCW_SECRET_KEY` [environment variable](#environment-variables), or via a [shared configuration file](#shared-configuration-file),
166-
in this priority order.
167-
168-
- `organization_id` - (Optional) The organization ID that will be used as default value for all resources. It can also be sourced from
169-
the `SCW_DEFAULT_ORGANIZATION_ID` [environment variable](https://github.com/scaleway/scaleway-sdk-go/blob/master/scw/README.md#environment-variables), or via a [shared configuration file](https://github.com/scaleway/scaleway-sdk-go/blob/master/scw/README.md#scaleway-config),
170-
in this priority order.
171-
172-
- `project_id` - (Optional) The project ID that will be used as default value for all resources.
173-
It can also be sourced from the `SCW_DEFAULT_PROJECT_ID` [environment variable](https://github.com/scaleway/scaleway-sdk-go/blob/master/scw/README.md#environment-variables), or via a [shared configuration file](https://github.com/scaleway/scaleway-sdk-go/blob/master/scw/README.md#scaleway-config), in this priority order.
174-
175-
- `region` - (Optional) The [region](./guides/regions_and_zones.md#regions) that will be used as default value for all resources. It can also be sourced from
176-
the `SCW_DEFAULT_REGION` [environment variable](https://github.com/scaleway/scaleway-sdk-go/blob/master/scw/README.md#environment-variables), or via a [shared configuration file](https://github.com/scaleway/scaleway-sdk-go/blob/master/scw/README.md#scaleway-config),
177-
in this priority order.
178-
179-
- `zone` - (Optional) The [zone](./guides/regions_and_zones.md#zones) that will be used as default value for all resources. It can also be sourced from
180-
the `SCW_DEFAULT_ZONE` [environment variable](https://github.com/scaleway/scaleway-sdk-go/blob/master/scw/README.md#environment-variables), or via a [shared configuration file](https://github.com/scaleway/scaleway-sdk-go/blob/master/scw/README.md#scaleway-config),
181-
in this priority order.
166+
| Provider Argument | [Environment Variables](#environment-variables) | Description | Mandatory |
167+
|-------------------|-------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------|-----------|
168+
| `access_key` | `SCW_ACCESS_KEY` | [Scaleway access key](https://console.scaleway.com/project/credentials) ||
169+
| `secret_key` | `SCW_SECRET_KEY` | [Scaleway secret key](https://console.scaleway.com/project/credentials) ||
170+
| `organization_id` | `SCW_DEFAULT_ORGANIZATION_ID` | The [organization ID](https://console.scaleway.com/account/organization/profile) that will be used as default value for all resources. | |
171+
| `project_id` | `SCW_DEFAULT_PROJECT_ID` | The [project ID](https://console.scaleway.com/project/settings) that will be used as default value for all resources. | |
172+
| `region` | `SCW_DEFAULT_REGION` | The [region](./guides/regions_and_zones.md#regions) that will be used as default value for all resources. | |
173+
| `zone` | `SCW_DEFAULT_ZONE` | The [zone](./guides/regions_and_zones.md#zones) that will be used as default value for all resources. | |
182174

183-
## Scaleway S3-compatible
175+
## Store terraform state on Scaleway S3-compatible object storage
184176

185177
[Scaleway object storage](https://www.scaleway.com/en/object-storage/) can be used to store your Terraform state.
186178
Configure your backend as:
@@ -203,7 +195,8 @@ terraform {
203195
Beware as no locking mechanism are yet supported.
204196
Using scaleway object storage as terraform backend is not suitable if you work in a team with a risk of simultaneous access to the same plan.
205197

206-
Note: For security reason it's not recommended to store secrets in terraform files. If you want to configure the backend with environment var, you need to use `AWS_ACCESS_KEY_ID` and `AWS_SECRET_ACCESS_KEY` [source](https://www.terraform.io/docs/backends/types/s3.html#access_key).
198+
Note: For security reason it's not recommended to store secrets in terraform files.
199+
If you want to configure the backend with environment var, you need to use `AWS_ACCESS_KEY_ID` and `AWS_SECRET_ACCESS_KEY` [source](https://www.terraform.io/docs/backends/types/s3.html#access_key).
207200

208201
```bash
209202
export AWS_ACCESS_KEY_ID=$SCW_ACCESS_KEY

0 commit comments

Comments
 (0)