Skip to content

Commit c4fc83c

Browse files
authored
feat: add azure terraform to stack new (#857)
1 parent ec6cf65 commit c4fc83c

File tree

3 files changed

+64
-8
lines changed

3 files changed

+64
-8
lines changed
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# The provider to use and it's published version
2+
# See releases:
3+
# https://github.com/nitrictech/nitric/tags
4+
provider: nitric/azuretf@{{.Version}}
5+
# The target Azure region to deploy to
6+
# See available regions:
7+
# https://azure.microsoft.com/en-us/explore/global-infrastructure/products-by-region/?products=container-apps
8+
region:
9+
10+
# Org to associate deployed API Management services with
11+
org:
12+
13+
# Subscription ID to associate deployed services with
14+
subscription-id:
15+
16+
# Admin email to associate deployed API Management services with, this can be any email address
17+
adminemail: test@example.com
18+
# Optional configuration below
19+
20+
# # Configure your deployed functions/services
21+
# config:
22+
# # How functions without a type will be deployed
23+
# default:
24+
# # configure a sample rate for telemetry (between 0 and 1) e.g. 0.5 is 50%
25+
# telemetry: 0
26+
# # configure functions to deploy to Google Cloud Run
27+
# # see: https://learn.microsoft.com/en-us/azure/container-apps/containers#configuration
28+
# containerapps: # Available since v0.26.0
29+
# # set 1/4 vCPU
30+
# cpu: 0.25
31+
# # set 0.5GB of RAM
32+
# memory: 0.5
33+
# # The minimum number of instances to scale down to
34+
# min-replicas: 0
35+
# # The maximum number of instances to scale up to
36+
# max-replicas: 10
37+
# # Additional deployment types
38+
# # You can target these types by setting a `type` in your project configuration
39+
# big-service:
40+
# telemetry: 0
41+
# containerapps:
42+
# memory: 1
43+
# min-replicas: 2
44+
# max-replicas: 100

pkg/project/stack/stack.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ var gcpConfigTemplate string
5252
//go:embed gcptf.config.yaml
5353
var gcpTfConfigTemplate string
5454

55+
//go:embed azuretf.config.yaml
56+
var azureTfConfigTemplate string
57+
5558
var fileNameRegex = regexp.MustCompile(`(?i)^nitric\.(\S+)\.ya?ml$`)
5659

5760
func IsValidFileName(stackName string) bool {
@@ -78,6 +81,8 @@ func NewStackFile(fs afero.Fs, providerName string, stackName string, dir string
7881
templateStr = awsTfConfigTemplate
7982
case "gcp-tf":
8083
templateStr = gcpTfConfigTemplate
84+
case "azure-tf":
85+
templateStr = azureTfConfigTemplate
8186
}
8287

8388
// Parse and execute the template with the version injected

pkg/view/tui/commands/stack/new/stack_new.go

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -295,14 +295,15 @@ func stackNameExistsValidator(projectDir string) validation.StringValidator {
295295
}
296296

297297
const (
298-
Aws = "Pulumi AWS"
299-
Azure = "Pulumi Azure"
300-
Gcp = "Pulumi Google Cloud"
301-
AwsTf = "Terraform AWS (Preview)"
302-
GcpTf = "Terraform Google Cloud (Preview)"
298+
Aws = "Pulumi AWS"
299+
Azure = "Pulumi Azure"
300+
Gcp = "Pulumi Google Cloud"
301+
AwsTf = "Terraform AWS (Preview)"
302+
AzureTf = "Terraform Azure (Preview)"
303+
GcpTf = "Terraform Google Cloud (Preview)"
303304
)
304305

305-
var availableProviders = []string{Aws, Gcp, Azure, AwsTf, GcpTf}
306+
var availableProviders = []string{Aws, Gcp, Azure, AwsTf, GcpTf, AzureTf}
306307

307308
func New(fs afero.Fs, args Args) Model {
308309
// Load and update the project name in the template's nitric.yaml
@@ -347,9 +348,13 @@ func New(fs afero.Fs, args Args) Model {
347348
}
348349

349350
if args.ProviderName != "" {
350-
if !lo.Contains([]string{"aws", "azure", "gcp", "aws-tf"}, args.ProviderName) {
351+
validProviders := lo.Map(availableProviders, func(p string, _ int) string {
352+
return providerLabelToValue(p)
353+
})
354+
355+
if !lo.Contains(validProviders, args.ProviderName) {
351356
return Model{
352-
err: fmt.Errorf("cloud name is not valid, must be aws, azure, gcp, or aws-tf"),
357+
err: fmt.Errorf("cloud name is not valid, must be one of: %v", strings.Join(validProviders, ", ")),
353358
}
354359
}
355360

@@ -394,6 +399,8 @@ func providerLabelToValue(provider string) string {
394399
return "aws-tf"
395400
case GcpTf:
396401
return "gcp-tf"
402+
case AzureTf:
403+
return "azure-tf"
397404
}
398405

399406
return strings.ToLower(provider)

0 commit comments

Comments
 (0)