This message was deleted.
# general
b
This message was deleted.
w
šŸ‘‹Hi Antonette, welcome to the chat! I’m Ali, one of the co-founders. Yep, I know what you mean - we ask people to add a comment on any issues they’d like to work on - that way the rest of the community know who else is working on what (we assign the issue in GitHub too), and we can help with it. We’ve iterated on our contributing guide for adding new resources and that’s where we suggest new contributors to start.
m
Thanks @white-airport-8778 I will check it out and see if I can get anything going.
šŸ‘ 1
w
If the new resource issue you’re interested doesn’t have cost component details, add a comment and we can add details
m
Hi @white-airport-8778 I'm interested in doing https://github.com/infracost/infracost/issues/889 I've already forked the infracost project and downloaded the infracost cli as well as registering the API Key. I also cloned the cloud-pricing-api repo and setup the database with PostgreSQL. I'm following the video provided as well as the long tutorial right now.
b
Hello Antonette! šŸ‘‹ Thank you for willing to contribute! Could you please leave a comment on the issue as well, so we can assign it to you? We also need to provide details about cost components the resource should have. We'll add them shortly.
@miniature-megabyte-75526 BTW, how do you find our guides? Is everything clear or maybe something needs more explanation? We'll be happy to get some feedback, so we can improve them šŸ™‚
m
Thank you @busy-agent-35515. So far the guides are spectacular and easy to follow. I will say this, the video mentioned for the demo on how to add a resource, it may needs to be updated to reflect the automatic way of using the infracost cli too to generate the necessary files. If I'm not mistaken, the video shows to create the necessary files manually.
b
Haha, thank you! You're right, this video was recorded before the guide. And video production is hard šŸ˜….
w
maybe we should tweak the doc to mention that the video is from before we added the code generation helper, so contributors know the video itself is still valid but the first part is easier
m
@white-airport-8778 That can work also, whichever works
@busy-agent-35515 Hi there. I started working on the first Sentinel resource - Sentinel Data Connector AWS Cloudtrail, after setting up the basic configuration, I ran into an error message. I'm using the debug to make sure that it goes through correctly and see if anything that was missing.
Here is the snippet of the error message:
Copy code
ARGS="--run TestSentinelDataConnectorAwsCloudTrail -v -update" make test_azure
INFRACOST_LOG_LEVEL=warn go test -timeout 30m -ldflags="-X '<http://github.com/infracost/infracost/internal/version.Version=v0.9.19+53-g898e0213-dirty|github.com/infracost/infracost/internal/version.Version=v0.9.19+53-g898e0213-dirty>'" ./internal/providers/terraform/azure --run TestSentinelDataConnectorAwsCloudTrail -v -update
=== RUN   TestSentinelDataConnectorAwsCloudTrailGoldenFile
=== PAUSE TestSentinelDataConnectorAwsCloudTrailGoldenFile
=== CONT  TestSentinelDataConnectorAwsCloudTrailGoldenFile
=== RUN   TestSentinelDataConnectorAwsCloudTrailGoldenFile/HCL
level=warning msg="Using eastus for resource azurerm_sentinel_data_connector_aws_cloud_trail.sentinel_data_connector_aws_cloud_trail as its 'location' property could not be found."
    testutil.go:201: Unexpected log write.  To capture logs remove t.Parallel and use GoldenFileOptions { CaptureLogs = true }: level=warning msg="Using eastus for resource azurerm_sentinel_data_connector_aws_cloud_trail.sentinel_data_connector_aws_cloud_trail as its 'location' property could not be found."
    testutil.go:177: Wrote golden file testdata/sentinel_data_connector_aws_cloud_trail_test/sentinel_data_connector_aws_cloud_trail_test.golden
=== RUN   TestSentinelDataConnectorAwsCloudTrailGoldenFile/Terraform_CLI
level=warning msg="Using eastus for resource azurerm_sentinel_data_connector_aws_cloud_trail.sentinel_data_connector_aws_cloud_trail as its 'location' property could not be found."
    testutil.go:201: Unexpected log write.  To capture logs remove t.Parallel and use GoldenFileOptions { CaptureLogs = true }: level=warning msg="Using eastus for resource azurerm_sentinel_data_connector_aws_cloud_trail.sentinel_data_connector_aws_cloud_trail as its 'location' property could not be found."
