canonical / solutions-engineering-automation

Repo for automating tasks for Solutions Engineering Team.
0 stars 4 forks source link

fix(terraform): create pr only if workflow files content is different #19

Closed jneo8 closed 3 months ago

jneo8 commented 3 months ago
jneo8 commented 3 months ago

I do not think it's working as expected, since in plan I can see that it will create branch for PR, push file and create PR. Or I do not understand it correctly?

Can you explain more? I am not sure what is your issue.

There are some conditions to make sure the pr won't be created if the files are the same.

rgildein commented 3 months ago

I do not think it's working as expected, since in plan I can see that it will create branch for PR, push file and create PR. Or I do not understand it correctly?

Can you explain more? I am not sure what is your issue.

There are some conditions to make sure the pr won't be created if the files are the same.

I think that this plan should do nothing, or not?

Also, why do we need to use output here?

jneo8 commented 3 months ago

I do not think it's working as expected, since in plan I can see that it will create branch for PR, push file and create PR. Or I do not understand it correctly?

Can you explain more? I am not sure what is your issue. There are some conditions to make sure the pr won't be created if the files are the same.

  • Line 143 is saying that the branch will be created.
  • Line 155 is saying that "codeowners" file will be created.
  • Line 174 is saying that new PR will be created.
  • Summary on Line 210 is saying that 5 thinks will be added.

I think that this plan should do nothing, or not?

Also, why do we need to use output here?

There is a local variable changed_files

# Compare the fetched content with the local content to create a map of changed files
locals {
  changed_files = {
    for file_key, file_info in var.workflow_files : file_key => file_info
      if file(file_info.source) != local.repository_files_content[file_info.destination]
  }
}

The branch and pr will be created if there are any file difference been detected. Those plans show on terraform plan is because change_files is based on data source github_repository_file.files,w which only only fetch the files when terraform apply.

rgildein commented 3 months ago

Since the plan is stored and then applied, I do not think that the PR will not be created. Let's try it.