Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cloud IoT module #4

Merged
merged 48 commits into from
Dec 10, 2019
Merged

Cloud IoT module #4

merged 48 commits into from
Dec 10, 2019

Conversation

namusyaka
Copy link
Contributor

@namusyaka namusyaka commented Jun 15, 2019

This is a new Cloud IoT module implementation. Just combining existing the pubsub module with google_cloudiot_registry.
In addition, the module has strongly depended on the features introduced in terraform v0.12.
In order to use the new features, I needed to upgrade a few things such as terraform validate and terraform-docs.

Basically the changes are separated into multiple commits, so please review those based for each commit.
After getting merged, I think we can work on the upgrading main pubsub module to 0.12.

@morgante @aaron-lane

main.tf Outdated
@@ -19,14 +19,15 @@ locals {
}

resource "google_pubsub_topic" "topic" {
count = "${var.topic == "" ? 0 : 1}"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a measure for the IoT side to not be able to call module conditionally.

modules/cloudiot/README.md Outdated Show resolved Hide resolved
@aaron-lane aaron-lane added the enhancement New feature or request label Jun 17, 2019
@Jberlinsky
Copy link

Hi @namusyaka -- thanks for your contribution! It looks like there have been significant changes to this module since you filed this PR; would you mind rebasing your changes on master so we can review this properly?

@namusyaka
Copy link
Contributor Author

Sure, will do

@namusyaka namusyaka self-assigned this Oct 7, 2019
This change is to allow submodule to use pubsub module as optional.
Now the validator behaves as if this were `false`.
See: hashicorp/terraform#21408 (comment)

However, as a result of my investigation, the validator uses the source
module to check whether the syntax is valid and types/values are being
used correctly.

To react with the changes, this commit adds PWD=directory as an
temporary environment variable on the command execution, because validate
command seems to refer to the current directory.
This commit also contains a workaround for an issue that
terraform-docs unsupport 0.12.0.
The workaround avoids the failure of terraform-docs by
passing variables.tf and outputs.tf instead of the directory name.

ref: terraform-docs/terraform-docs#62
@namusyaka
Copy link
Contributor Author

@Jberlinsky Updated. PTAL

@namusyaka
Copy link
Contributor Author

Seems conflicted again.

project_id = var.project_id
topic_name = "ci-int-topic-${random_id.random_suffix.hex}"
topic_name = var.topic_name
Copy link
Contributor Author

@namusyaka namusyaka Dec 6, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the count argument depends on the resource like random_id, the error happens:
The "count" value depends on resource attributes that cannot be determined

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh that's a big issue, I will add a note above.

@morgante morgante assigned morgante and unassigned aaron-lane Dec 6, 2019
Copy link
Contributor

@morgante morgante left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the delayed review!

CONTRIBUTING.md Outdated Show resolved Hide resolved
modules/cloudiot/main.tf Outdated Show resolved Hide resolved
event_notification_configs {
pubsub_topic_name = "projects/${var.project_id}/topics/${module.event_notification_topic.topic}"
}
state_notification_config = {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dynamic block?

Copy link
Contributor Author

@namusyaka namusyaka Dec 9, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think so, this is a map type. IIUC I can't use dynamic for the map type, right?
But I've tried to change these config blocks to be optional: 236d904

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, can you try dynamic? I think it might work.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've already tried it but got an error like: Blocks of type "xxxx" are not expected here.
In fact, i think we're using dynamic only for typeList, i couldn't find the case for typeMap.

If there is any thing I overlooked, let me know.

modules/cloudiot/outputs.tf Show resolved Hide resolved
default = []
}

variable "event_notification_config" {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please include typdef.

Copy link
Contributor Author

@namusyaka namusyaka Dec 9, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done: 236d904

test/fixtures/cloudiot/rsa_cert1.pem Outdated Show resolved Hide resolved
test/fixtures/cloudiot/terraform.tfvars.sample Outdated Show resolved Hide resolved
project_id = var.project_id
topic_name = "ci-int-topic-${random_id.random_suffix.hex}"
topic_name = var.topic_name
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh that's a big issue, I will add a note above.

main.tf Outdated Show resolved Hide resolved
test/setup/iam.tf Show resolved Hide resolved
Copy link
Contributor Author

@namusyaka namusyaka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the review, PTAL again.

CONTRIBUTING.md Outdated Show resolved Hide resolved
test/fixtures/cloudiot/rsa_cert1.pem Outdated Show resolved Hide resolved
modules/cloudiot/outputs.tf Show resolved Hide resolved
modules/cloudiot/main.tf Outdated Show resolved Hide resolved
event_notification_configs {
pubsub_topic_name = "projects/${var.project_id}/topics/${module.event_notification_topic.topic}"
}
state_notification_config = {
Copy link
Contributor Author

@namusyaka namusyaka Dec 9, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think so, this is a map type. IIUC I can't use dynamic for the map type, right?
But I've tried to change these config blocks to be optional: 236d904

default = {}
}

variable "state_notification_config" {
Copy link
Contributor Author

@namusyaka namusyaka Dec 9, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done: 236d904

main.tf Outdated Show resolved Hide resolved
test/fixtures/cloudiot/terraform.tfvars.sample Outdated Show resolved Hide resolved
test/setup/iam.tf Show resolved Hide resolved
test/fixtures/cloudiot/terraform.tfvars.sample Outdated Show resolved Hide resolved
test/fixtures/cloudiot/main.tf Outdated Show resolved Hide resolved
event_notification_configs {
pubsub_topic_name = "projects/${var.project_id}/topics/${module.event_notification_topic.topic}"
}
state_notification_config = {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, can you try dynamic? I think it might work.

Copy link
Contributor

@morgante morgante left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just one suggestion.

@morgante morgante merged commit ac245ed into master Dec 10, 2019
@namusyaka namusyaka deleted the iot branch December 10, 2019 02:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants