Replace github.com/stoggi/aws-oidc with git.narnian.us/lordwelch/aws-oidc Update import paths to git.narnian.us/lordwelch/sshrimp Remove unnecessary logging This reverts commit 2ae68a7e316f6f692a4773ba4d2702bf144d5155.
58 lines
1.4 KiB
Go
58 lines
1.4 KiB
Go
package ca
|
|
|
|
import (
|
|
"encoding/json"
|
|
"strconv"
|
|
|
|
"git.narnian.us/lordwelch/sshrimp/internal/config"
|
|
)
|
|
|
|
// Provider describes an AWS provider
|
|
type Provider struct {
|
|
Version string `json:"version"`
|
|
Alias string `json:"alias"`
|
|
Region string `json:"region"`
|
|
AllowedAccountIDs []string `json:"allowed_account_ids"`
|
|
}
|
|
|
|
// Module describes a terraform module
|
|
type Module struct {
|
|
Source string `json:"source"`
|
|
Providers map[string]string `json:"providers"`
|
|
}
|
|
|
|
// TerraformOutput represents the main.tf.json struct
|
|
type TerraformOutput struct {
|
|
Provider map[string][]Provider `json:"provider"`
|
|
Module map[string]Module `json:"module"`
|
|
}
|
|
|
|
func generateTerraform(c *config.SSHrimp) ([]byte, error) {
|
|
|
|
providers := make([]Provider, len(c.CertificateAuthority.Regions))
|
|
modules := make(map[string]Module, len(c.CertificateAuthority.Regions))
|
|
for index, region := range c.CertificateAuthority.Regions {
|
|
providers[index].Version = "~> 2.49"
|
|
providers[index].Alias = region
|
|
providers[index].Region = region
|
|
providers[index].AllowedAccountIDs = []string{
|
|
strconv.Itoa(c.CertificateAuthority.AccountID),
|
|
}
|
|
modules["sshrimp-"+region] = Module{
|
|
Source: "./terraform",
|
|
Providers: map[string]string{
|
|
"aws": "aws." + region,
|
|
},
|
|
}
|
|
}
|
|
|
|
output := TerraformOutput{
|
|
Provider: map[string][]Provider{
|
|
"aws": providers,
|
|
},
|
|
Module: modules,
|
|
}
|
|
|
|
return json.MarshalIndent(output, "", " ")
|
|
}
|