--- FAIL: TestSentinelDataConnectorAwsCloudTrailGoldenFile (10.73s)
    --- FAIL: TestSentinelDataConnectorAwsCloudTrailGoldenFile/HCL (0.14s)
    --- FAIL: TestSentinelDataConnectorAwsCloudTrailGoldenFile/Terraform_CLI (10.59s)
FAIL
FAIL	<http://github.com/infracost/infracost/internal/providers/terraform/azure|github.com/infracost/infracost/internal/providers/terraform/azure>	14.854s
FAIL
make: *** [Makefile:88: test_azure] Error 1
Copy code
provider "azurerm" {
  skip_provider_registration = true
  features {}
}

resource "azurerm_resource_group" "example" {
  name     = "example-resources"
  location = "eastus"
}

# Add example resources for SentinelDataConnectorAwsCloudTrail below

resource "azurerm_log_analytics_workspace" "sentinel_data_connector_aws_cloud_trail" {
  name                = "example-workspace"
  location            = azurerm_resource_group.example.location
  resource_group_name = azurerm_resource_group.example.name
  sku                 = "PerGB2018"
}

resource "azurerm_log_analytics_solution" "sentinel_data_connector_aws_cloud_trail" {
  solution_name         = "exampleinsights"
  location              = azurerm_resource_group.example.location
  resource_group_name   = azurerm_resource_group.example.name
  workspace_resource_id = azurerm_log_analytics_workspace.sentinel_data_connector_aws_cloud_trail.id
  workspace_name        = azurerm_log_analytics_workspace.sentinel_data_connector_aws_cloud_trail.name

  plan {
    publisher = "Microsoft"
    product   = "OMSGallery/SecurityInsights"
  }
}

