in hcl/parse.go [308:436]
func ParseAzureProvider(f hcl.File) (*[]AzureProvider, []error) {
content, _, diags := f.Body.PartialContent(&ProviderBlockSchema)
if diags.HasErrors() {
logrus.Error(diags)
}
results := make([]AzureProvider, 0)
for _, block := range content.Blocks {
if block.Type == "provider" && len(block.Labels) > 0 && (block.Labels[0] == "azapi" || block.Labels[0] == "azurerm") {
attrs, diags := block.Body.JustAttributes()
if diags.HasErrors() {
diags := skipJustAttributesDiags(diags)
if diags.HasErrors() {
return nil, diags.Errs()
}
}
p := AzureProvider{
Type: block.Labels[0],
FileName: block.DefRange.Filename,
LineNumber: block.DefRange.Start.Line,
}
if raw, ok := attrs["alias"]; ok {
v, errs := mockExpression(raw.Expr)
if errs != nil {
return nil, errs
}
p.Alias = v.AsString()
}
if raw, ok := attrs["subscription_id"]; ok {
v, errs := mockExpression(raw.Expr)
if errs != nil {
return nil, errs
}
p.SubscriptionId = v.AsString()
}
if raw, ok := attrs["tenant_id"]; ok {
v, errs := mockExpression(raw.Expr)
if errs != nil {
return nil, errs
}
p.TenantId = v.AsString()
}
if raw, ok := attrs["auxiliary_tenant_ids"]; ok {
v, errs := mockExpression(raw.Expr)
if errs != nil {
return nil, errs
}
// mocked variable is string type, but this field could be list or string
if v.Type().IsPrimitiveType() {
p.AuxiliaryTenantIdsString = v.AsString()
}
if v.CanIterateElements() {
slice := v.AsValueSlice()
for _, v := range slice {
p.AuxiliaryTenantIds = append(p.AuxiliaryTenantIds, v.AsString())
}
}
}
if raw, ok := attrs["client_id"]; ok {
v, errs := mockExpression(raw.Expr)
if errs != nil {
return nil, errs
}
p.ClientId = v.AsString()
}
if raw, ok := attrs["client_certificate"]; ok {
v, errs := mockExpression(raw.Expr)
if errs != nil {
return nil, errs
}
p.ClientCertificate = v.AsString()
}
if raw, ok := attrs["client_certificate_password"]; ok {
v, errs := mockExpression(raw.Expr)
if errs != nil {
return nil, errs
}
p.ClientCertificatePassword = v.AsString()
}
if raw, ok := attrs["client_secret"]; ok {
v, errs := mockExpression(raw.Expr)
if errs != nil {
return nil, errs
}
p.ClientSecret = v.AsString()
}
if raw, ok := attrs["oidc_request_token"]; ok {
v, errs := mockExpression(raw.Expr)
if errs != nil {
return nil, errs
}
p.OidcRequestToken = v.AsString()
}
if raw, ok := attrs["oidc_token"]; ok {
v, errs := mockExpression(raw.Expr)
if errs != nil {
return nil, errs
}
p.OidcToken = v.AsString()
}
results = append(results, p)
}
}
return &results, nil
}