Skip to content

Commit d3343f2

Browse files
authored
Merge pull request #33 from mach-composer/feat/update-vercel-plugin-provider-version
feat: make plugin compatible with provider v1.12.0
2 parents b06eb97 + a06c032 commit d3343f2

File tree

7 files changed

+36
-33
lines changed

7 files changed

+36
-33
lines changed

.changes/unreleased/changes.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
### Compatibility
2+
* Vercel provider now requires field deployment_type instead of protect_production.

internal/config.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ func NewVercelConfig() VercelConfig {
1818

1919
ProjectConfig: ProjectConfig{
2020
PasswordProtection: PasswordProtection{
21-
ProtectProduction: true,
21+
DeploymentType: "standard_protection",
2222
},
2323
VercelAuthentication: VercelAuthentication{
24-
ProtectProduction: true,
24+
DeploymentType: "standard_protection",
2525
},
2626
},
2727
}
@@ -130,11 +130,11 @@ func (c *ProjectConfig) extendConfig(o *ProjectConfig) *ProjectConfig {
130130
cfg.ProtectionBypassForAutomation = c.ProtectionBypassForAutomation
131131
}
132132

133-
if !c.VercelAuthentication.ProtectProduction {
134-
cfg.VercelAuthentication.ProtectProduction = c.VercelAuthentication.ProtectProduction
133+
if c.VercelAuthentication.DeploymentType != "" {
134+
cfg.VercelAuthentication.DeploymentType = c.VercelAuthentication.DeploymentType
135135
}
136136

137-
if c.PasswordProtection.Password != "" || !c.PasswordProtection.ProtectProduction {
137+
if c.PasswordProtection.Password != "" {
138138
cfg.PasswordProtection = c.PasswordProtection
139139
}
140140

@@ -189,12 +189,12 @@ func (c *GitRepository) extendConfig(o *GitRepository) *GitRepository {
189189
}
190190

191191
type PasswordProtection struct {
192-
Password string `mapstructure:"password"`
193-
ProtectProduction bool `mapstructure:"protect_production"`
192+
Password string `mapstructure:"password"`
193+
DeploymentType string `mapstructure:"deployment_type"`
194194
}
195195

196196
type VercelAuthentication struct {
197-
ProtectProduction bool `mapstructure:"protect_production"`
197+
DeploymentType string `mapstructure:"deployment_type"`
198198
}
199199

200200
type ProjectEnvironmentVariable struct {

internal/plugin.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ type VercelPlugin struct {
2020

2121
func NewVercelPlugin() schema.MachComposerPlugin {
2222
state := &VercelPlugin{
23-
provider: "0.15.1", // Provider version of `vercel/vercel`
23+
provider: "1.12.0", // Provider version of `vercel/vercel`
2424
siteConfigs: map[string]*VercelConfig{},
2525
}
2626
return plugin.NewPlugin(&schema.PluginSchema{
@@ -188,11 +188,11 @@ func (p *VercelPlugin) RenderTerraformComponent(site string, component string) (
188188
{{ renderProperty "vercel_project_manual_production_deployment" .ProjectConfig.ManualProductionDeployment }}
189189
{{ renderProperty "vercel_project_protection_bypass_for_automation" .ProjectConfig.ProtectionBypassForAutomation }}
190190
vercel_project_vercel_authentication = {
191-
{{ renderProperty "protect_production" .ProjectConfig.VercelAuthentication.ProtectProduction }}
191+
{{ renderProperty "deployment_type" .ProjectConfig.VercelAuthentication.DeploymentType }}
192192
}
193193
vercel_project_password_protection = {
194194
{{ renderProperty "password" .ProjectConfig.PasswordProtection.Password }}
195-
{{ renderProperty "protect_production" .ProjectConfig.PasswordProtection.ProtectProduction }}
195+
{{ renderProperty "deployment_type" .ProjectConfig.PasswordProtection.DeploymentType }}
196196
}
197197
vercel_project_git_repository = {
198198
{{ renderProperty "production_branch" .ProjectConfig.GitRepository.ProductionBranch }}

internal/plugin_test.go

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,11 @@ func TestSetVercelConfig(t *testing.T) {
5252
"domains": domains,
5353
"protection_bypass_for_automation": true,
5454
"vercel_authentication": map[string]any{
55-
"protect_production": true,
55+
"deployment_type": "only_preview_deployments",
5656
},
5757
"password_protection": map[string]any{
58-
"password": "MyPassword",
59-
"protect_production": true,
58+
"password": "MyPassword",
59+
"deployment_type": "only_preview_deployments",
6060
},
6161
},
6262
}
@@ -89,7 +89,7 @@ func TestSetVercelConfig(t *testing.T) {
8989
assert.Contains(t, component.Variables, "type = \"github\"")
9090
assert.Contains(t, component.Variables, "repo = \"mach-composer/my-project\"")
9191
assert.Contains(t, component.Variables, "protection_bypass_for_automation = true")
92-
assert.Contains(t, component.Variables, "protect_production = true")
92+
assert.Contains(t, component.Variables, "deployment_type = \"only_preview_deployments\"")
9393
assert.Contains(t, component.Variables, "password = \"MyPassword\"")
9494

9595
// Test environment variables
@@ -121,11 +121,11 @@ func TestInheritance(t *testing.T) {
121121
"manual_production_deployment": true,
122122
"protection_bypass_for_automation": true,
123123
"vercel_authentication": map[string]any{
124-
"protect_production": true,
124+
"deployment_type": "standard_protection",
125125
},
126126
"password_protection": map[string]any{
127-
"password": "MyPassword",
128-
"protect_production": true,
127+
"password": "MyPassword",
128+
"deployment_type": "standard_protection",
129129
},
130130
"environment_variables": globalVariables,
131131
},
@@ -145,10 +145,11 @@ func TestInheritance(t *testing.T) {
145145
"api_token": "test-token-override",
146146
"project_config": map[string]any{
147147
"vercel_authentication": map[string]any{
148-
"protect_production": false,
148+
"deployment_type": "standard_protection",
149149
},
150150
"password_protection": map[string]any{
151-
"protect_production": false,
151+
"password": "MyPassword",
152+
"deployment_type": "standard_protection",
152153
},
153154
"environment_variables": siteVariables,
154155
},
@@ -175,7 +176,7 @@ func TestInheritance(t *testing.T) {
175176
// Test whether environment variables get extended
176177
assert.Contains(t, component.Variables, "environment = [\"development\", \"preview\", \"production\"]")
177178
assert.Contains(t, component.Variables, "environment = [\"production\", \"preview\"]")
178-
assert.Contains(t, component.Variables, "protect_production = false")
179+
assert.Contains(t, component.Variables, "deployment_type = \"standard_protection\"")
179180

180181
assert.Contains(t, component.Variables, "environment")
181182
}

internal/schemas/component-config.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,8 @@
9595
"vercel_authentication": {
9696
"type": "object",
9797
"properties": {
98-
"protect_production": {
99-
"type": "boolean"
98+
"deployment_type": {
99+
"enum": ["standard_protection", "all_deployments", "only_production_deployments", "only_preview_deployments"]
100100
}
101101
}
102102
},
@@ -106,8 +106,8 @@
106106
"password": {
107107
"type": "string"
108108
},
109-
"protect_production": {
110-
"type": "boolean"
109+
"deployment_type": {
110+
"enum": ["standard_protection", "all_deployments", "only_production_deployments", "only_preview_deployments"]
111111
}
112112
}
113113
}

internal/schemas/global-config.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,8 @@
9595
"vercel_authentication": {
9696
"type": "object",
9797
"properties": {
98-
"protect_production": {
99-
"type": "boolean"
98+
"deployment_type": {
99+
"enum": ["standard_protection", "all_deployments", "only_production_deployments", "only_preview_deployments"]
100100
}
101101
}
102102
},
@@ -106,8 +106,8 @@
106106
"password": {
107107
"type": "string"
108108
},
109-
"protect_production": {
110-
"type": "boolean"
109+
"deployment_type": {
110+
"enum": ["standard_protection", "all_deployments", "only_production_deployments", "only_preview_deployments"]
111111
}
112112
}
113113
}

internal/schemas/site-config.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,8 @@
9494
"vercel_authentication": {
9595
"type": "object",
9696
"properties": {
97-
"protect_production": {
98-
"type": "boolean"
97+
"deployment_type": {
98+
"enum": ["standard_protection", "all_deployments", "only_production_deployments", "only_preview_deployments"]
9999
}
100100
}
101101
},
@@ -105,8 +105,8 @@
105105
"password": {
106106
"type": "string"
107107
},
108-
"protect_production": {
109-
"type": "boolean"
108+
"deployment_type": {
109+
"enum": ["standard_protection", "all_deployments", "only_production_deployments", "only_preview_deployments"]
110110
}
111111
}
112112
}

0 commit comments

Comments
 (0)