resource "azurerm_sentinel_data_connector_aws_cloud_trail" "sentinel_data_connector_aws_cloud_trail" {
  name                       = "example"
  log_analytics_workspace_id = azurerm_log_analytics_solution.sentinel_data_connector_aws_cloud_trail.workspace_resource_id
  aws_role_arn               = "arn:aws:iam::000000000000:role/role1"
}
Appreciate all the help!
šŸ‘€ 1
c
So looking at the lookupRegion method for azure, if there’s no
location
field on the resource, it tries to look it up using a reference to the ā€œparent resourceā€ (and throws the warning if it can’t find one). So in this case it looks like the parent resource for
azurerm_sentinel_data_connector_aws_cloud_trail
is referenced through
log_analytics_workspace_id
so try adding
log_analytics_workspace_id
as a
ReferenceAttribute
in the
RegistryItem
, and passing it to
lookupRegion
in
parentResourceKeys
m
I did see the instruction to add
log_analytics_workspace_id
as a
ReferenceAttribute
in the
RegistryItem
but I may have missed something else?
Copy code
func getSentinelDataConnectorAwsCloudTrailRegistryItem() *schema.RegistryItem {
	return &schema.RegistryItem{
		Name:  "azurerm_sentinel_data_connector_aws_cloud_trail",
		RFunc: newSentinelDataConnectorAwsCloudTrail,
		ReferenceAttributes: []string{
			"resource_group_name",
			"log_analytics_workspace_id",
		},
	}
}
c
yeah that looks good, and you’ve got something like
region := lookupRegion(d, []string{"log_analytics_workspace_id"})
too?
m
Ah that might be it, let me add that then. I didn't see the section after that
let me add that then
great it went through
šŸ‘ 1
sorry about that, that was slight oversight on my part, i didn't know to add the rest in the last section
c
no worries. Don’t hesitate to send a pr for the contributing guide if you think it could be clarified.
m
To send a PR, do you prefer to send one by one for each of the resource?
c
Hmm good question. We don’t have a strict rule so follow your ā¤ļø. Usually there’s one pr per issue, but if you see a clear separation maybe multiple PRs would be better. If they are all closely related or the implementation is tightly coupled one PR probably makes sense.
I guess each PR should be ā€œcompleteā€ in that it adds useful functionality, not just a partial implementation.
šŸ‘ 1
m
So I was able to replicate through the rest of the azurerm sentinel resources. So I'm working on the second part regarding
log_analytics_workspace
. Where am I updating the
log_analytics_workspace
? In
infracost-usage-example.yml
? Or within each of the resource
*.usage.yml
file within
terraform/azure/testdata
? From my understanding there is no cost component for the resources.
šŸ‘€ 1
c
Both. You should add the new key
monthly_sentinel_data_ingestion_gb
to the
azurerm_log_analytics_workspace
block in
infracost-usage-example.yml
so that people know it is available (that’s sort of the documentation for usage costs). And you should add it to
terraform/azure/testdata/log_analytics_workspace_test/log_analytics_workspace_test.usage.yml
so there is test coverage. I assume you will need to add a new resource block to
terraform/azure/testdata/log_analytics_workspace_test/log_analytics_workspace_test.tf
with the sentinel enabled.
From my understanding there is no cost component for the resources.
I’m not sure what you mean by this — the task is to add a new
Sentinel data ingestion
cost component to
internal/resources/azure/log_analytics_workspace.go
m
I was following the example in the issue, and the detail mentioned that there is no cost component, so from the tutorial/walkthrough there is a section on how to set up cost component. I only need to reference
log_analytics_workspace_id
to support reverse references.
Unless I misunderstood, and from what you just said, I'm only adding the
Sentinel data ingestion
cost component to
internal/resources/azure/log_analytics_workspace.go
c
Yes, sorry I’m being slow with my response to make sure I understand correctly šŸ™‚
m
it's okay, not a rush. this is a learning process for me so I'm not trying to rush through and send an incomplete PR
c
Yes the cost component is only on
internal/resources/azure/log_analytics_workspace.go
. As far as the tests… I guess it would be best to have a test case for each sentinel_data_connector resource, so a
testdata
dir with a .tf file with
azurerm_log_analytics_workspace
and
azurerm_sentinel_data_connector_...
resource block pairs. And there would be two cases for each connector resource, one with usage and one without.
Does that make sense? That would probably be the best way to prevent anything from getting messed up by mistake, but if that feels like too much I could be convinced putting a few test cases in
log_analytics_workspace_test
is sufficient.
m
That makes sense, let me go and work on a bit more, and I'll return if I have any more questions. Thank you!
šŸ‘ 1
I'm in the process of creating a PR but before I do that I'm following the instruction to use
make lint
and
make fmt
. After doing this, i noticed there are extra test files. Are these needed to be included with the PR?
c
you mean extra files in the
testdata/…
directory? it should just be the
.tf
.golden
and
.usage.yml
files.
m
i pulled in the latest from master, and these are what came up after I ran
make lint
and
make fmt
. Mind you, I didn't run this before I started making changes.
Copy code
Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
	modified:   internal/providers/terraform/aws/testdata/glue_job_test/glue_job_test.tf
	modified:   internal/providers/terraform/aws/testdata/vpc_endpoint_test/vpc_endpoint_test.tf
	modified:   internal/providers/terraform/azure/testdata/container_registry_test/container_registry_test.tf
	modified:   internal/providers/terraform/azure/testdata/frontdoor_test/frontdoor_test.tf
	modified:   internal/providers/terraform/azure/testdata/lb_outbound_rule_test/lb_outbound_rule_test.tf
c
(sorry, fell asleep šŸ™‚) I see what you mean now. You can either ignore those changes or put them into a separate commit with the message
refactor: make fmt; make lint
I guess we need to add check to our build to ensure the code has been formatted and linted.
m
Hi everyone I'm back, I already made the changes on my local branch so I'm rebasing again to make sure that it's up to date, and I'm working on the changes. The one question I have is the azure.log_analytics_workspace file, where I go to add
SentinelEnabled: sentinelEnabled
at the bottom of the file, and I received an error, with this piece of code. I received an error
invalid argument: ref (variable of type int) for lencompilerInvalidLen)
. I'm still learning the Go language, so this error kind of stumped me a little bit. Any suggestions?
Copy code
sentinelEnabled := false
	for ref, _ := range sentinelRefs {
		if len(ref) > 0 {
			sentinelEnabled = true
			break
		}
	}
b
Hey! Welcome back šŸ™‚ From the first sight it seems like the for loop should have
for _, ref
as the first argument is integer index, and second one is the struct.
Coming from Ruby world, I have my own struggles with Go too, it is very different from what I'm used to šŸ˜…
m
Thank you! I have updated my PR to reflect some of the changes I've made on your recommendations. I think there are a couple things that still needs to be changed but I wanted to update my PR. This past two weeks have been a little stressful for me so I apologize for that.
šŸš€ 1
b
Hey! No worries at all šŸ™‚ Hope it's better now. I'll take a look today or tomorrow. Thank you very much for pushing forward šŸ˜„
m
No problem šŸ™‚
šŸ™Œ 1