Mukul
Mukul

Reputation: 371

unable to import azurerm provider to cdktf using golang

I am currently trying to figure out how to import azurerm provider to my golang code, I am new to golang and trying to use CDKTF to create infrastructure in Azure, My code looks like this where a simple RG is getting created.


import (
    "github.com/aws/constructs-go/constructs/v10"
    jsii "github.com/aws/jsii-runtime-go"
    "github.com/hashicorp/terraform-cdk-go/cdktf"
)

func NewMyStack(scope constructs.Construct, id string) cdktf.TerraformStack {
    stack := cdktf.NewTerraformStack(scope, &id)

    //Initialise the provider
    azurerm.NewAzurermProvider(stack, jsii.String("azurerm"), &azurerm.AzurermProviderConfig{
        Features: &azurerm.AzurermProviderFeatures{},
        //Subscription:    jsii.String(""), //Just for an example, login credential is coming from ARM* environment variables
    })
    //Create a resource group
    rg := azurerm.NewResourceGroup(stack, jsii.String("test_rg"), &azurerm.ResourceGroupConfig{
        //Name:     n.ResourceGroupOutput(), //GOTO 26
        Name:     jsii.String("test-rg"),
        Location: jsii.String("westeurope"),
    })

    //Output stuff
    cdktf.NewTerraformOutput(stack, jsii.String("names"), &cdktf.TerraformOutputConfig{
        Value: &[]*string{rg.Name()},
    })

    return stack
}

func main() {
    app := cdktf.NewApp(nil)

    NewMyStack(app, "cdktf-azure-go")

    app.Synth()
}

When this runs, it ends up in error

Command output on stderr:

    # command-line-arguments
    ./main.go:15:2: undefined: azurerm
    ./main.go:16:14: undefined: azurerm
    ./main.go:20:8: undefined: azurerm

using go version go1.19.13

Upvotes: 1

Views: 50

Answers (0)

Related Questions